gentle-flower-25372
03/23/2024, 12:54 PM[tool.poetry]
name = "package-name"
version = "0.0.0"
description = ""
authors = [""]
packages = [
{ include = "package_name" },
]
[tool.poetry.dependencies]
python = ">=3.9,<3.10"
dep-a = { path = "../../packages/dep-a", develop = true }
dep-b = { path = "../../packages/dep-b", develop = true }
How can I do something like this in pants before packaging the dist? I think the answer is a custom plugin as described in the python_distribution docs but I want to be sure just in case that won’t work or is the wrong path.
import tomlkit
# Path to TOML file
file_path = "pyproject.toml"
# The version number to update the package and it's dependencies to
new_version = "1.2.3"
# Read the existing TOML file
with open(file_path, "r") as file:
data = tomlkit.parse(file.read())
# Update the version in the [tool.poetry] section
data["tool"]["poetry"]["version"] = new_version
# Loop through each dependency in [tool.poetry.dependencies]
for dep, details in data["tool"]["poetry"]["dependencies"].items():
# Check if this dependency has a 'path' property
if isinstance(details, dict) and "path" in details:
# Update this dependency to the new version, removing the 'path' and 'develop' keys
data["tool"]["poetry"]["dependencies"][dep] = new_version
# Write the updated TOML data back to the file
with open(file_path, "w") as file:
file.write(tomlkit.dumps(data))
broad-processor-92400
03/24/2024, 9:46 PMgentle-flower-25372
03/24/2024, 9:47 PMgentle-flower-25372
03/24/2024, 9:48 PMgentle-flower-25372
03/24/2024, 9:49 PMgentle-flower-25372
03/24/2024, 9:51 PM