Skip to content

Commit

Permalink
ENH: Allow to pass the version number as a string to `misc.compare_ve…
Browse files Browse the repository at this point in the history
…rsions`
  • Loading branch information
remi-braun committed Jan 24, 2025
1 parent 0fd7740 commit c3cb1d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.45.0 (2025-mm-dd)

- **ENH: Use `odc.geo.xr.crop` instead of `rio.clip` to make `rasters.crop` dask-compatible** ([#27](https://github.com/sertit/sertit-utils/issues/27))
- ENH: Allow to pass the version number as a string to `misc.compare_versions`
- FIX: Fixes when trying to write COGs with dask in `rasters.write`

## 1.44.6 (2025-01-13)
Expand Down
4 changes: 3 additions & 1 deletion ci/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pytest

from ci.script_utils import Polarization
from sertit import ci, misc
from sertit import __version__, ci, misc
from sertit.misc import compare, compare_version

ci.reduce_verbosity()
Expand Down Expand Up @@ -159,3 +159,5 @@ def test_compare_versions():
""""""
assert compare_version("geopandas", "0.10.0", ">=")
assert compare_version("geopandas", "5.0.0", "<")
assert compare_version(__version__, "5.0.0", "<")
assert compare_version(__version__, "1.0.0", ">")
11 changes: 8 additions & 3 deletions sertit/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def compare_version(
Compare the version of a librarie to a reference, giving the operator.
Args:
lib (str): Name of the library
lib (str): Name of the library, it's version as a string or as a Version object
version_to_check (str): Version of the library to be compared
operator (str): Operator to use (:code:`>`, :code:`<`, :code:`>=`, :code:`<=`, :code:`==`)
Expand All @@ -531,14 +531,19 @@ def compare_version(
Example:
>>> compare_version("geopandas", "0.10.0", ">=")
True
>>> compare_version(sertit.__version__, "1.0.0", ">=")
True
"""
from importlib.metadata import version
from importlib.metadata import PackageNotFoundError, version

if isinstance(lib, Version):
lib_version = lib
elif isinstance(lib, str):
lib_version = Version(version(lib))
try:
lib_version = Version(version(lib))
except PackageNotFoundError:
lib_version = Version(lib)
else:
raise TypeError(
"'lib' should either be the name of your library as a string or directly a 'Version' object."
Expand Down

0 comments on commit c3cb1d4

Please sign in to comment.