Architecture¶
Layers¶
The imports go one way (property 13). A module imports only the layers on its left; imports
imports nothing from feu. tests/unit/test_layers.py checks it.
imports -> utils -> version -> compat -> install -> cli
| Layer | What it does | I/O |
|---|---|---|
imports |
Availability checks of the optional libraries (a port of coola.utils.imports), MissingPackageError, lazy_exports. |
none |
utils |
Registry[T], run_command, fetch_data/fetch_response, PackageSpec, the platform of the interpreter, JSON files, mappings. |
command.py (subprocess), http.py (network) |
version |
The installed version, version comparison and filtering, the version request, pyproject bounds, PyPI metadata (fetch_pypi_project). |
pypi.py, package.py (network) |
compat |
Target, the registry, the shipped data, the discovery from PyPI, the wheel tags. |
discover.py (network), shipped.py (read files) |
install |
The installers, the dependency resolvers, install_package and friends. |
installer.py (subprocess) |
cli |
The click commands; they only parse and print. |
none of its own |
feu.benchmark, feu.github, feu.local_git and feu.testing are outside the chain and only use
the lower layers (feu.benchmark uses only the standard library).
| Package | What it does | Extra |
|---|---|---|
feu.github |
The metadata of a repository and of the repositories of an owner, from the GitHub API. | requests |
feu.local_git |
The tags of the local git repository, and the last (version) tag. | git |
feu.testing |
The pytest marks <name>_available and <name>_not_available for the optional libraries. |
none |
feu.benchmark |
The trend of the pytest-benchmark results, see below. |
none |
Public names and lazy imports¶
import feu imports only feu.imports. The names of feu.__all__ (find_closest_version,
install_package, is_package_available, ...) are resolved on first use by the __getattr__ that
feu.imports.lazy_exports builds from a table {name: module}. This keeps import feu cheap and
independent of the optional libraries, and tests/integration/test_import_weight.py checks that no
optional library is imported. A module that needs an optional library calls check_<package>() (for
example check_requests()) inside the function that uses it, never at import time.
feu.benchmark¶
feu.benchmark has one module per role, so that the I/O is visible in the file list: one loader that
validates, one pure analysis, one pure renderer, and a thin command (feu benchmark-trend).
| Module | What it does | I/O |
|---|---|---|
runs.py |
Run, KINDS, STATS, LABELS, load_runs, prune_runs: read, validate and delete the result files. |
reads and deletes the result files |
trend.py |
Regression, find_regressions: the latest run against the median of the previous runs, by machine. |
none |
report.py |
TrendReport, UNITS, make_report: the Markdown report and the ::warning:: annotations of the runs. |
none |
The results are frozen dataclasses with named fields. cli.py calls load_runs, make_report, then
prune_runs (only with --prune, after the report was built, so a failing load deletes nothing).
Data flow¶
dev/generate_compat_data.pycallsdiscover_compat_targets(package). It fetches the project once with the Simple API (fetch_pypi_project), parses the wheel file names (parse_wheel_filename) and writesfeu/compat/data/<package>.json.get_default_compat_registry()lists the files withimportlib.resources(nothing is parsed). The first lookup of a package parses its file.find_closest_version(package, request, target)resolves the version request against the known versions and the ranges of the target.install_package_closest_versioncalls it with the full current target.- The
Installerresolves the dependencies with the resolver registry and runs one command:<sys.executable> -m pip install ...oruv pip install --python <sys.executable> ....
How to add a package¶
Run the generator with the name of the package. The list of packages is the list of files, so nothing else is edited:
python dev/generate_compat_data.py --new my-package
The bot workflow bot-update-discovered-compat refreshes every file each week.
How to add a companion or an ignored version¶
Some packages publish their platform wheels in another package. COMPANIONS in
feu/compat/discover.py describes them with data:
>>> from feu.compat import COMPANIONS
>>> COMPANIONS["jax"]
SameVersion(package='jaxlib')
>>> COMPANIONS["pydantic"]
PinnedDependency(package='pydantic-core')
SameVersion means that the companion has a release with the same version, PinnedDependency that
the release pins the companion release. For such a package a pure-Python wheel never counts: the
release is judged by its platform wheels, or by the wheels of the companion release. A one-off case
does not need an edit of the table, pass companion= or ignore_versions= to
discover_compat_targets.
How to add an installer¶
An installer is a subclass of Installer that only differs by its prefix. Register the class
under a name:
>>> from feu.install import Installer, get_default_installer_registry, register_installer
>>> class PdmInstaller(Installer):
... prefix = ("pdm", "add")
>>> register_installer("pdm", PdmInstaller)
>>> get_default_installer_registry().find("pdm") is PdmInstaller
True
>>> from packaging.requirements import Requirement
>>> PdmInstaller("--dev").command([Requirement("numpy==2.0.2")])
['pdm', 'add', '--dev', 'numpy==2.0.2']
Override check_available() to raise a RuntimeError when the tool is missing. Every function
that installs takes an optional registry= if you do not want to change the default registry.
How to add a resolver¶
A resolver is a function from a PackageSpec to a list of requirements. It receives a version
request and should reason on the whole request (pandas==2.* straddles the threshold of
numpy<2.0.0, "" is the latest version):
>>> from packaging.requirements import Requirement
>>> from feu.install import register_resolver
>>> from feu.install.resolver import default_resolver, resolve
>>> from feu.utils.package import PackageSpec
>>> def my_resolver(package):
... return [*default_resolver(package), Requirement("typing-extensions>=4")]
>>> register_resolver("my-package", my_resolver)
>>> resolve(PackageSpec("My_Package", "1.0"))
[<Requirement('My_Package==1.0')>, <Requirement('typing-extensions>=4')>]
For a package that needs numpy<2.0.0 below a version, add the version to NUMPY2_MIN_VERSION in
feu/install/resolver.py or use numpy2_resolver(min_version).
Design choices¶
The Design page gives the properties that this architecture enforces and the trade-offs of the main choices.
Tests¶
Unit tests mirror the source tree and are fast: no network, no real installer. Every patched
behaviour has an integration test in tests/integration/ that exercises the real thing, for
example tests/integration/install/test_pip_offline.py builds a wheel and runs the real pip and
uv with --dry-run --no-index --find-links. The shipped data is asked real questions in
tests/integration/compat/test_data.py and its contract is checked by
tests/unit/compat/test_shipped_data.py.