pyproject#

Tools for loading, inspecting, and updating pyproject.toml.

class Pyproject(document: PyprojectTOML, source: IO | Path | None = None)[source]#

Bases: object

Read-only representation of a pyproject.toml file.

classmethod load(source: IO | Path | str = PosixPath('pyproject.toml'), *, session: Session | None = None) → Self[source]#

Load a pyproject.toml file from a file, I/O stream, or str.

dumps() → str[source]#
get_table(dotted_header: str, /, *, create: bool = False, fallback: Any = <object object>) → Mapping[str, Any][source]#
final has_table(dotted_header: str, /) → bool[source]#
final get_package_name() → str | None[source]#
final get_package_name(*, raise_on_missing: Literal[False]) → str | None
final get_package_name(*, raise_on_missing: Literal[True]) → str
final get_repo_url() → str[source]#

Extract the source URL from the project table in pyproject.toml.

>>> Pyproject.load().get_repo_url()
'https://github.com/ComPWA/policy'
final get_supported_python_versions() → list[Literal['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15']][source]#

Extract sorted, supported Python versions from package classifiers.

>>> Pyproject.load().get_supported_python_versions()
['3.11', '3.12', '3.13', '3.14', '3.15']
class ModifiablePyproject(document: PyprojectTOML, source: IO | Path | None = None, changelog: Changelog = NOTHING)[source]#

Bases: Pyproject, ModifiableResource

Stateful representation of a pyproject.toml file.

Use this class to apply multiple modifications to a pyproject.toml file in separate sub-hooks. The modifications are dumped once the context is exited.

classmethod load(source: IO | Path | str = PosixPath('pyproject.toml'), *, session: Session | None = None) → Self[source]#

Load a pyproject.toml file from a file, I/O stream, or str.

dumps() → str[source]#
dump(target: IO | Path | str | None = None) → None[source]#

Write the in-memory representation to the working tree.

get_table(dotted_header: str, /, *, create: bool = False, fallback: Any = <object object>) → MutableMapping[str, Any][source]#
add_dependency(requirement: str, /, *, extra: str | OrderedCollection[str] | None = None, group: str | OrderedCollection[str] | None = None) → None[source]#
move_dependencies_to_group(packages: OrderedCollection[str], group: str) → None[source]#

Move existing declarations without dropping constraints or included groups.

remove_empty_dependency_groups() → None[source]#
remove_dependency(package: str, /, ignored_sections: ExplicitCollection[str] | None = None) → None[source]#
property changelog: list[str][source]#

Changes made to the in-memory representation.

class ModifiablePixi(document: PyprojectTOML, source: IO | Path | None = None, changelog: Changelog = NOTHING)[source]#

Bases: ModifiablePyproject

Session-owned representation of pixi.toml.

classmethod load(source: IO | Path | str = PosixPath('pixi.toml'), *, session: Session | None = None) → Self[source]#

Load a pyproject.toml file from a file, I/O stream, or str.

complies_with_subset(settings: Mapping, minimal_settings: Mapping, *, exact_value_match: bool = True) → bool[source]#

Compare if a nested mapping fits inside another nested mapping.

>>> complies_with_subset(
...     {"channels": ["conda-forge"]},
...     {"channels": ["conda-forge"], "platforms": ["linux-64"]},
... )
False
>>> complies_with_subset(
...     {"channels": ["conda-forge"], "platforms": ["linux-64"]},
...     {"channels": ["conda-forge"]},
... )
True
>>> complies_with_subset(
...     {"channels": ["conda-forge", "default"]},
...     {"channels": ["conda-forge"]},
...     exact_value_match=False,
... )
True
has_pyproject_package_name(session: Session, /) → bool[source]#
has_dependency(pyproject: Pyproject, /, package: str | tuple[str, ...], group: str | ExplicitCollection[str] | None = None) → bool[source]#

Check whether a package is listed as a dependency.

If a group is given, the search is limited to that group and the groups it pulls in through include-group.

get_constraints_file(python_version: Literal['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15']) → Path | None[source]#
load_pyproject_toml(source: IO | Path | str, modifiable: bool) → PyprojectTOML[source]#

Load a pyproject.toml file from a file, I/O stream, or str.

The modifiable flag determines which parser to use:

  • False: use tomli, which is faster, but does not preserve comments and formatting.

  • True: uses tomlkit, which is slower, but preservers comments and formatting.

Submodules and Subpackages