-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: add option to output locations to gpx files #286
Conversation
Ah, looks like Should I change the
Edit: see #287. Once thats merged I'll rebase this on top of master |
ah, tried to rebase on top of the mypy fix from smscalls to see if CI works for this (since adding the will try to just merge into this branch later today edit: huh, seemed to work, lmn if you want any changes here |
Oh, and also on the
I found something like https://github.com/tkrajina/gpx-cmd-tools/blob/master/gpxtools/gpxsplitter.py if thats something we want to pursue, perhaps with localized datetimes, or by clustering locations together for a particular trip etc. |
comment=location.datasource, | ||
) | ||
except AttributeError: | ||
yield TypeError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is also @runtime_checkable
but never tried it myself, and it needs typing_extensions
. So just in case you haven't seen it :) https://mypy.readthedocs.io/en/stable/protocols.html#using-isinstance-with-protocols
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, I saw that but disregarded because of the version requirement. I guess this would work even if the user duck-typed some other location class 👍
|
||
# can ignore the mypy warning here, locations_to_gpx yields any errors | ||
# if you didnt pass it something that matches the LocationProtocol | ||
for exc in locations_to_gpx(res, sys.stdout): # type: ignore[arg-type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess one downside is that it doesn't respect the same exception policies as select_range, and just dumps everything to terminal. But not a big deal, and perhaps can think about it later if necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah, this was more just a safeguard to prevent crashing, can add the two if statements to handle errors
we dont have a 'warn exceptions' flag on the cli though... guess it could use the logger instead?
edit: probably fine to leave it as is for now, one way to solve this is I'll write up some docs for hpi query
as those are currently just on the main page and I'll add an example there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one (somewhat hacky?) way to make it fit into the existing mechanism might be hacking a wrapper iterable before calling select_range
, e.g.
if output == 'gpx':
input_src = map(check_conforms_to_location_procotol, input_src)
# select_range call etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see what you mean -- that way exceptions will end up in stdout and mess with gpx output. Anyway I think it's fine as it is :) But yeah later might worth adding an option to select_range
/cli support to log exceptions to stderr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sounds good, will do that when I PR some docs for hpi query
This adds an
--output gpx
option tohpi query
that will output anything thatlooks like a
LocationProtocol
to GPX on stdoutFound a nice GUI tool to quickly preview GPX files: https://github.com/tumic0/GPXSee