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

Fix parsing pre-release package versions #292

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- CI: update type/`mypy` check ([#288](https://github.com/Lightning-AI/utilities/pull/288))
- Fixed parsing pre-release package versions in `RequirementCache` ([#292](https://github.com/Lightning-AI/utilities/pull/292))

## [0.11.4] - 2024-07-15

Expand Down
2 changes: 1 addition & 1 deletion src/lightning_utilities/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

__version__ = "0.11.5"
__version__ = "0.11.6"
__author__ = "Lightning AI et al."
__author_email__ = "pytorch@lightning.ai"
__license__ = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/lightning_utilities/core/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _check_requirement(self) -> None:
try:
req = Requirement(self.requirement)
pkg_version = Version(_version(req.name))
self.available = req.specifier.contains(pkg_version) and (
self.available = req.specifier.contains(pkg_version, prereleases=True) and (
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
not req.extras or self._check_extras_available(req)
)
except (PackageNotFoundError, InvalidVersion) as ex:
Expand Down Expand Up @@ -180,7 +180,7 @@ def _check_extras_available(self, requirement: Requirement) -> bool:
try:
extra_dist = distribution(extra_req.name)
extra_installed_version = Version(extra_dist.version)
if extra_req.specifier and not extra_req.specifier.contains(extra_installed_version):
if extra_req.specifier and not extra_req.specifier.contains(extra_installed_version, prereleases=True):
return False
except importlib.metadata.PackageNotFoundError:
return False
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/core/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def test_requirement_cache_with_extras(distribution_mock, version_mock, requirem
assert not RequirementCache("jsonargparse[signatures]>=1.0.0")


@mock.patch("lightning_utilities.core.imports._version")
def test_requirement_cache_with_prerelease_package(version_mock):
version_mock.return_value = "0.11.0"
assert RequirementCache("transformer-engine>=0.11.0")
version_mock.return_value = "0.11.0.dev0+931b44f"
assert not RequirementCache("transformer-engine>=0.11.0")
version_mock.return_value = "1.10.0.dev0+931b44f"
assert RequirementCache("transformer-engine>=0.11.0")


def test_module_available_cache():
assert RequirementCache(module="pytest")
assert not RequirementCache(module="this_module_is_not_installed")
Expand Down
Loading