Skip to content

Version

feu.version

Contain functions to manage package versions.

feu.version.PackageBounds dataclass

Lower and upper version bounds for a package dependency.

Attributes:

Name Type Description
name str

The canonical package name as declared in the dependency specifier.

lower str | None

The lower bound version string (from >= or > specifiers), or None if no lower bound is declared.

upper str | None

The upper bound version string (from < or <= specifiers), or None if no upper bound is declared.

section str

The pyproject.toml section where the dependency was found (e.g. 'project.dependencies', 'project.optional-dependencies.dev', 'dependency-groups.dev').

feu.version.PypiFile dataclass

Represent a file of a release published on PyPI.

Parameters:

Name Type Description Default
filename str

The file name, e.g. "numpy-2.0.2.tar.gz".

required
requires_python str | None

The requires-python specifier of the file (e.g. ">=3.9"), or None.

required
yanked bool

True if the file is yanked.

required
uploaded datetime | None

The upload time (UTC), or None if unknown.

required

feu.version.PypiProject dataclass

Represent a project published on PyPI.

Parameters:

Name Type Description Default
name str

The canonical project name (PEP 503).

required
releases Mapping[str, tuple[PypiFile, ...]]

The files of each release, in PEP 440 ascending order of the release versions. The mapping is read-only. A release without any recognised file maps to an empty tuple.

required
Example
>>> from feu.version.pypi import PypiProject
>>> PypiProject(name="numpy", releases={})
PypiProject(name='numpy', releases={})

feu.version.VersionRequest dataclass

Represent a version request.

Use parse_version_request to create an instance.

Parameters:

Name Type Description Default
text str

The request as given, stripped: "" (the latest), "2.4.*" (a wildcard) or "2.4.0" (an exact version).

required
exact Version | None

The requested version for an exact request, otherwise None.

None
prefix tuple[int, ...] | None

The release prefix for a wildcard request, e.g. (2, 4) for "2.4.*", otherwise None.

None
Example
>>> from feu.version import parse_version_request
>>> parse_version_request("2.4.*")
VersionRequest(text='2.4.*', exact=None, prefix=(2, 4))

feu.version.VersionRequest.is_latest property

is_latest: bool

Indicate if the request is for the latest version.

Returns:

Type Description
bool

True for "" (and None), otherwise False.

Example
>>> from feu.version import parse_version_request
>>> parse_version_request("").is_latest
True
>>> parse_version_request("2.*").is_latest
False

feu.version.VersionRequest.entirely_below

entirely_below(version: Version) -> bool

Indicate if every version that satisfies the request is lower than a version.

Parameters:

Name Type Description Default
version Version

The version to compare with.

required

Returns:

Type Description
bool

True if the whole request lies below version. A wildcard that straddles version (e.g. "2.*" and 2.2.2) and the latest request are not entirely below.

Example
>>> from packaging.version import Version
>>> from feu.version import parse_version_request
>>> parse_version_request("2.1.*").entirely_below(Version("2.2.2"))
True
>>> parse_version_request("2.*").entirely_below(Version("2.2.2"))
False

feu.version.VersionRequest.matches

matches(version: Version) -> bool

Indicate if a version satisfies the request.

An exact request matches the version that is equal to it. A wildcard request matches the versions whose release segment, padded with zeros, starts with the prefix; pre-releases never match a wildcard. The latest request matches every version.

Parameters:

Name Type Description Default
version Version

The version to check.

required

Returns:

Type Description
bool

True if version satisfies the request, otherwise False.

Example
>>> from packaging.version import Version
>>> from feu.version import parse_version_request
>>> request = parse_version_request("2.4.*")
>>> request.matches(Version("2.4.17"))
True
>>> request.matches(Version("2.40"))
False

feu.version.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.version.fetch_latest_major_versions_map

fetch_latest_major_versions_map(
    packages: Sequence[PackageBounds],
    *,
    include_lower_bound: bool = False,
) -> dict[str, list[str]]

Fetch the latest major versions for a sequence of packages.

This function is kept for the scripts that copy dev/generate_versions.py; use fetch_package_versions in new code.

Parameters:

Name Type Description Default
packages Sequence[PackageBounds]

A sequence of PackageBounds instances, typically obtained from read_pyproject_bounds. If a package appears more than once in packages (e.g. because it was found in multiple sections), the last entry wins.

required
include_lower_bound bool

If True, the first stable version at or above each package's lower bound is included in its version list. Has no effect for packages whose lower bound is None.

False

Returns:

Type Description
dict[str, list[str]]

A dictionary mapping each package name to the list of latest major version strings returned by fetch_latest_versions.

Example
>>> from feu.version import PackageBounds, fetch_latest_major_versions_map
>>> bounds = [PackageBounds("requests", "2.28", None, "project.dependencies")]
>>> versions = fetch_latest_major_versions_map(
...     bounds, include_lower_bound=True
... )  # doctest: +SKIP

feu.version.fetch_latest_minor_versions_map

fetch_latest_minor_versions_map(
    packages: Sequence[PackageBounds],
    *,
    include_lower_bound: bool = False,
) -> dict[str, list[str]]

Fetch the latest minor versions for a sequence of packages.

This function is kept for the scripts that copy dev/generate_versions.py; use fetch_package_versions in new code.

Parameters:

Name Type Description Default
packages Sequence[PackageBounds]

A sequence of PackageBounds instances, typically obtained from read_pyproject_bounds. If a package appears more than once in packages (e.g. because it was found in multiple sections), the last entry wins.

required
include_lower_bound bool

If True, the first stable version at or above each package's lower bound is included in its version list. Has no effect for packages whose lower bound is None.

False

Returns:

Type Description
dict[str, list[str]]

A dictionary mapping each package name to the list of latest minor version strings returned by fetch_latest_versions.

