Skip to content

Main functions

feu

Root package of feu.

feu.compare_version

compare_version(
    package: str, op: Callable, version: str
) -> bool

Compare the installed version of a package to a given version.

Parameters:

Name Type Description Default
package str

The package to check.

required
op Callable

The comparison operator, e.g. operator.ge. It is called as op(installed_version, Version(version)).

required
version str

The version to compare with.

required

Returns:

Type Description
bool

The comparison status. False if the package is not installed.

Example
>>> import operator
>>> from feu.version import compare_version
>>> compare_version("pytest", op=operator.ge, version="7.3.0")
True

feu.get_package_version

get_package_version(package: str) -> Version | None

Get the package version.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
Version | None

The package version, or None if the package is not installed.

Example
>>> from feu.version import get_package_version
>>> get_package_version("pytest")
<Version('...')>

feu.install_package

install_package(
    installer: InstallerSpec, package: PackageSpec
) -> None

Install a package with the specified installer.

The package is installed as specified, without any version compatibility check. Use install_package_closest_version to install the closest compatible version.

Parameters:

Name Type Description Default
installer InstallerSpec

The installer specification.

required
package PackageSpec

The package specification.

required

Raises:

Type Description
RuntimeError

If no installer is registered for the installer name.

CalledProcessError

If the installation command fails.

Example
>>> from feu.install import install_package
>>> from feu.utils.installer import InstallerSpec
>>> from feu.utils.package import PackageSpec
>>> install_package(
...     installer=InstallerSpec("pip"), package=PackageSpec(name="pandas", version="2.2.2")
... )  # doctest: +SKIP

feu.install_package_closest_version

install_package_closest_version(
    installer: InstallerSpec, package: PackageSpec
) -> None

Install a package and associated packages by using the specified installer.

This function finds the closest valid version if the specified version is not compatible with the current Python version (the OS and the CPU architecture are not considered). A wildcard version (e.g. '2.12.*') cannot be checked against the compatibility registry, so the package is installed as specified.

Parameters:

Name Type Description Default
installer InstallerSpec

The installer specification.

required
package PackageSpec

The package specification.

required

Raises:

Type Description
RuntimeError

If no package version is specified, or if no installer is registered for the installer name.

UnsupportedVersionError

If no version of the package is valid for the current Python version.

CalledProcessError

If the installation command fails.

Example
>>> from feu.install import install_package_closest_version
>>> from feu.utils.installer import InstallerSpec
>>> from feu.utils.package import PackageSpec
>>> install_package_closest_version(
...     installer=InstallerSpec("pip"), package=PackageSpec(name="pandas", version="2.2.2")
... )  # doctest: +SKIP

feu.is_module_available cached

is_module_available(name: str) -> bool

Indicate if a module is available or not.

Unlike is_package_available, the module is imported, so importing it can have side effects. The result is cached.

Parameters:

Name Type Description Default
name str

The module name to check.

required

Returns:

Type Description
bool

True if the module is available, otherwise False.

Example
>>> from feu.imports import is_module_available
>>> is_module_available("os")
True
>>> is_module_available("os.missing")
False
>>> is_module_available("missing.module")
False

feu.is_package_available cached

is_package_available(name: str) -> bool

Indicate if a package is available or not.

The package is searched without being imported. The result is cached.

Parameters:

Name Type Description Default
name str

The package name to check.

required

Returns:

Type Description
bool

True if the package is available, otherwise False.

Example
>>> from feu.imports import is_package_available
>>> is_package_available("os")
True
>>> is_package_available("missing_package")
False