-
Notifications
You must be signed in to change notification settings - Fork 137
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
Conversation
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.
Thanks! Comments inline.
else: | ||
stk.append(token[idx]) | ||
else: | ||
stk.append(token[idx]) |
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.
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: |
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 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 |
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.
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\"" | ||
|
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.
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+)') | ||
|
||
|
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.
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>\[.*\])? |
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.
Please put the alignment here back how it was, it's like that deliberately.
I'm closing this PR and use new PR instead |
resolve #213