Skip to content

Commit

Permalink
Use PEP-440 compatible version comparisons
Browse files Browse the repository at this point in the history
Currently, we we're using the
[`semantic-version`](https://pypi.org/project/semantic-version/)
library, to construct it's custom `Version` objects, which have
comparison support, however, this could easily lead to issues, as python
packaging doesn't follow the semver naming spec exactly, instead, it
follows the spec from [PEP-440](https://peps.python.org/pep-0440/).

This means certain things, such as alpha releases, use version tags like
`1.1.0a1`, instead of the semver alternative (`1.1.0-alpha.1`). Using
these incompatible version strings with the `semantic_version.Version`
class would lead to a `ValueError` getting raised during initialization.
This would cause all deprecated objects to be unusable on these
semver-incompatible mcproto versions, as the decorator where this check
happens would end with this `ValueError`.

This fixes the issue by moving to
[`packaging.version.Version`](https://packaging.pypa.io/en/stable/version.html#packaging.version.Version),
which was designed specifically for the PEP-440 version naming standard.
  • Loading branch information
ItsDrike committed Jan 9, 2025
1 parent 5fc0cb4 commit bb117de
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
1 change: 1 addition & 0 deletions changes/427.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix version comparisons in deprecated functions for PEP440, non-semver compatible versions
4 changes: 2 additions & 2 deletions mcproto/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import wraps
from typing import TypeVar

from semantic_version import Version
from packaging.version import Version
from typing_extensions import ParamSpec, Protocol

__all__ = ["deprecated", "deprecation_warn"]
Expand Down Expand Up @@ -46,7 +46,7 @@ def deprecation_warn(
except importlib.metadata.PackageNotFoundError:
# v0.0.0 will never mark things as already deprecated (removal_version will always be newer)
warnings.warn("Failed to get mcproto project version, assuming v0.0.0", category=RuntimeWarning, stacklevel=1)
project_version = Version(major=0, minor=0, patch=0)
project_version = Version("0.0.0")
else:
project_version = Version(_project_version)

Expand Down
17 changes: 1 addition & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ packages = [{ include = "mcproto" }]
python = ">=3.9,<4"
asyncio-dgram = "^2.1.2"
typing-extensions = "^4.4.0"
semantic-version = "^2.10.0"
httpx = "^0.24.1"
cryptography = ">=41.0.3,<44.0.0"
attrs = ">=23.2,<25.0"
packaging = "^24.2"

[tool.poetry.group.dev.dependencies]
pre-commit = ">=2.18.1,<5.0.0"
Expand Down

0 comments on commit bb117de

Please sign in to comment.