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')) T[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) 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']][source]#

Extract sorted, supported Python versions from package classifiers.

>>> Pyproject.load().get_supported_python_versions()
['3.9', '3.10', '3.11', '3.12']
class ModifiablePyproject(document: PyprojectTOML, source: IO | Path | None = None, changelog: list[str] = NOTHING)[source]#

Bases: Pyproject, AbstractContextManager

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')) T[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]#
get_table(dotted_header: str, create: bool = False) MutableMapping[str, Any][source]#
add_dependency(package: str, dependency_group: str | Sequence[str] | None = None, optional_key: str | Sequence[str] | None = None) None[source]#
remove_dependency(package: str, ignored_sections: Iterable[str] | None = None) None[source]#
property changelog: list[str][source]#
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() bool[source]#
get_constraints_file(python_version: Literal['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']) 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 rtoml, which is faster, but does not preserve comments and formatting.

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

Submodules and Subpackages