stouputils.continuous_delivery.pyproject module#
Utilities for reading, writing and managing pyproject.toml files.
This module provides functions to handle pyproject.toml files, including reading, writing, version management and TOML formatting capabilities.
read_pyproject: Read the pyproject.toml file.
write_pyproject: Write to the pyproject.toml file.
format_toml_lists: Format TOML lists with proper indentation.
increment_version_from_input: Increment the patch version number.
increment_version_from_pyproject: Increment version in pyproject.toml.
get_version_from_pyproject: Get version from pyproject.toml.
- read_pyproject(
- pyproject_path: str,
Read the pyproject.toml file.
- Parameters:
pyproject_path – Path to the pyproject.toml file.
- Returns:
The content of the pyproject.toml file.
- Return type:
dict[str, Any]
Example
>>> content = read_pyproject("pyproject.toml") >>> "." in content["project"]["version"] True
- format_toml_lists(content: str) str[source]#
Format TOML lists with indentation.
- Parameters:
content (str) – The content of the pyproject.toml file.
- Returns:
The formatted content with properly indented lists.
- Return type:
str
Example
>>> toml_content = '''[project] ... dependencies = [ "tqdm>=4.0.0", "requests>=2.20.0", "pyyaml>=6.0.0", ]''' >>> format_toml_lists(toml_content).replace("\t", " ") == '''[project] ... dependencies = [ ... "tqdm>=4.0.0", ... "requests>=2.20.0", ... "pyyaml>=6.0.0", ... ]''' True
- write_pyproject(
- path: str,
- content: dict[str, Any],
Write to the pyproject.toml file with properly indented lists.
- Parameters:
path – Path to the pyproject.toml file.
content – Content to write to the pyproject.toml file.
- increment_version_from_input(version: str) str[source]#
Increment the version.
- Parameters:
version – The version to increment. (ex: “0.1.0”)
- Returns:
The incremented version. (ex: “0.1.1”)
- Return type:
str
Example
>>> increment_version_from_input("0.1.0") '0.1.1' >>> increment_version_from_input("1.2.9") '1.2.10'