Skip to content

Commit

Permalink
Fix parsing pre-release package versions (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli authored Jul 23, 2024
1 parent 911448a commit f0fa61e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
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 (
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

0 comments on commit f0fa61e

Please sign in to comment.