Skip to content

Commit

Permalink
Feat: only support prereleases
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Jun 10, 2022
1 parent 2e44479 commit d842b97
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 51 deletions.
60 changes: 9 additions & 51 deletions hatch_nodejs_version/version_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@
[-\.]?
(?P<pre_n>[0-9]+)?
)?
(?P<post> # post release
(?:-(?P<post_n1>[0-9]+))
|
(?:
[-\.]?
(?P<post_l>post|rev|r)
[-\.]?
(?P<post_n2>[0-9]+)?
)
)?
(?P<dev> # dev release
[-\.]?
(?P<dev_l>dev)
[-\.]?
(?P<dev_n>[0-9]+)?
)?
"""

# The NodeJS-aware Python version regex
Expand All @@ -59,22 +43,6 @@
[-_\.]?
(?P<pre_n>[0-9]+)?
)?
(?P<post> # post release
(?:-(?P<post_n1>[0-9]+))
|
(?:
[-_\.]?
(?P<post_l>post|rev|r)
[-_\.]?
(?P<post_n2>[0-9]+)?
)
)?
(?P<dev> # dev release
[-_\.]?
(?P<dev_l>dev)
[-_\.]?
(?P<dev_n>[0-9]+)?
)?
)
"""

Expand All @@ -96,13 +64,10 @@ def node_version_to_python(self, version: str) -> str:
parts = ["{major}.{minor}.{patch}".format_map(match)]

if match["pre"]:
parts.append("{pre_l}{pre_n}".format_map(match))
if match["post_n1"]:
parts.append(".post{post_n1}".format_map(match))
elif match["post_l"]:
parts.append(".{post_l}{post_n2}".format_map(match))
if match["dev"]:
parts.append("{dev_l}{dev_n}".format_map(match))
if match["pre_n"] is None:
parts.append("{pre_l}".format_map(match))
else:
parts.append("{pre_l}{pre_n}".format_map(match))

return "".join(parts)

Expand All @@ -115,22 +80,15 @@ def python_version_to_node(self, version: str) -> str:
re.VERBOSE | re.IGNORECASE,
)
if match is None:
raise ValueError(f"Version {node_version!r} did not match regex")
raise ValueError(f"Version {version!r} did not match regex")

parts = ["{major}.{minor}.{patch}".format_map(match)]

pre_parts = []
if match["pre"]:
pre_parts.append("{pre_l}{pre_n}".format_map(match))
if match["post_n1"]:
pre_parts.append(".post{post_n1}".format_map(match))
elif match["post_l"]:
pre_parts.append(".{post_l}{post_n2}".format_map(match))
if match["dev"]:
pre_parts.append("{dev_l}{dev_n}".format_map(match))

if pre_parts:
parts.append("-" + "".join(pre_parts))
if match["pre_n"] is None:
parts.append("-{pre_l}".format_map(match))
else:
parts.append("-{pre_l}{pre_n}".format_map(match))

return "".join(parts)

Expand Down
Empty file added tests/conftest.py
Empty file.
Empty file added tests/test_version_config.py
Empty file.

0 comments on commit d842b97

Please sign in to comment.