Example
>>> from feu.version import PackageBounds, fetch_latest_minor_versions_map
>>> bounds = [PackageBounds("requests", "2.28", None, "project.dependencies")]
>>> versions = fetch_latest_minor_versions_map(
...     bounds, include_lower_bound=True
... )  # doctest: +SKIP

feu.version.fetch_latest_stable_version

fetch_latest_stable_version(package: str) -> str

Get the latest stable valid version for a given package.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
str

The latest stable valid version.

Raises:

Type Description
ValueError

If the package has no stable valid version.

Example
>>> from feu.version import fetch_latest_stable_version
>>> version = fetch_latest_stable_version("requests")  # doctest: +SKIP

feu.version.fetch_latest_version

fetch_latest_version(package: str) -> str

Get the latest valid version for a given package.

The latest version can be a pre-release, post-release or development release.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
str

The latest valid version.

Raises:

Type Description
ValueError

If the package has no valid version.

Example
>>> from feu.version import fetch_latest_version
>>> version = fetch_latest_version("requests")  # doctest: +SKIP

feu.version.fetch_latest_versions

fetch_latest_versions(
    package: str,
    *,
    group: Literal["major", "minor"],
    lower: str | None = None,
    upper: str | None = None,
    include_lower_bound: bool = False,
) -> tuple[str, ...]

Get the latest version of each major (or minor) version of a package.

Parameters:

Name Type Description Default
package str

The package name.

required
group Literal['major', 'minor']

"major" to get the latest version of each major version, "minor" for each major.minor version.

required
lower str | None

The lower version bound (inclusive). If None, no lower limit is applied.

None
upper str | None

The upper version bound (exclusive). If None, no upper limit is applied.

None
include_lower_bound bool

If True and lower is not None, the first stable version at or above lower is included in the result. This ensures the lower bound itself is always represented, even if it is not the latest patch of its group. If lower is None, this argument has no effect.

False

Returns:

Type Description
tuple[str, ...]

A tuple containing the latest version of each group, in ascending order. If include_lower_bound is True and lower is not None, the first stable version at or above lower is also included.

Raises:

Type Description
ValueError

If group is not "major" or "minor".

Example
>>> from feu.version import fetch_latest_versions
>>> versions = fetch_latest_versions(
...     "requests", group="minor", lower="2.28"
... )  # doctest: +SKIP

feu.version.fetch_package_versions

fetch_package_versions(
    pyproject: str | Path,
    *,
    major_only: Collection[str] = ("packaging",),
    include_lower_bound: bool = True,
) -> dict[str, list[str]]

Fetch the versions to test of the dependencies of a project.

The dependencies are read from [project.dependencies] and [project.optional-dependencies.*] of the pyproject.toml file (not from the [dependency-groups.*]). For each package, the latest version of each minor version at or above the lower bound is returned, or the latest version of each major version for the packages of major_only.

Parameters:

Name Type Description Default
pyproject str | Path

Path to the pyproject.toml file.

required
major_only Collection[str]

The packages for which only the latest version of each major version is returned. The names are compared in their canonical form.

('packaging',)
include_lower_bound bool

If True, the first stable version at or above the lower bound of each package is included.

True

Returns:

Type Description
dict[str, list[str]]

A dictionary mapping each canonical package name to its versions, sorted by package name. If a package appears more than once, the last entry wins.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
>>> from feu.version import fetch_package_versions
>>> versions = fetch_package_versions("pyproject.toml")  # doctest: +SKIP

feu.version.fetch_pypi_pinned_dependency_version cached

fetch_pypi_pinned_dependency_version(
    package: str, version: str, dependency: str
) -> str | None

Get the exact pinned version of a dependency required by a specific release of a package on PyPI.

This is only able to detect an exact pin (e.g. dependency==1.2.3). It is intended for packages that pin a compiled dependency to an exact version per release, e.g. pydantic pinning pydantic-core. The package names are compared in their canonical form (PEP 503). A requirement with an environment marker (e.g. dependency==1.2.3; python_version < "3.9") is skipped. The result is cached.

Parameters:

Name Type Description Default
package str

The package name.

required
version str

The release version to inspect.

required
dependency str

The dependency name to look for (e.g. "pydantic-core").

required

Returns:

Type Description
str | None

The exact pinned version of dependency required by package==version, or None if the release has no such exact pin.

Example
>>> from feu.version import fetch_pypi_pinned_dependency_version
>>> version = fetch_pypi_pinned_dependency_version(
...     "pydantic", "2.9.0", "pydantic-core"
... )  # doctest: +SKIP

feu.version.fetch_pypi_project

fetch_pypi_project(package: str) -> PypiProject

Fetch the metadata of a project from PyPI.

