Skip to content
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

Improve understanding of revisions vs filters [#706] #711

Merged
merged 2 commits into from
Sep 12, 2022
Merged

Conversation

olsen232
Copy link
Collaborator

@olsen232 olsen232 commented Sep 9, 2022

Don't assume things are filters just because they seem not to be revisions - they may be a revision with a typo in them. Instead, check to make sure filters are present at HEAD, and fail with an error message if we can't decide if something is a revision or a filter.

Also fixes up some naming.

Fixes #706

Changelog doesn't need updating: already refers to this issue for the next release.

Don't assume things are filters just because they seem not to be
revisions - they may be a revision with a typo in them. Instead,
check to make sure filters are present at HEAD, and fail with
an error message if we can't decide if something is a revision or
a filter.

Also fixes up some naming.
@olsen232 olsen232 requested a review from craigds September 9, 2022 02:35
Comment on lines 75 to 81
t = type(option_val)
if t == int or t == str:
options.append(f"--{option_name}={option_val}")
elif t == tuple:
options.extend([f"--{option_name}={o}" for o in option_val]),
elif t == bool and option_val:
options.append(f"--{option_name}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use isinstance

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good call but I find it amusing how you recommend style changes to your own code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. not sure what i was thinking when i wrote it, that code doesn't seem like something I would write normally. Maybe I wrote it before I had a ☕

kart/parse_args.py Outdated Show resolved Hide resolved
kart/parse_args.py Outdated Show resolved Hide resolved
def _disambiguate_revisions_and_filters(repo, args):
revisions = []
filters = []
warning_set = set()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this needs to be a set; it looks like you're only adding SILENCING_HINT, so there should be other ways to dedupe that. Making it a set means the output will be nondeterministically ordered if you ever add a second thing to the set.

Perhaps we should configure the warnings module? It will de-dupe warnings automatically if configured correctly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... the warnings module looks great for deprecating things in modules that will be imported by third parties, etc etc. But I am just trying to print something once: I don't need auto line numbers + module names, or configuration options, and I especially don't want it to remember which warnings it has already printed for any longer than this function call (as could happen with our testing framework / kart helper). It's not beautiful how it is but I've just spent 10 minutes thinking about this and I think it's not really worth spending any longer on it - there's actually nothing measurably wrong with it right now

Copy link
Member

@craigds craigds Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kart helper

yep, that could use some work. Looks like there's no simple way to reset the warning registry globally: https://bugs.python.org/issue21724 - which we'd need to make this work well for kart helper

as could happen with our testing framework

AFAIK pytest resets the warnings state between each test, by default. Maybe it uses the hacky workaround in that python ticket 🤷 . It also has really good support for the warnings module if you want to check for warnings in your tests: https://docs.pytest.org/en/latest/how-to/capture-warnings.html

So in that case, I guess leave this as it is 👍

kart/show.py Outdated Show resolved Hide resolved
def parse_commits_and_filters(
filter_path = arg.split(":", maxsplit=1)[0]
head_tree = repo.head_tree
is_useful_filter_at_head = head_tree and filter_path in head_tree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how's filter_path in head_tree work? It looks like filter_path is something like ["<datasetname>", "<pk_value>"] and you're passing it to a pygit2.Tree.__contains__, which doesn't know about our path encodings. Or am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only pass the first part of a filter to it - everything before the ":" - which is a path with no particular encoding. Everything after that is ignored. So if you have an arg like "points:feature:25" and a dataset called "points" and no revision called "points", we're happy to assume your arg is a filter - even without encoding the feature PK to see if it exists, it's enough that the dataset exists.

Copy link
Member

@craigds craigds Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I misread L102

@olsen232 olsen232 requested a review from craigds September 12, 2022 01:14
@olsen232 olsen232 merged commit e05df57 into master Sep 12, 2022
@olsen232 olsen232 deleted the fix-rev-parse branch September 12, 2022 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diff, show (and others) need improved understanding of commits vs paths
2 participants