Skip to content

implement: validate_environment_marker#220

Closed
mr54ndm4n wants to merge 4 commits into
pypa:masterfrom
mr54ndm4n:validator_env_marker_parentheses
Closed

implement: validate_environment_marker#220
mr54ndm4n wants to merge 4 commits into
pypa:masterfrom
mr54ndm4n:validator_env_marker_parentheses

Conversation

@mr54ndm4n
Copy link
Copy Markdown

resolve #213

Copy link
Copy Markdown
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.

Comment thread flit/validate.py
else:
stk.append(token[idx])
else:
stk.append(token[idx])
Copy link
Copy Markdown
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.

Comment thread flit/validate.py
idx += 1
if len(stk) != 1 or stk[-1] != "EXP":
problems.append("Invalid environment markers syntax")
except Exception as e:
Copy link
Copy Markdown
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.

Comment thread tests/test_validate.py
assert len(res) == 1
assert res[0].startswith("Invalid expression")

res = vem("""()))))()extra == "test"(((((((""") # No chained comparisons
Copy link
Copy Markdown
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

Comment thread tests/test_validate.py
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
Copy Markdown
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 ()?

Comment thread flit/validate.py
$""", re.IGNORECASE | re.VERBOSE)
MARKER_OP = re.compile(r'(~=|===?|!=|<=?|>=?|\s+in\s+|\s+not in\s+)')


Copy link
Copy Markdown
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.

Comment thread flit/validate.py
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
Copy Markdown
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
Copy Markdown
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