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 Nov 18, 2021
1 parent f1f7d1e commit b7728c3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packaging/specifiers.py
Expand Up @@ -316,8 +316,10 @@ def wrapped(self: "Specifier", prospective: ParsedVersion, spec: str) -> bool:

class Specifier(_IndividualSpecifier):

_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 @@ -409,7 +411,10 @@ class Specifier(_IndividualSpecifier):
)
"""

_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 b7728c3

Please sign in to comment.