Version
feu.version ¶
Contain functions to compare package versions.
feu.version.compare_version ¶
compare_version(
package: str, op: Callable, version: str
) -> bool
Compare a package version to a given version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package
|
str
|
Specifies the package to check. |
required |
op
|
Callable
|
Specifies the comparison operator. |
required |
version
|
str
|
Specifies the version to compare with. |
required |
Returns:
Type | Description |
---|---|
bool
|
The comparison status. |
Example usage:
>>> import operator
>>> from feu.version import compare_version
>>> compare_version("pytest", op=operator.ge, version="7.3.0")
True
feu.version.filter_stable_versions ¶
filter_stable_versions(
versions: Sequence[str],
) -> list[str]
Filter out pre-release, post-release, and dev-release versions from a list of version strings.
A stable version is defined as
- Not a pre-release (e.g., alpha
a
, betab
, release candidaterc
) - Not a post-release (e.g.,
1.0.0.post1
) - Not a development release (e.g.,
1.0.0.dev1
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
versions
|
Sequence[str]
|
A list of version strings. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list containing only stable version strings. |
Example usage:
>>> from feu.version import filter_stable_versions
>>> versions = filter_stable_versions(
... ["1.0.0", "1.0.0a1", "2.0.0", "2.0.0.dev1", "3.0.0.post1"]
... )
>>> versions
['1.0.0', '2.0.0']
feu.version.filter_valid_versions ¶
filter_valid_versions(versions: Sequence[str]) -> list[str]
Filter out invalid version strings based on PEP 440.
A valid version is one that can be parsed by packaging.version.Version
.
Invalid versions include strings that don't conform to semantic versioning rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
versions
|
Sequence[str]
|
A list of version strings. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list containing only valid version strings. |
Example usage:
>>> from feu.version import filter_valid_versions
>>> versions = filter_valid_versions(
... [
... "1.0.0",
... "1.0.0a1",
... "2.0.0.post1",
... "not-a-version",
... "",
... "2",
... "3.0",
... "v1.0.0",
... "1.0.0.0.0",
... "4.0.0.dev1",
... ]
... )
>>> versions
['1.0.0', '1.0.0a1', '2.0.0.post1', '2', '3.0', 'v1.0.0', '1.0.0.0.0', '4.0.0.dev1']
feu.version.get_package_version ¶
get_package_version(package: str) -> Version | None
Get the package version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package
|
str
|
Specifies the package name. |
required |
Returns:
Type | Description |
---|---|
Version | None
|
The package version. |
Example usage:
>>> from feu.version import get_package_version
>>> get_package_version("pytest")
<Version('...')>
feu.version.get_python_major_minor
cached
¶
get_python_major_minor() -> str
Get the MAJOR.MINOR version of the current python.
Returns:
Type | Description |
---|---|
str
|
The MAJOR.MINOR version of the current python. |
Example usage:
>>> from feu.version import get_python_major_minor
>>> get_python_major_minor() # doctest: +SKIP