Skip to content
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

Use regex-based version casting that accept #658

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions python/mlcroissant/mlcroissant/_src/core/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def cast_version(version: Any) -> str | None:
if isinstance(version, str):
numbers = version.split(".")
are_not_all_numbers = any(not number.isnumeric() for number in numbers)
if len(numbers) != 3 or are_not_all_numbers:
if are_not_all_numbers:
raise WarningException(
f"Version doesn't follow MAJOR.MINOR.PATCH: {version}. For more"
" information refer to: https://semver.org/spec/v2.0.0.html"
f"Version contains non-numeric characters: {version}."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the warning for non-numeric versioning. Reasonable? Or shall I remove this as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could fully implement the semantic versioning standard.

semver is a python library that does exactly this. However it seems we only need to check the compatibility with the standard, so we could also just reuse their regular expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think that it's worth mentioning the semantic versioning standard: https://semver.org/spec/v2.0.0.html, and that minor and patch can be omitted.

)
return version
elif isinstance(version, int):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,9 @@ def test_invalid_version(version, expected_error):
@pytest.mark.parametrize(
["version", "expected_warning"],
[
[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still keep this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Those should fail)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above, you could add that the versions 1 and 1.2 now succeed

"1.2.x",
"Version doesn't follow MAJOR.MINOR.PATCH: 1.2.x.",
],
[
"...123",
"Version doesn't follow MAJOR.MINOR.PATCH: ...123.",
],
[
"a.b.c",
"Version doesn't follow MAJOR.MINOR.PATCH: a.b.c",
"Version contains non-numeric characters: a.b.c",
],
],
)
Expand Down
Loading