Skip to content

Commit

Permalink
Split Specifier regex into operator and version parts
Browse files Browse the repository at this point in the history
Tokenizer uses _version_regex_str to detect 'VERSION' token.
  • Loading branch information
hrnciar committed Jul 19, 2022
1 parent 9ab90ae commit 8137185
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packaging/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, value: str) -> None:
self.value = value

def __str__(self) -> str:
return str(self.value)
return self.value

def __repr__(self) -> str:
return f"<{self.__class__.__name__}('{self}')>"
Expand Down
9 changes: 7 additions & 2 deletions packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def filter(

class Specifier(BaseSpecifier):

_regex_str = r"""
_operator_regex_str = r"""
(?P<operator>(~=|==|!=|<=|>=|<|>|===))
"""
_version_regex_str = r"""
(?P<version>
(?:
# The identity operators allow for an escape hatch that will
Expand Down Expand Up @@ -173,7 +175,10 @@ class Specifier(BaseSpecifier):
)
"""

_regex = re.compile(r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE)
_regex = re.compile(
r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$",
re.VERBOSE | re.IGNORECASE,
)

_operators = {
"~=": "compatible",
Expand Down

0 comments on commit 8137185

Please sign in to comment.