-
-
Notifications
You must be signed in to change notification settings - Fork 7
Add option to canonicalise the version #18
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
935d9f0
9d601b4
7561d9e
d2139b3
04b91b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,34 @@ | |
|
||
GOOD_NODE_PYTHON_VERSIONS = [ | ||
("1.4.5", "1.4.5"), | ||
("1.4.5-a0", "1.4.5a0"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right - In fact, this shouldn't successfully parse. Can you change the NodeJS REGEX to make the (?P<pre_n>\.[0-9]+)? This would mean that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current regex is (?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
[-\.]?
(?P<pre_n>[0-9]+)? Is it ok to drop the dash? d2139b3 assumes so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be explicit, these changes are to the general regex, rather than just the canonicalisation logic you're proposing.
I suppose the new pattern would be (?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
\.
(?P<pre_n>[0-9]+) I'm using for reference, but they're complex documents, so it's possible I will make mistakes. Let me know if you disagree! |
||
("1.4.5-a.0", "1.4.5a0"), | ||
("1.4.5-a", "1.4.5a"), | ||
("1.4.5-b0", "1.4.5b0"), | ||
("1.4.5-c1", "1.4.5c1"), | ||
("1.4.5-rc0", "1.4.5rc0"), | ||
("1.4.5-alpha0", "1.4.5alpha0"), | ||
("1.4.5-beta0", "1.4.5beta0"), | ||
("1.4.5-pre9", "1.4.5pre9"), | ||
("1.4.5-preview0", "1.4.5preview0"), | ||
("1.4.5-preview0+build1.0.0", "1.4.5preview0+build1.0.0"), | ||
("1.4.5-preview0+build-1.0.0", "1.4.5preview0+build-1.0.0"), | ||
("1.4.5-preview0+good-1_0.0", "1.4.5preview0+good-1_0.0"), | ||
("1.4.5-b.0", "1.4.5b0"), | ||
("1.4.5-c.1", "1.4.5c1"), | ||
("1.4.5-rc.0", "1.4.5rc0"), | ||
("1.4.5-alpha.0", "1.4.5alpha0"), | ||
("1.4.5-beta.0", "1.4.5beta0"), | ||
("1.4.5-pre.9", "1.4.5pre9"), | ||
("1.4.5-preview.0", "1.4.5preview0"), | ||
("1.4.5-preview.0+build1.0.0", "1.4.5preview0+build1.0.0"), | ||
("1.4.5-preview.0+build-1.0.0", "1.4.5preview0+build-1.0.0"), | ||
("1.4.5-preview.0+good-1_0.0", "1.4.5preview0+good-1_0.0"), | ||
] | ||
|
||
GOOD_CANONICAL_NODE_PYTHON_VERSIONS = [ | ||
("1.4.5", "1.4.5"), | ||
("1.4.5-alpha.0", "1.4.5a0"), | ||
("1.4.5-alpha", "1.4.5a"), | ||
("1.4.5-beta.0", "1.4.5b0"), | ||
("1.4.5-rc.1", "1.4.5c1"), | ||
("1.4.5-rc.0", "1.4.5rc0"), | ||
("1.4.5-alpha.0", "1.4.5alpha0"), | ||
("1.4.5-beta.0", "1.4.5beta0"), | ||
("1.4.5-rc.9", "1.4.5pre9"), | ||
("1.4.5-rc.0", "1.4.5preview0"), | ||
("1.4.5-rc.0+build1.0.0", "1.4.5preview0+build1.0.0"), | ||
("1.4.5-rc.0+build-1.0.0", "1.4.5preview0+build-1.0.0"), | ||
("1.4.5-rc.0+good-1_0.0", "1.4.5preview0+good-1_0.0"), | ||
] | ||
|
||
|
||
|
@@ -75,8 +91,6 @@ def test_version_from_package( | |
[project] | ||
name = "my-app" | ||
dynamic = ["version"] | ||
[tool.hatch.version] | ||
source = "nodejs" | ||
""" | ||
) | ||
package_json = "package.json" if alt_package_json is None else alt_package_json | ||
|
@@ -132,3 +146,46 @@ def test_version_to_package( | |
|
||
written_package = json.loads((project / package_json).read_text()) | ||
assert written_package["version"] == node_version | ||
|
||
@pytest.mark.parametrize( | ||
"node_version, python_version", | ||
GOOD_CANONICAL_NODE_PYTHON_VERSIONS, | ||
) | ||
@pytest.mark.parametrize( | ||
"alt_package_json", | ||
[None, "package-other.json"], | ||
) | ||
def test_canonical_version_to_package( | ||
self, project, node_version, python_version, alt_package_json | ||
): | ||
package_json = "package.json" if alt_package_json is None else alt_package_json | ||
(project / "pyproject.toml").write_text( | ||
""" | ||
[build-system] | ||
requires = ["hatchling", "hatch-vcs"] | ||
build-backend = "hatchling.build" | ||
[project] | ||
name = "my-app" | ||
dynamic = ["version"] | ||
[tool.hatch.version] | ||
source = "nodejs" | ||
canonical = True | ||
""" | ||
) | ||
(project / package_json).write_text( | ||
""" | ||
{ | ||
"name": "my-app", | ||
"version": "0.0.0" | ||
} | ||
""" | ||
) | ||
config = {} if alt_package_json is None else {"path": alt_package_json} | ||
config["canonical"] = True | ||
version_source = NodeJSVersionSource(project, config=config) | ||
version_data = version_source.get_version_data() | ||
version_source.set_version(python_version, version_data) | ||
|
||
written_package = json.loads((project / package_json).read_text()) | ||
assert written_package["version"] == node_version | ||
|
Uh oh!
There was an error while loading. Please reload this page.