One request to the Simple API (https://pypi.org/simple/<name>/, JSON form) gives the versions, the file names, requires-python, yanked and the upload time. The result is cached by canonical project name and is immutable.

Parameters:

Name Type Description Default
package str

The package name. It is canonicalised (PEP 503).

required

Returns:

Type Description
PypiProject

The project.

Raises:

Type Description
RuntimeError

If the request fails.

MissingPackageError

If requests is not installed.

Example
>>> from feu.version import fetch_pypi_project
>>> project = fetch_pypi_project("requests")  # doctest: +SKIP
>>> list(project.releases)[:2]  # doctest: +SKIP
['0.0.1', '0.1.0']

feu.version.fetch_pypi_requires_python

fetch_pypi_requires_python(
    package: str,
) -> Mapping[str, str | None]

Get the requires-python specifier for each release of a package on PyPI.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
Mapping[str, str | None]

A read-only mapping from each release version string to its requires-python specifier (e.g. ">=3.9"), or None if the release has no files or no file declares one. The first file that declares a specifier is used.

Example
>>> from feu.version import fetch_pypi_requires_python
>>> mapping = fetch_pypi_requires_python("requests")  # doctest: +SKIP

feu.version.fetch_pypi_versions

fetch_pypi_versions(
    package: str,
    *,
    start_date: date | str | None = None,
    end_date: date | str | None = None,
    ignore_yanked: bool = True,
) -> tuple[str, ...]

Get the package versions available on PyPI.

Parameters:

Name Type Description Default
package str

The package name.

required
start_date date | str | None

If specified, only the versions released on or after this date (UTC) are returned. The date can be a date object or an ISO 8601 formatted string e.g. '2024-01-01'.

None
end_date date | str | None

If specified, only the versions released on or before this date (UTC) are returned. The date can be a date object or an ISO 8601 formatted string e.g. '2024-12-31'.

None
ignore_yanked bool

If True, yanked versions are excluded from the returned versions.

True

Returns:

Type Description
tuple[str, ...]

A tuple containing the version strings in ascending PEP 440 order. Use [::-1] for the descending order. The release date of a version is the earliest upload time of its files, so a version without any file is dropped when a date bound is given.

Example
>>> from feu.version import fetch_pypi_versions
>>> versions = fetch_pypi_versions("requests")  # doctest: +SKIP
>>> versions = fetch_pypi_versions(
...     "requests", start_date="2024-01-01", end_date="2024-12-31"
... )  # doctest: +SKIP

feu.version.fetch_pypi_wheel_filenames

fetch_pypi_wheel_filenames(
    package: str,
) -> Mapping[str, tuple[str, ...]]

Get the wheel file names for each release of a package on PyPI.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
Mapping[str, tuple[str, ...]]

A read-only mapping from each release version string to a tuple of its wheel file names (an empty tuple if the release has no wheel).

Example
>>> from feu.version import fetch_pypi_wheel_filenames
>>> mapping = fetch_pypi_wheel_filenames("numpy")  # doctest: +SKIP

feu.version.fetch_versions

fetch_versions(
    package: str,
    *,
    lower: str | None = None,
    upper: str | None = None,
) -> tuple[str, ...]

Get the valid stable versions for a given package.

Parameters:

Name Type Description Default
package str

The package name.

required
lower str | None

The lower version bound (inclusive). If None, no lower limit is applied.

None
upper str | None

The upper version bound (exclusive). If None, no upper limit is applied.

None

Returns:

Type Description
tuple[str, ...]

A tuple containing the unique, valid, stable versions in ascending order.

Example
>>> from feu.version import fetch_versions
>>> versions = fetch_versions("requests")  # doctest: +SKIP

feu.version.filter_every_n_versions

filter_every_n_versions(
    versions: Sequence[str], n: int
) -> list[str]

Filter a list of version strings, keeping only every n-th version using 0-based indexing.

This function preserves the original order of the input list and returns a new list containing only the versions at positions that are multiples of n (using 0-based indexing). For example, if n = 2, the function keeps the 0th, 2nd, 4th, ... versions from the list.

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings.

required
n int

The interval for selecting versions. Must be >= 1.

required

Returns:

Type Description
list[str]

A new list containing only every n-th version in versions, starting from index 0.

Raises:

Type Description
ValueError

If n is less than 1.

Example
>>> from feu.version import filter_every_n_versions
>>> versions = filter_every_n_versions(["1.0", "1.1", "1.2", "1.3", "1.5", "1.6"], n=2)
>>> versions
['1.0', '1.2', '1.5']
>>> versions = filter_every_n_versions(["1.0", "1.1", "1.2", "1.3", "1.5", "1.6"], n=1)
>>> versions
['1.0', '1.1', '1.2', '1.3', '1.5', '1.6']

feu.version.filter_last_n_versions

filter_last_n_versions(
    versions: Sequence[str], n: int
) -> list[str]

Return only the last n versions from a list of version strings.

This function preserves the original ordering of the final n elements. If n is greater than the number of versions available, the entire list is returned.

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings.

required
n int

Number of versions to keep from the end of the list. Must be > 0.

required

Returns:

Type Description
list[str]

A new list containing only the last n versions, in order.

Raises:

Type Description
ValueError

If n is less than or equal to 0.

Example
>>> from feu.version import filter_last_n_versions
>>> versions = filter_last_n_versions(["1.0", "1.1", "1.2", "1.3"], n=2)
>>> versions
['1.2', '1.3']
>>> versions = filter_last_n_versions(["1.0", "1.1", "1.2", "1.3"], n=5)
>>> versions
['1.0', '1.1', '1.2', '1.3']

feu.version.filter_range_versions

filter_range_versions(
    versions: Sequence[str],
    lower: str | None = None,
    upper: str | None = None,
) -> list[str]

Filter a list of version strings to include only versions within optional bounds.

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings.

required
lower str | None

The lower version bound (inclusive). If None, no lower limit is applied.

None
upper str | None

The upper version bound (exclusive). If None, no upper limit is applied.

None

Returns:

Type Description
list[str]

A list of version strings that fall within the specified bounds, in the original order.

Raises:

Type Description
InvalidVersion

If a version string is not a valid PEP 440 version.

Example
>>> from feu.version import filter_range_versions
>>> versions = filter_range_versions(
...     ["1.0.0", "1.2.0", "1.3.0", "2.0.0"], lower="1.1.0", upper="2.0.0"
... )
>>> versions
['1.2.0', '1.3.0']
>>> versions = filter_range_versions(["0.9.0", "1.0.0", "1.1.0"], lower="1.0.0")
>>> versions
['1.0.0', '1.1.0']

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, beta b, release candidate rc)
  • 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, in the original order.

Raises:

Type Description
InvalidVersion

If a version string is not a valid PEP 440 version.

