I have a lot of first party python packages in a m...
# general
g
I have a lot of first party python packages in a monorepo and in their pyproject.toml files all have their versions set to 0.0.0 and the local deps are referenced using paths, i.e.
Copy code
[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.
Copy code
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))
b
I don't know the answer to the actual question you're asking... but, just checking: are these distributions published as libraries, or are they only published as executable artifacts (e.g. pex, docker images)? If the latter, I think the typical approach is to skip the `python_distribution`s and just let pants dependency inference pull individual files together, rather than wrap them up in distributions.
g
These are published as libraries and then slurped up and used in Databricks notebooks. Eventually we aim to use only docker container with PEX but I need to support both models during the transition.
👍 1
I’ve thought about it over the weekend and I’m thinking about creating a new target that takes in the pyproject.toml as a source and outputs the file transformed and then pass that into the python_distribution.
I also might just write something that does them all in the monorepo before running pants since I don’t need to support this long term.
Small go program for the win! 🏆