Install
feu.install ¶
Contain package installers.
feu.install.InstallResult ¶
Bases: NamedTuple
Represent the outcome of installing multiple versions of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installed
|
The versions that were installed successfully. |
required | |
failed
|
The versions for which the installation failed. |
required |
feu.install.Installer
dataclass
¶
Define the base class of the package installers.
An installer builds one command, as an argument vector, that
installs the requirements of a package. The subclasses differ by
their prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
Optional arguments to pass to the package
installer, after the prefix. The valid arguments depend on
the package installer. A string is split once with
|
()
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
>>> from feu.install import PipInstaller
>>> from feu.utils.package import PackageSpec
>>> installer = PipInstaller("-U")
>>> installer
PipInstaller(arguments=('-U',))
>>> installer.install(PackageSpec(name="pandas", version="2.2.2")) # doctest: +SKIP
feu.install.Installer.check_available ¶
check_available() -> None
Check that the tool used to install packages is available.
The default implementation does nothing.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the tool is not available. |
feu.install.Installer.command ¶
command(requirements: Sequence[Requirement]) -> list[str]
Build the command that installs requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requirements
|
Sequence[Requirement]
|
The requirements to install. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The command, as an argument vector: the prefix, the installer arguments and the requirements. |
Example
>>> from packaging.requirements import Requirement
>>> from feu.install import PipInstaller
>>> command = PipInstaller("-U").command([Requirement("numpy==2.0.0")])
>>> command[1:]
['-m', 'pip', 'install', '-U', 'numpy==2.0.0']
feu.install.Installer.install ¶
install(
package: PackageSpec,
*,
resolvers: Registry[Resolver] | None = None,
) -> None
Install a package and its associated requirements with a single command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
PackageSpec
|
The package to install. |
required |
resolvers
|
Registry[Resolver] | None
|
The dependency resolver registry. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the tool used to install packages is not available. |
CalledProcessError
|
If the installation command fails. |
Example
>>> from feu.install import PipInstaller
>>> from feu.utils.package import PackageSpec
>>> PipInstaller().install(PackageSpec("pandas", "2.2.2")) # doctest: +SKIP
feu.install.InstallerSpec
dataclass
¶
Define a dataclass to represent an installer specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The installer name. |
required |
arguments
|
str | Sequence[str]
|
The optional installer arguments. A string is
split once with |
()
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
>>> from feu.install import InstallerSpec
>>> installer1 = InstallerSpec("pip")
>>> installer1
InstallerSpec(name='pip', arguments=())
>>> installer2 = InstallerSpec("pip", arguments="-U --pre")
>>> installer2
InstallerSpec(name='pip', arguments=('-U', '--pre'))
>>> installer3 = InstallerSpec("pip", arguments=["-U", "--pre"])
>>> installer3 == installer2
True
feu.install.PipInstaller
dataclass
¶
Bases: Installer
Implement a pip package installer.
The package dependencies are resolved first, and then installed
with a single python -m pip install command, where python
is the interpreter that runs feu (sys.executable). The
packages are therefore installed in the environment that is
checked by the compatibility functions, and not in the one of the
first pip found on the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
Optional arguments to pass to |
()
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When installing, if |
Example
>>> from feu.install import PipInstaller
>>> installer = PipInstaller()
>>> installer
PipInstaller(arguments=())
feu.install.UvInstaller
dataclass
¶
Bases: Installer
Implement a uv package installer.
The package dependencies are resolved first, and then installed
with a single uv pip install --python <sys.executable> command,
so the packages are installed in the interpreter that runs feu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
Optional arguments to pass to |
()
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When installing, if |
Example
>>> from feu.install import UvInstaller
>>> installer = UvInstaller()
>>> installer
UvInstaller(arguments=())
feu.install.get_default_installer_registry
cached
¶
Get the default installer registry.
The registry maps an installer name (case-insensitive) to an
installer class. "pip" and "uv" are registered by default.
The same instance is returned by every call.
Returns:
| Type | Description |
|---|---|
Registry[type[Installer]]
|
The default registry. |
Example
>>> from feu.install import get_default_installer_registry
>>> get_default_installer_registry().keys()
['pip', 'uv']
feu.install.get_default_resolver_registry
cached
¶
get_default_resolver_registry() -> Registry[Resolver]
Get the default dependency resolver registry.
The registry maps a canonical package name (PEP 503) to a resolver.
The packages that are not compatible with numpy 2.0 before a
version (NUMPY2_MIN_VERSION) and jax have a resolver. The
same instance is returned by every call.
Returns:
| Type | Description |
|---|---|
Registry[Resolver]
|
The default registry. |
Example
>>> from feu.install.resolver import get_default_resolver_registry
>>> registry = get_default_resolver_registry()
>>> "Scikit_Learn" in registry
True
feu.install.get_installable_versions ¶
get_installable_versions(
pkg_name: str,
target: Target,
*,
start_date: date | str | None = None,
) -> list[str]
Get the stable package versions compatible with a target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to inspect (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
start_date
|
date | str | None
|
If specified, only the versions released on or
after this date are considered. The date can be a
|
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The stable versions of the package that are valid for the given target, in PEP 440 order (ascending). |
Example
>>> from feu.compat import Target
>>> from feu.install import get_installable_versions
>>> versions = get_installable_versions(
... "numpy", target=Target(python_version="3.11")
... ) # doctest: +SKIP
feu.install.install_all_versions ¶
install_all_versions(
installer: InstallerSpec,
package: str,
target: Target,
*,
start_date: date | str | None = None,
) -> InstallResult
Install all the versions of a package that are compatible with a target, one after the other.
A failure to install one version does not stop the installation of the remaining versions. The failure is logged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerSpec
|
The installer specification. |
required |
package
|
str
|
The package to install, optionally with extras
e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
start_date
|
date | str | None
|
If specified, only the versions released on or
after this date are installed. The date can be a
|
None
|
Returns:
| Type | Description |
|---|---|
InstallResult
|
The versions that were installed successfully and the versions for which the installation failed. |
Raises:
| Type | Description |
|---|---|
InvalidRequirement
|
If |
Example
>>> from feu.compat import Target
>>> from feu.install import InstallerSpec, install_all_versions
>>> result = install_all_versions(
... installer=InstallerSpec("pip"),
... package="pandas[performance]",
... target=Target(python_version="3.11"),
... ) # doctest: +SKIP
feu.install.install_package ¶
install_package(
installer: InstallerSpec,
package: PackageSpec,
*,
registry: Registry[type[Installer]] | None = None,
) -> 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. The cached availability
checks (feu.imports.clear_availability_caches) are cleared after
a successful installation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerSpec
|
The installer specification. |
required |
package
|
PackageSpec
|
The package specification. |
required |
registry
|
Registry[type[Installer]] | None
|
The installer registry. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no installer is registered for the installer name, or if the tool of the installer is not available. |
CalledProcessError
|
If the installation command fails. |
Example
>>> from feu.install import InstallerSpec, install_package
>>> from feu.utils.package import PackageSpec
>>> install_package(
... installer=InstallerSpec("pip"), package=PackageSpec(name="pandas", version="2.2.2")
... ) # doctest: +SKIP
feu.install.install_package_closest_version ¶
install_package_closest_version(
installer: InstallerSpec,
package: PackageSpec,
*,
target: Target | None = None,
registry: Registry[type[Installer]] | None = None,
) -> 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 target. By default, the target is the current environment: the Python version, the free-threaded flag, the OS and the CPU architecture.
The package version is a version request: an exact version
('2.0.2'), a wildcard ('2.*') or '' for the latest
version. A request is resolved to the latest compatible version. If
that version lies in an open-ended range, the request itself is
installed, so the installer picks the real latest release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerSpec
|
The installer specification. |
required |
package
|
PackageSpec
|
The package specification. |
required |
target
|
Target | None
|
The compatibility target. |
None
|
registry
|
Registry[type[Installer]] | None
|
The installer registry. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no installer is registered for the installer name, or if the tool of the installer is not available. |
UnsupportedVersionError
|
If no version of the package is valid for the target, or if no known version satisfies a wildcard request. |
ValueError
|
If the package version is not a valid version request. |
CalledProcessError
|
If the installation command fails. |
Example
>>> from feu.install import InstallerSpec, install_package_closest_version
>>> from feu.utils.package import PackageSpec
>>> install_package_closest_version(
... installer=InstallerSpec("pip"), package=PackageSpec(name="pandas", version="2.2.2")
... ) # doctest: +SKIP
feu.install.is_pip_available
cached
¶
is_pip_available() -> bool
Check if pip is available in the interpreter that runs
feu.
The result is cached.
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.install import is_pip_available
>>> isinstance(is_pip_available(), bool)
True
feu.install.is_uv_available
cached
¶
is_uv_available() -> bool
Check if uv is available.
The result is cached.
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.install import is_uv_available
>>> isinstance(is_uv_available(), bool)
True
feu.install.register_installer ¶
register_installer(
name: str,
installer: type[Installer],
*,
exist_ok: bool = False,
) -> None
Register an installer class in the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The installer name e.g. |
required |
installer
|
type[Installer]
|
The installer class used for the given name. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If an installer is already registered for the
name and |
Example
>>> from feu.install import PipInstaller, register_installer
>>> register_installer("pip", PipInstaller, exist_ok=True)
feu.install.register_resolver ¶
register_resolver(
package: str,
resolver: Resolver,
*,
exist_ok: bool = False,
) -> None
Register a dependency resolver in the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The package name, e.g. |
required |
resolver
|
Resolver
|
The resolver used for the package. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a resolver is already registered for the
package and |
Example
>>> from feu.install.resolver import default_resolver, register_resolver
>>> register_resolver("torch", default_resolver, exist_ok=True)
feu.install.api ¶
Contain the functions to install a package.
feu.install.api.install_package ¶
install_package(
installer: InstallerSpec,
package: PackageSpec,
*,
registry: Registry[type[Installer]] | None = None,
) -> 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. The cached availability
checks (feu.imports.clear_availability_caches) are cleared after
a successful installation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerSpec
|
The installer specification. |
required |
package
|
PackageSpec
|
The package specification. |
required |
registry
|
Registry[type[Installer]] | None
|
The installer registry. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no installer is registered for the installer name, or if the tool of the installer is not available. |
CalledProcessError
|
If the installation command fails. |
Example
>>> from feu.install import InstallerSpec, install_package
>>> from feu.utils.package import PackageSpec
>>> install_package(
... installer=InstallerSpec("pip"), package=PackageSpec(name="pandas", version="2.2.2")
... ) # doctest: +SKIP
feu.install.api.install_package_closest_version ¶
install_package_closest_version(
installer: InstallerSpec,
package: PackageSpec,
*,
target: Target | None = None,
registry: Registry[type[Installer]] | None = None,
) -> 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 target. By default, the target is the current environment: the Python version, the free-threaded flag, the OS and the CPU architecture.
The package version is a version request: an exact version
('2.0.2'), a wildcard ('2.*') or '' for the latest
version. A request is resolved to the latest compatible version. If
that version lies in an open-ended range, the request itself is
installed, so the installer picks the real latest release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerSpec
|
The installer specification. |
required |
package
|
PackageSpec
|
The package specification. |
required |
target
|
Target | None
|
The compatibility target. |
None
|
registry
|
Registry[type[Installer]] | None
|
The installer registry. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no installer is registered for the installer name, or if the tool of the installer is not available. |
UnsupportedVersionError
|
If no version of the package is valid for the target, or if no known version satisfies a wildcard request. |
ValueError
|
If the package version is not a valid version request. |
CalledProcessError
|
If the installation command fails. |
Example
>>> from feu.install import InstallerSpec, install_package_closest_version
>>> from feu.utils.package import PackageSpec
>>> install_package_closest_version(
... installer=InstallerSpec("pip"), package=PackageSpec(name="pandas", version="2.2.2")
... ) # doctest: +SKIP
feu.install.all_versions ¶
Contain the functions to install all the compatible versions of a package.
feu.install.all_versions.InstallResult ¶
Bases: NamedTuple
Represent the outcome of installing multiple versions of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installed
|
The versions that were installed successfully. |
required | |
failed
|
The versions for which the installation failed. |
required |
feu.install.all_versions.get_installable_versions ¶
get_installable_versions(
pkg_name: str,
target: Target,
*,
start_date: date | str | None = None,
) -> list[str]
Get the stable package versions compatible with a target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to inspect (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
start_date
|
date | str | None
|
If specified, only the versions released on or
after this date are considered. The date can be a
|
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The stable versions of the package that are valid for the given target, in PEP 440 order (ascending). |
Example
>>> from feu.compat import Target
>>> from feu.install import get_installable_versions
>>> versions = get_installable_versions(
... "numpy", target=Target(python_version="3.11")
... ) # doctest: +SKIP
feu.install.all_versions.install_all_versions ¶
install_all_versions(
installer: InstallerSpec,
package: str,
target: Target,
*,
start_date: date | str | None = None,
) -> InstallResult
Install all the versions of a package that are compatible with a target, one after the other.
A failure to install one version does not stop the installation of the remaining versions. The failure is logged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerSpec
|
The installer specification. |
required |
package
|
str
|
The package to install, optionally with extras
e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
start_date
|
date | str | None
|
If specified, only the versions released on or
after this date are installed. The date can be a
|
None
|
Returns:
| Type | Description |
|---|---|
InstallResult
|
The versions that were installed successfully and the versions for which the installation failed. |
Raises:
| Type | Description |
|---|---|
InvalidRequirement
|
If |
Example
>>> from feu.compat import Target
>>> from feu.install import InstallerSpec, install_all_versions
>>> result = install_all_versions(
... installer=InstallerSpec("pip"),
... package="pandas[performance]",
... target=Target(python_version="3.11"),
... ) # doctest: +SKIP
feu.install.installer ¶
Contain the package installers and their registry.
feu.install.installer.Installer
dataclass
¶
Define the base class of the package installers.
An installer builds one command, as an argument vector, that
installs the requirements of a package. The subclasses differ by
their prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
Optional arguments to pass to the package
installer, after the prefix. The valid arguments depend on
the package installer. A string is split once with
|
()
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
>>> from feu.install import PipInstaller
>>> from feu.utils.package import PackageSpec
>>> installer = PipInstaller("-U")
>>> installer
PipInstaller(arguments=('-U',))
>>> installer.install(PackageSpec(name="pandas", version="2.2.2")) # doctest: +SKIP
feu.install.installer.Installer.check_available ¶
check_available() -> None
Check that the tool used to install packages is available.
The default implementation does nothing.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the tool is not available. |
feu.install.installer.Installer.command ¶
command(requirements: Sequence[Requirement]) -> list[str]
Build the command that installs requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requirements
|
Sequence[Requirement]
|
The requirements to install. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The command, as an argument vector: the prefix, the installer arguments and the requirements. |
Example
>>> from packaging.requirements import Requirement
>>> from feu.install import PipInstaller
>>> command = PipInstaller("-U").command([Requirement("numpy==2.0.0")])
>>> command[1:]
['-m', 'pip', 'install', '-U', 'numpy==2.0.0']
feu.install.installer.Installer.install ¶
install(
package: PackageSpec,
*,
resolvers: Registry[Resolver] | None = None,
) -> None
Install a package and its associated requirements with a single command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
PackageSpec
|
The package to install. |
required |
resolvers
|
Registry[Resolver] | None
|
The dependency resolver registry. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the tool used to install packages is not available. |
CalledProcessError
|
If the installation command fails. |
Example
>>> from feu.install import PipInstaller
>>> from feu.utils.package import PackageSpec
>>> PipInstaller().install(PackageSpec("pandas", "2.2.2")) # doctest: +SKIP
feu.install.installer.InstallerSpec
dataclass
¶
Define a dataclass to represent an installer specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The installer name. |
required |
arguments
|
str | Sequence[str]
|
The optional installer arguments. A string is
split once with |
()
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
>>> from feu.install import InstallerSpec
>>> installer1 = InstallerSpec("pip")
>>> installer1
InstallerSpec(name='pip', arguments=())
>>> installer2 = InstallerSpec("pip", arguments="-U --pre")
>>> installer2
InstallerSpec(name='pip', arguments=('-U', '--pre'))
>>> installer3 = InstallerSpec("pip", arguments=["-U", "--pre"])
>>> installer3 == installer2
True
feu.install.installer.PipInstaller
dataclass
¶
Bases: Installer
Implement a pip package installer.
The package dependencies are resolved first, and then installed
with a single python -m pip install command, where python
is the interpreter that runs feu (sys.executable). The
packages are therefore installed in the environment that is
checked by the compatibility functions, and not in the one of the
first pip found on the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
Optional arguments to pass to |
()
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When installing, if |
Example
>>> from feu.install import PipInstaller
>>> installer = PipInstaller()
>>> installer
PipInstaller(arguments=())
feu.install.installer.UvInstaller
dataclass
¶
Bases: Installer
Implement a uv package installer.
The package dependencies are resolved first, and then installed
with a single uv pip install --python <sys.executable> command,
so the packages are installed in the interpreter that runs feu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
Optional arguments to pass to |
()
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When installing, if |
Example
>>> from feu.install import UvInstaller
>>> installer = UvInstaller()
>>> installer
UvInstaller(arguments=())
feu.install.installer.get_default_installer_registry
cached
¶
Get the default installer registry.
The registry maps an installer name (case-insensitive) to an
installer class. "pip" and "uv" are registered by default.
The same instance is returned by every call.
Returns:
| Type | Description |
|---|---|
Registry[type[Installer]]
|
The default registry. |
Example
>>> from feu.install import get_default_installer_registry
>>> get_default_installer_registry().keys()
['pip', 'uv']
feu.install.installer.is_pip_available
cached
¶
is_pip_available() -> bool
Check if pip is available in the interpreter that runs
feu.
The result is cached.
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.install import is_pip_available
>>> isinstance(is_pip_available(), bool)
True
feu.install.installer.is_uv_available
cached
¶
is_uv_available() -> bool
Check if uv is available.
The result is cached.
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.install import is_uv_available
>>> isinstance(is_uv_available(), bool)
True
feu.install.installer.normalize_arguments ¶
normalize_arguments(
arguments: str | Sequence[str],
) -> tuple[str, ...]
Normalize the arguments of an installer to a tuple of strings.
A string is split once with shlex.split (POSIX rules, on every
platform). A sequence of strings is converted to a tuple and is not
split again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
str | Sequence[str]
|
The installer arguments, as one string e.g.
|
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The arguments as a tuple of strings. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
>>> from feu.install.installer import normalize_arguments
>>> normalize_arguments("-U --pre")
('-U', '--pre')
>>> normalize_arguments(["--index-url", "https://example.com/my index"])
('--index-url', 'https://example.com/my index')
feu.install.installer.register_installer ¶
register_installer(
name: str,
installer: type[Installer],
*,
exist_ok: bool = False,
) -> None
Register an installer class in the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The installer name e.g. |
required |
installer
|
type[Installer]
|
The installer class used for the given name. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If an installer is already registered for the
name and |
Example
>>> from feu.install import PipInstaller, register_installer
>>> register_installer("pip", PipInstaller, exist_ok=True)
feu.install.resolver ¶
Contain the dependency resolvers.
A dependency resolver is a function that takes a PackageSpec and
returns the list of requirements to install to get a working package,
e.g. pandas before 2.2.2 needs numpy<2.0.0. The resolvers are
registered by canonical package name in a Registry.
feu.install.resolver.default_resolver ¶
default_resolver(package: PackageSpec) -> list[Requirement]
Resolve a package with the default resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
PackageSpec
|
The package to install. |
required |
Returns:
| Type | Description |
|---|---|
list[Requirement]
|
The package itself. |
Example
>>> from feu.install.resolver import default_resolver
>>> from feu.utils.package import PackageSpec
>>> default_resolver(PackageSpec("my_package", version="1.2.3"))
[<Requirement('my_package==1.2.3')>]
feu.install.resolver.get_default_resolver_registry
cached
¶
get_default_resolver_registry() -> Registry[Resolver]
Get the default dependency resolver registry.
The registry maps a canonical package name (PEP 503) to a resolver.
The packages that are not compatible with numpy 2.0 before a
version (NUMPY2_MIN_VERSION) and jax have a resolver. The
same instance is returned by every call.
Returns:
| Type | Description |
|---|---|
Registry[Resolver]
|
The default registry. |
Example
>>> from feu.install.resolver import get_default_resolver_registry
>>> registry = get_default_resolver_registry()
>>> "Scikit_Learn" in registry
True
feu.install.resolver.jax_resolver ¶
jax_resolver(package: PackageSpec) -> list[Requirement]
Resolve jax.
jaxlib is pinned to the same version request (and not at all
for the latest version). numpy 2.0 support was added in
jax 0.4.26, so numpy<2.0.0 is added below it.
ml_dtypes<=0.2.0 is added for 0.4.9 to 0.4.11
(https://github.com/google/jax/issues/17693).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
PackageSpec
|
The |
required |
Returns:
| Type | Description |
|---|---|
list[Requirement]
|
The requirements. |
Example
>>> from feu.install.resolver import jax_resolver
>>> from feu.utils.package import PackageSpec
>>> jax_resolver(PackageSpec("jax", version="0.4.26"))
[<Requirement('jax==0.4.26')>, <Requirement('jaxlib==0.4.26')>]
>>> jax_resolver(PackageSpec("jax", version="0.4.25"))
[<Requirement('jax==0.4.25')>, <Requirement('jaxlib==0.4.25')>, <Requirement('numpy<2.0.0')>]
feu.install.resolver.numpy2_resolver ¶
numpy2_resolver(min_version: str) -> Resolver
Create a resolver for a package that did not pin numpy<2.0
and is not fully compatible with numpy 2.0 before a version.
numpy<2.0.0 is added when the whole version request lies
below min_version: pandas==2.1.* is below 2.2.2, but
pandas==2.* straddles it and "" is the latest version, so
no pin is added for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_version
|
str
|
The first version that is fully compatible with
|
required |
Returns:
| Type | Description |
|---|---|
Resolver
|
The resolver. |
Example
>>> from feu.install.resolver import numpy2_resolver
>>> from feu.utils.package import PackageSpec
>>> resolver = numpy2_resolver("1.2.3")
>>> resolver(PackageSpec("my_package", version="1.2.3"))
[<Requirement('my_package==1.2.3')>]
>>> resolver(PackageSpec("my_package", version="1.2.2"))
[<Requirement('my_package==1.2.2')>, <Requirement('numpy<2.0.0')>]
feu.install.resolver.register_resolver ¶
register_resolver(
package: str,
resolver: Resolver,
*,
exist_ok: bool = False,
) -> None
Register a dependency resolver in the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The package name, e.g. |
required |
resolver
|
Resolver
|
The resolver used for the package. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a resolver is already registered for the
package and |
Example
>>> from feu.install.resolver import default_resolver, register_resolver
>>> register_resolver("torch", default_resolver, exist_ok=True)
feu.install.resolver.resolve ¶
resolve(
package: PackageSpec,
registry: Registry[Resolver] | None = None,
) -> list[Requirement]
Resolve the requirements to install for a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
PackageSpec
|
The package to install. |
required |
registry
|
Registry[Resolver] | None
|
The resolver registry. |
None
|
Returns:
| Type | Description |
|---|---|
list[Requirement]
|
The requirements to install. |
Example
>>> from feu.install.resolver import resolve
>>> from feu.utils.package import PackageSpec
>>> resolve(PackageSpec("pandas", version="2.2.1"))
[<Requirement('pandas==2.2.1')>, <Requirement('numpy<2.0.0')>]