Example
>>> 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: Iterable[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 are the strings that don't conform to PEP 440.

Parameters:

Name Type Description Default
versions Iterable[str]

A list of version strings.

required

Returns:

Type Description
list[str]

A list containing only valid version strings, in the original order.

Example
>>> 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_bounds

get_package_bounds(
    packages: Sequence[PackageBounds], name: str
) -> PackageBounds

Return the first PackageBounds matching a given package name.

The name comparison is case-insensitive and treats hyphens and underscores as equivalent (see packaging.utils.canonicalize_name).

Parameters:

Name Type Description Default
packages Sequence[PackageBounds]

A sequence of PackageBounds instances to search.

required
name str

The package name to look up.

required

Returns:

Type Description
PackageBounds

The first PackageBounds whose name matches name.

Raises:

Type Description
ValueError

If no entry matching name is found in packages.

Example
>>> from feu.version import PackageBounds, get_package_bounds
>>> packages = [
...     PackageBounds(
...         name="numpy", lower="1.21", upper="2.0", section="project.dependencies"
...     ),
...     PackageBounds(
...         name="torch", lower="2.0", upper=None, section="project.dependencies"
...     ),
... ]
>>> get_package_bounds(packages, "numpy")
PackageBounds(name='numpy', lower='1.21', upper='2.0', section='project.dependencies')

feu.version.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 or if its version is not a valid PEP 440 version.

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

feu.version.latest_major_versions

latest_major_versions(versions: Sequence[str]) -> list[str]

Return the latest version for each major version in a list of semantic versions.

This function takes a list of semantic version strings (e.g. "1.0.0", "1.2.1", "2.0.0"), groups them by their major version number, and returns only the latest version from each major group (based on minor and patch numbers).

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings in semantic version format.

required

Returns:

Type Description
list[str]

A list containing the latest version for each major version, sorted by major version number. The strings are the ones of versions.

Raises:

Type Description
InvalidVersion

If a version string is not a valid PEP 440 version.

Example
>>> from feu.version import latest_major_versions
>>> versions = latest_major_versions(["1.0.0", "1.1.0", "1.2.0", "1.2.1", "2.0.0"])
>>> versions
['1.2.1', '2.0.0']

feu.version.latest_minor_versions

latest_minor_versions(versions: Sequence[str]) -> list[str]

Return the latest version for each minor version in a list of semantic versions.

This function takes a list of semantic version strings (e.g. "1.0.0", "1.0.1", "1.1.0", "2.0.0"), groups them by their major and minor version numbers, and returns only the latest version from each minor group (based on the patch number).

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings in semantic version format.

required

Returns:

Type Description
list[str]

A list containing the latest version for each minor version, sorted by major and minor version numbers. The strings are the ones of versions.

Raises:

Type Description
InvalidVersion

If a version string is not a valid PEP 440 version.

Example
>>> from feu.version import latest_minor_versions
>>> versions = latest_minor_versions(["1.0.0", "1.0.1", "1.1.0", "1.1.2", "2.0.0", "2.0.3"])
>>> versions
['1.0.1', '1.1.2', '2.0.3']

feu.version.latest_version

latest_version(versions: Sequence[str]) -> str

Return the latest version string in a list of version identifiers.

This function compares version strings according to the PEP 440 specification using :class:packaging.version.Version. It supports standard releases, pre-releases (alpha, beta, release candidates), development releases, post releases, and epoch-based versions.

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings to compare.

required

Returns:

Type Description
str

The highest (latest) version in the list based on PEP 440 ordering, as it is written in versions.

Raises:

Type Description
ValueError

If versions is empty.

InvalidVersion

If a version string is not a valid PEP 440 version.

Example
>>> from feu.version import latest_version
>>> latest_version(["1.0.0", "1.0.1rc1", "1.0.1"])
'1.0.1'
>>> latest_version(["1.2.0", "2.0.0a1"])
'2.0.0a1'
>>> latest_version(["1.0-1", "1.0"])
'1.0-1'

feu.version.parse_version_request

parse_version_request(text: str | None) -> VersionRequest

Parse a version request.

Parameters:

Name Type Description Default
text str | None

The request. None, "" and a blank string request the latest version. A PEP 440 version (e.g. "2.4.0") is an exact request. A wildcard is digits and dots followed by one trailing ".*" (e.g. "2.4.*", "2.*").

required

Returns:

Type Description
VersionRequest

The parsed request.

Raises:

Type Description
ValueError

If text contains a * but is not a valid wildcard (e.g. "*", "2.*.1", "2.4*", "2.4.0rc1.*", "1!2.*").

InvalidVersion

If text is not a valid PEP 440 version (InvalidVersion is a ValueError).

Example
>>> from feu.version import parse_version_request
>>> parse_version_request("2.4.0")
VersionRequest(text='2.4.0', exact=<Version('2.4.0')>, prefix=None)
>>> parse_version_request("2.*")
VersionRequest(text='2.*', exact=None, prefix=(2,))
>>> parse_version_request(None)
VersionRequest(text='', exact=None, prefix=None)

feu.version.partition_package_bounds

partition_package_bounds(
    packages: Sequence[PackageBounds], names: Sequence[str]
) -> tuple[list[PackageBounds], list[PackageBounds]]

Split a sequence of PackageBounds into matched and unmatched by name.

Parameters:

Name Type Description Default
packages Sequence[PackageBounds]

A sequence of PackageBounds instances to filter.

required
names Sequence[str]

The package names to match against.

required

Returns:

Type Description
list[PackageBounds]

A tuple of two lists, both in the order they appear in packages:

list[PackageBounds]
  • The first list contains the PackageBounds instances whose name appears in names.
tuple[list[PackageBounds], list[PackageBounds]]
  • The second list contains the PackageBounds instances whose name does not appear in names.
Example
>>> from feu.version import PackageBounds, partition_package_bounds
>>> packages = [
...     PackageBounds(
...         name="numpy", lower="1.21", upper="2.0", section="project.dependencies"
...     ),
...     PackageBounds(
...         name="torch", lower="2.0", upper=None, section="project.dependencies"
...     ),
... ]
>>> matched, unmatched = partition_package_bounds(packages, ["numpy"])
>>> matched
[PackageBounds(name='numpy', lower='1.21', upper='2.0', section='project.dependencies')]
>>> unmatched
[PackageBounds(name='torch', lower='2.0', upper=None, section='project.dependencies')]

feu.version.read_pyproject_bounds

read_pyproject_bounds(
    path: str | Path, *, package: str | None = None
) -> list[PackageBounds]

Read a pyproject.toml file and return the version bounds of its dependencies.

The file is parsed once. The following standard sections are read, in this order:

  • [project.dependencies]
  • [project.optional-dependencies.*]
  • [dependency-groups.*] (the {include-group = ...} entries of PEP 735 are skipped)

The names of the returned bounds are canonical (PEP 503).

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required
package str | None

If specified, only the occurrences of this package are returned. The comparison uses the canonical names, so it is case-insensitive and treats hyphens, underscores and dots as equivalent.

None

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per occurrence in the sections above. The section field gives the section, e.g. 'project.optional-dependencies.dev'.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_bounds("pyproject.toml", package="numpy")
for b in bounds:
    print(b.section, b.lower, b.upper)

feu.version.read_pyproject_dependencies

read_pyproject_dependencies(
    path: str | Path,
) -> list[PackageBounds]

Read a pyproject.toml file and return the bounds for all packages defined in [project.dependencies].

This function is kept for the scripts that copy dev/generate_versions.py; use read_pyproject_bounds in new code.

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per entry in

list[PackageBounds]

[project.dependencies]. Returns an empty list if the section

list[PackageBounds]

is absent or empty.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_dependencies("pyproject.toml")
for b in bounds:
    print(b.name, b.lower, b.upper)

feu.version.read_pyproject_optional_dependencies

read_pyproject_optional_dependencies(
    path: str | Path,
) -> list[PackageBounds]

Read a pyproject.toml file and return the bounds for all packages defined in [project.optional-dependencies].

All groups under [project.optional-dependencies] are included. The section field of each returned PackageBounds identifies the group, e.g. 'project.optional-dependencies.dev'.

This function is kept for the scripts that copy dev/generate_versions.py; use read_pyproject_bounds in new code.

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per entry across all

list[PackageBounds]

optional-dependency groups, in the order they appear in the file.

list[PackageBounds]

Returns an empty list if the section is absent or empty.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_optional_dependencies("pyproject.toml")
for b in bounds:
    print(b.name, b.section, b.lower, b.upper)

feu.version.read_pyproject_package_bounds

read_pyproject_package_bounds(
    path: str | Path, package: str
) -> list[PackageBounds]

Read a pyproject.toml file and return the version bounds for a package.

This is read_pyproject_bounds(path, package=package), kept for the existing callers.

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required
package str

The name of the package to look up.

required

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per occurrence of the

list[PackageBounds]

package across all sections. Returns an empty list if the package

list[PackageBounds]

is not found.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_package_bounds("pyproject.toml", "numpy")
for b in bounds:
    print(b.section, b.lower, b.upper)

feu.version.sort_versions

sort_versions(
    versions: Sequence[str], reverse: bool = False
) -> list[str]

Sort a list of version strings in ascending or descending order.

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings.

required
reverse bool

If False, sort in ascending order; if True, sort in descending order.

False

Returns:

Type Description
list[str]

A new list of version strings sorted according to PEP 440 version order. The input is not modified.

Raises:

Type Description
InvalidVersion

If a version string is not a valid PEP 440 version.

Example
>>> from feu.version import sort_versions
>>> sort_versions(["1.0.0", "1.2.0", "1.1.0"])
['1.0.0', '1.1.0', '1.2.0']
>>> sort_versions(["1.0.0", "1.2.0", "1.1.0"], reverse=True)
['1.2.0', '1.1.0', '1.0.0']

feu.version.unique_versions

unique_versions(versions: Sequence[str]) -> list[str]

Return a list of unique versions while preserving order.

Parameters:

Name Type Description Default
versions Sequence[str]

A list of version strings.

required

Returns:

Type Description
list[str]

A list containing only unique version strings, preserving the original order of first occurrence.

Example
>>> from feu.version import unique_versions, sort_versions
>>> versions = sort_versions(unique_versions(["1.0.0", "1.0.1", "1.0.0", "1.2.0"]))
>>> versions
['1.0.0', '1.0.1', '1.2.0']

feu.version.request

Contain the parser of a version request.

A version argument of feu is a request, not a version. It has three forms: an exact version ("2.4.0"), a release-prefix wildcard ("2.4.*", "2.*") and the latest version ("" or None).

feu.version.request.VersionRequest dataclass

Represent a version request.

Use parse_version_request to create an instance.

Parameters:

Name Type Description Default
text str

The request as given, stripped: "" (the latest), "2.4.*" (a wildcard) or "2.4.0" (an exact version).

required
exact Version | None

The requested version for an exact request, otherwise None.

None
prefix tuple[int, ...] | None

The release prefix for a wildcard request, e.g. (2, 4) for "2.4.*", otherwise None.

None
Example
>>> from feu.version import parse_version_request
>>> parse_version_request("2.4.*")
VersionRequest(text='2.4.*', exact=None, prefix=(2, 4))

feu.version.request.VersionRequest.is_latest property

is_latest: bool

Indicate if the request is for the latest version.

Returns:

Type Description
bool

True for "" (and None), otherwise False.

Example
>>> from feu.version import parse_version_request
>>> parse_version_request("").is_latest
True
>>> parse_version_request("2.*").is_latest
False

feu.version.request.VersionRequest.entirely_below

entirely_below(version: Version) -> bool

Indicate if every version that satisfies the request is lower than a version.

Parameters:

Name Type Description Default
version Version

The version to compare with.

required

Returns:

Type Description
bool

True if the whole request lies below version. A wildcard that straddles version (e.g. "2.*" and 2.2.2) and the latest request are not entirely below.

Example
>>> from packaging.version import Version
>>> from feu.version import parse_version_request
>>> parse_version_request("2.1.*").entirely_below(Version("2.2.2"))
True
>>> parse_version_request("2.*").entirely_below(Version("2.2.2"))
False

feu.version.request.VersionRequest.matches

matches(version: Version) -> bool

Indicate if a version satisfies the request.

An exact request matches the version that is equal to it. A wildcard request matches the versions whose release segment, padded with zeros, starts with the prefix; pre-releases never match a wildcard. The latest request matches every version.

Parameters:

Name Type Description Default
version Version

The version to check.

required

Returns:

Type Description
bool

True if version satisfies the request, otherwise False.

Example
>>> from packaging.version import Version
>>> from feu.version import parse_version_request
>>> request = parse_version_request("2.4.*")
>>> request.matches(Version("2.4.17"))
True
>>> request.matches(Version("2.40"))
False

feu.version.request.parse_version_request

parse_version_request(text: str | None) -> VersionRequest

Parse a version request.

Parameters:

Name Type Description Default
text str | None

The request. None, "" and a blank string request the latest version. A PEP 440 version (e.g. "2.4.0") is an exact request. A wildcard is digits and dots followed by one trailing ".*" (e.g. "2.4.*", "2.*").

required

Returns:

Type Description
VersionRequest

The parsed request.

Raises:

Type Description
ValueError

If text contains a * but is not a valid wildcard (e.g. "*", "2.*.1", "2.4*", "2.4.0rc1.*", "1!2.*").

InvalidVersion

If text is not a valid PEP 440 version (InvalidVersion is a ValueError).

Example
>>> from feu.version import parse_version_request
>>> parse_version_request("2.4.0")
VersionRequest(text='2.4.0', exact=<Version('2.4.0')>, prefix=None)
>>> parse_version_request("2.*")
VersionRequest(text='2.*', exact=None, prefix=(2,))
>>> parse_version_request(None)
VersionRequest(text='', exact=None, prefix=None)

feu.version.pypi

Contain functions to fetch package metadata from PyPI.

The metadata of a project is fetched once with the Simple API in its JSON form (PEP 691 and PEP 700), cached by canonical project name, and returned as immutable values. Everything else (versions, wheel file names, requires-python) is derived from it.

feu.version.pypi.PypiFile dataclass

Represent a file of a release published on PyPI.

Parameters:

Name Type Description Default
filename str

The file name, e.g. "numpy-2.0.2.tar.gz".

required
requires_python str | None

The requires-python specifier of the file (e.g. ">=3.9"), or None.

required
yanked bool

True if the file is yanked.

required
uploaded datetime | None

The upload time (UTC), or None if unknown.

required

feu.version.pypi.PypiProject dataclass

Represent a project published on PyPI.

Parameters:

Name Type Description Default
name str

The canonical project name (PEP 503).

required
releases Mapping[str, tuple[PypiFile, ...]]

The files of each release, in PEP 440 ascending order of the release versions. The mapping is read-only. A release without any recognised file maps to an empty tuple.

required
Example
>>> from feu.version.pypi import PypiProject
>>> PypiProject(name="numpy", releases={})
PypiProject(name='numpy', releases={})

feu.version.pypi.fetch_pypi_pinned_dependency_version cached

fetch_pypi_pinned_dependency_version(
    package: str, version: str, dependency: str
) -> str | None

Get the exact pinned version of a dependency required by a specific release of a package on PyPI.

This is only able to detect an exact pin (e.g. dependency==1.2.3). It is intended for packages that pin a compiled dependency to an exact version per release, e.g. pydantic pinning pydantic-core. The package names are compared in their canonical form (PEP 503). A requirement with an environment marker (e.g. dependency==1.2.3; python_version < "3.9") is skipped. The result is cached.

Parameters:

Name Type Description Default
package str

The package name.

required
version str

The release version to inspect.

required
dependency str

The dependency name to look for (e.g. "pydantic-core").

required

Returns:

Type Description
str | None

The exact pinned version of dependency required by package==version, or None if the release has no such exact pin.

Example
>>> from feu.version import fetch_pypi_pinned_dependency_version
>>> version = fetch_pypi_pinned_dependency_version(
...     "pydantic", "2.9.0", "pydantic-core"
... )  # doctest: +SKIP

feu.version.pypi.fetch_pypi_project

fetch_pypi_project(package: str) -> PypiProject

Fetch the metadata of a project from PyPI.

One request to the Simple API (https://pypi.org/simple/<name>/, JSON form) gives the versions, the file names, requires-python, yanked and the upload time. The result is cached by canonical project name and is immutable.

Parameters:

Name Type Description Default
package str

The package name. It is canonicalised (PEP 503).

required

Returns:

Type Description
PypiProject

The project.

Raises:

Type Description
RuntimeError

If the request fails.

MissingPackageError

If requests is not installed.

Example
>>> from feu.version import fetch_pypi_project
>>> project = fetch_pypi_project("requests")  # doctest: +SKIP
>>> list(project.releases)[:2]  # doctest: +SKIP
['0.0.1', '0.1.0']

feu.version.pypi.fetch_pypi_requires_python

fetch_pypi_requires_python(
    package: str,
) -> Mapping[str, str | None]

Get the requires-python specifier for each release of a package on PyPI.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
Mapping[str, str | None]

A read-only mapping from each release version string to its requires-python specifier (e.g. ">=3.9"), or None if the release has no files or no file declares one. The first file that declares a specifier is used.

Example
>>> from feu.version import fetch_pypi_requires_python
>>> mapping = fetch_pypi_requires_python("requests")  # doctest: +SKIP

feu.version.pypi.fetch_pypi_versions

fetch_pypi_versions(
    package: str,
    *,
    start_date: date | str | None = None,
    end_date: date | str | None = None,
    ignore_yanked: bool = True,
) -> tuple[str, ...]

Get the package versions available on PyPI.

Parameters:

Name Type Description Default
package str

The package name.

required
start_date date | str | None

If specified, only the versions released on or after this date (UTC) are returned. The date can be a date object or an ISO 8601 formatted string e.g. '2024-01-01'.

None
end_date date | str | None

If specified, only the versions released on or before this date (UTC) are returned. The date can be a date object or an ISO 8601 formatted string e.g. '2024-12-31'.

None
ignore_yanked bool

If True, yanked versions are excluded from the returned versions.

True

Returns:

Type Description
tuple[str, ...]

A tuple containing the version strings in ascending PEP 440 order. Use [::-1] for the descending order. The release date of a version is the earliest upload time of its files, so a version without any file is dropped when a date bound is given.

Example
>>> from feu.version import fetch_pypi_versions
>>> versions = fetch_pypi_versions("requests")  # doctest: +SKIP
>>> versions = fetch_pypi_versions(
...     "requests", start_date="2024-01-01", end_date="2024-12-31"
... )  # doctest: +SKIP

feu.version.pypi.fetch_pypi_wheel_filenames

fetch_pypi_wheel_filenames(
    package: str,
) -> Mapping[str, tuple[str, ...]]

Get the wheel file names for each release of a package on PyPI.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
Mapping[str, tuple[str, ...]]

A read-only mapping from each release version string to a tuple of its wheel file names (an empty tuple if the release has no wheel).

Example
>>> from feu.version import fetch_pypi_wheel_filenames
>>> mapping = fetch_pypi_wheel_filenames("numpy")  # doctest: +SKIP

feu.version.package

Contain functions to fetch the versions of a package published on PyPI.

feu.version.package.fetch_latest_major_versions_map

fetch_latest_major_versions_map(
    packages: Sequence[PackageBounds],
    *,
    include_lower_bound: bool = False,
) -> dict[str, list[str]]

Fetch the latest major versions for a sequence of packages.

This function is kept for the scripts that copy dev/generate_versions.py; use fetch_package_versions in new code.

Parameters:

Name Type Description Default
packages Sequence[PackageBounds]

A sequence of PackageBounds instances, typically obtained from read_pyproject_bounds. If a package appears more than once in packages (e.g. because it was found in multiple sections), the last entry wins.

required
include_lower_bound bool

If True, the first stable version at or above each package's lower bound is included in its version list. Has no effect for packages whose lower bound is None.

False

Returns:

Type Description
dict[str, list[str]]

A dictionary mapping each package name to the list of latest major version strings returned by fetch_latest_versions.

Example
>>> from feu.version import PackageBounds, fetch_latest_major_versions_map
>>> bounds = [PackageBounds("requests", "2.28", None, "project.dependencies")]
>>> versions = fetch_latest_major_versions_map(
...     bounds, include_lower_bound=True
... )  # doctest: +SKIP

feu.version.package.fetch_latest_minor_versions_map

fetch_latest_minor_versions_map(
    packages: Sequence[PackageBounds],
    *,
    include_lower_bound: bool = False,
) -> dict[str, list[str]]

Fetch the latest minor versions for a sequence of packages.

This function is kept for the scripts that copy dev/generate_versions.py; use fetch_package_versions in new code.

Parameters:

Name Type Description Default
packages Sequence[PackageBounds]

A sequence of PackageBounds instances, typically obtained from read_pyproject_bounds. If a package appears more than once in packages (e.g. because it was found in multiple sections), the last entry wins.

required
include_lower_bound bool

If True, the first stable version at or above each package's lower bound is included in its version list. Has no effect for packages whose lower bound is None.

False

Returns:

Type Description
dict[str, list[str]]

A dictionary mapping each package name to the list of latest minor version strings returned by fetch_latest_versions.

Example
>>> from feu.version import PackageBounds, fetch_latest_minor_versions_map
>>> bounds = [PackageBounds("requests", "2.28", None, "project.dependencies")]
>>> versions = fetch_latest_minor_versions_map(
...     bounds, include_lower_bound=True
... )  # doctest: +SKIP

feu.version.package.fetch_latest_stable_version

fetch_latest_stable_version(package: str) -> str

Get the latest stable valid version for a given package.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
str

The latest stable valid version.

Raises:

Type Description
ValueError

If the package has no stable valid version.

Example
>>> from feu.version import fetch_latest_stable_version
>>> version = fetch_latest_stable_version("requests")  # doctest: +SKIP

feu.version.package.fetch_latest_version

fetch_latest_version(package: str) -> str

Get the latest valid version for a given package.

The latest version can be a pre-release, post-release or development release.

Parameters:

Name Type Description Default
package str

The package name.

required

Returns:

Type Description
str

The latest valid version.

Raises:

Type Description
ValueError

If the package has no valid version.

Example
>>> from feu.version import fetch_latest_version
>>> version = fetch_latest_version("requests")  # doctest: +SKIP

feu.version.package.fetch_latest_versions

fetch_latest_versions(
    package: str,
    *,
    group: Literal["major", "minor"],
    lower: str | None = None,
    upper: str | None = None,
    include_lower_bound: bool = False,
) -> tuple[str, ...]

Get the latest version of each major (or minor) version of a package.

Parameters:

Name Type Description Default
package str

The package name.

required
group Literal['major', 'minor']

"major" to get the latest version of each major version, "minor" for each major.minor version.

required
lower str | None

The lower version bound (inclusive). If None, no lower limit is applied.

None
upper str | None

The upper version bound (exclusive). If None, no upper limit is applied.

None
include_lower_bound bool

If True and lower is not None, the first stable version at or above lower is included in the result. This ensures the lower bound itself is always represented, even if it is not the latest patch of its group. If lower is None, this argument has no effect.

False

Returns:

Type Description
tuple[str, ...]

A tuple containing the latest version of each group, in ascending order. If include_lower_bound is True and lower is not None, the first stable version at or above lower is also included.

Raises:

Type Description
ValueError

If group is not "major" or "minor".

Example
>>> from feu.version import fetch_latest_versions
>>> versions = fetch_latest_versions(
...     "requests", group="minor", lower="2.28"
... )  # doctest: +SKIP

feu.version.package.fetch_package_versions

fetch_package_versions(
    pyproject: str | Path,
    *,
    major_only: Collection[str] = ("packaging",),
    include_lower_bound: bool = True,
) -> dict[str, list[str]]

Fetch the versions to test of the dependencies of a project.

The dependencies are read from [project.dependencies] and [project.optional-dependencies.*] of the pyproject.toml file (not from the [dependency-groups.*]). For each package, the latest version of each minor version at or above the lower bound is returned, or the latest version of each major version for the packages of major_only.

Parameters:

Name Type Description Default
pyproject str | Path

Path to the pyproject.toml file.

required
major_only Collection[str]

The packages for which only the latest version of each major version is returned. The names are compared in their canonical form.

('packaging',)
include_lower_bound bool

If True, the first stable version at or above the lower bound of each package is included.

True

Returns:

Type Description
dict[str, list[str]]

A dictionary mapping each canonical package name to its versions, sorted by package name. If a package appears more than once, the last entry wins.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
>>> from feu.version import fetch_package_versions
>>> versions = fetch_package_versions("pyproject.toml")  # doctest: +SKIP

feu.version.package.fetch_versions

fetch_versions(
    package: str,
    *,
    lower: str | None = None,
    upper: str | None = None,
) -> tuple[str, ...]

Get the valid stable versions for a given package.

Parameters:

Name Type Description Default
package str

The package name.

required
lower str | None

The lower version bound (inclusive). If None, no lower limit is applied.

None
upper str | None

The upper version bound (exclusive). If None, no upper limit is applied.

None

Returns:

Type Description
tuple[str, ...]

A tuple containing the unique, valid, stable versions in ascending order.

Example
>>> from feu.version import fetch_versions
>>> versions = fetch_versions("requests")  # doctest: +SKIP

feu.version.pyproject

Contain functions to read package version bounds from a pyproject.toml file.

feu.version.pyproject.read_pyproject_bounds

read_pyproject_bounds(
    path: str | Path, *, package: str | None = None
) -> list[PackageBounds]

Read a pyproject.toml file and return the version bounds of its dependencies.

The file is parsed once. The following standard sections are read, in this order:

  • [project.dependencies]
  • [project.optional-dependencies.*]
  • [dependency-groups.*] (the {include-group = ...} entries of PEP 735 are skipped)

The names of the returned bounds are canonical (PEP 503).

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required
package str | None

If specified, only the occurrences of this package are returned. The comparison uses the canonical names, so it is case-insensitive and treats hyphens, underscores and dots as equivalent.

None

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per occurrence in the sections above. The section field gives the section, e.g. 'project.optional-dependencies.dev'.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_bounds("pyproject.toml", package="numpy")
for b in bounds:
    print(b.section, b.lower, b.upper)

feu.version.pyproject.read_pyproject_dependencies

read_pyproject_dependencies(
    path: str | Path,
) -> list[PackageBounds]

Read a pyproject.toml file and return the bounds for all packages defined in [project.dependencies].

This function is kept for the scripts that copy dev/generate_versions.py; use read_pyproject_bounds in new code.

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per entry in

list[PackageBounds]

[project.dependencies]. Returns an empty list if the section

list[PackageBounds]

is absent or empty.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_dependencies("pyproject.toml")
for b in bounds:
    print(b.name, b.lower, b.upper)

feu.version.pyproject.read_pyproject_optional_dependencies

read_pyproject_optional_dependencies(
    path: str | Path,
) -> list[PackageBounds]

Read a pyproject.toml file and return the bounds for all packages defined in [project.optional-dependencies].

All groups under [project.optional-dependencies] are included. The section field of each returned PackageBounds identifies the group, e.g. 'project.optional-dependencies.dev'.

This function is kept for the scripts that copy dev/generate_versions.py; use read_pyproject_bounds in new code.

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per entry across all

list[PackageBounds]

optional-dependency groups, in the order they appear in the file.

list[PackageBounds]

Returns an empty list if the section is absent or empty.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_optional_dependencies("pyproject.toml")
for b in bounds:
    print(b.name, b.section, b.lower, b.upper)

feu.version.pyproject.read_pyproject_package_bounds

read_pyproject_package_bounds(
    path: str | Path, package: str
) -> list[PackageBounds]

Read a pyproject.toml file and return the version bounds for a package.

This is read_pyproject_bounds(path, package=package), kept for the existing callers.

Parameters:

Name Type Description Default
path str | Path

Path to the pyproject.toml file.

required
package str

The name of the package to look up.

required

Returns:

Type Description
list[PackageBounds]

A list of PackageBounds instances, one per occurrence of the

list[PackageBounds]

package across all sections. Returns an empty list if the package

list[PackageBounds]

is not found.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

TOMLDecodeError

If the file is not valid TOML.

Example
bounds = read_pyproject_package_bounds("pyproject.toml", "numpy")
for b in bounds:
    print(b.section, b.lower, b.upper)