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

implement: validate_environment_marker #220

Closed
wants to merge 4 commits into from
Closed

implement: validate_environment_marker #220

wants to merge 4 commits into from

Conversation

mr54ndm4n
Copy link

resolve #213

Copy link
Member

@takluyver takluyver left a comment

Choose a reason for hiding this comment

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

Thanks! Comments inline.

else:
stk.append(token[idx])
else:
stk.append(token[idx])
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some comments in your parser code? I'm finding it a bit hard to follow.

idx += 1
if len(stk) != 1 or stk[-1] != "EXP":
problems.append("Invalid environment markers syntax")
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this structure - it could easily obscure a bug in the code by catching an overly general exception, and it means all the interesting code is indented a level more than it needs to be.

If you want to jump out of parsing as soon as a problem is detected, I think it's OK to use an early return.

@@ -76,6 +80,14 @@ def test_validate_environment_marker():
assert len(res) == 1
assert res[0].startswith("Invalid expression")

res = vem("""()))))()extra == "test"(((((((""") # No chained comparisons
Copy link
Member

Choose a reason for hiding this comment

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

The comment here is misleading, I think

res = vem("""extra == "test" and or (os_name == "nt" or python_version == "2.7")""") # No chained comparisons
assert len(res) == 1
assert res[0] == "Invalid expression \"and or\""

Copy link
Member

Choose a reason for hiding this comment

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

Can we add a test for an empty pair of parentheses, like extra == "test" and ()?

\s*(?P<version>[(=~<>!][^;]*)?
\s*(?P<envmark>;.*)?
$""", re.IGNORECASE | re.VERBOSE)
MARKER_OP = re.compile(r'(~=|===?|!=|<=?|>=?|\s+in\s+|\s+not in\s+)')


Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but as a general rule, please try not to reformat code beyond the bit that you're working on.

# Distribution name, not quite the same as a Python identifier
NAME = re.compile(r'^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$', re.IGNORECASE)
r''
VERSION_SPEC = re.compile(r'(~=|===?|!=|<=?|>=?)\s*[A-Z0-9\-_.*+!]+$', re.IGNORECASE)
REQUIREMENT = re.compile(NAME.pattern[:-1] + # Trim '$'
r"""\s*(?P<extras>\[.*\])?
r"""\s*(?P<extras>\[.*\])?
Copy link
Member

Choose a reason for hiding this comment

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

Please put the alignment here back how it was, it's like that deliberately.

@mr54ndm4n
Copy link
Author

mr54ndm4n commented Oct 31, 2018

I'm closing this PR and use new PR instead

@mr54ndm4n mr54ndm4n closed this Oct 31, 2018
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.

Validate parentheses properly in environment markers
2 participants