Hello everybody. I got a mono-repo for libraries ...
# general
t
Hello everybody. I got a mono-repo for libraries where each library is to be publish individually (as got different legacy consumers). They are all configured with poetry and I would love if I can implement individual versioning by using
poetry version xxx
(patch, minor, major). So each publish library has its own cadence depending on the changes. I don’t see anything option in pants to allow versioning (specially individually) but I might be missing something. Is this, or another similar option, supported? As an alternative, I was thinking it might just be ok to add a macro that runs just before the package state (but only if the system has detected changes). Having an individual version and increasing the version number for all packages is also an option, but that means we deploy all libraries all the time (even if there aren’t changes) what ain’t ideal. Other options/ideas welcomed! Thanks in advance!
h
How are you planning to build these libraries in Pants? As wheels, with a generated setup.py? Or with handwritten setup.py/pyproject.toml?
t
Hi @happy-kitchen-89482, I am just using the poetry build-system (so this in the poetry file)
Copy code
[tool.poetry]
name = "library_1"
version = "2.0.0"
description = "my internal library"
authors = ["<mailto:blabla@blablabla.com|blabla@blablabla.com>"]
readme = "README.md"
repository = "<https://ohhh-this-url-is-amazing/but-is-not-real>"

[tool.poetry.dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
I have created a publish macro like this:
Copy code
# flake8: noqa: F821
def poetry_distribution(name, **kwargs):
    resources(name="package_data", sources=["pyproject.toml", "README.md"])

    python_distribution(
        name="dist",
        dependencies=[":package_data", f"src/python/{name}/src", "//:root"],
        provides=python_artifact(name=name),
        generate_setup=False,
    )
Then I have BUILD file on the same folder with the following
Copy code
poetry_distribution(
    name="name-of-my-library",
)
the project structure is something like this:
Copy code
├── BUILD
├── dependencies.lock
├── dist
│   ├── library-1-2.0.0-py2.py3-none-any.whl
│   ├── library-1-2.0.0.tar.gz
│   ├── library-2-5.0.0-py2.py3-none-any.whl
│   ├── library-2-5.0.0.tar.gz
│   ├── library-3-3.0.0-py2.py3-none-any.whl
│   ├── library-3-3.0.0.tar.gz
│   ├── library-4-2.0.0-py2.py3-none-any.whl
│   └── library-4-2.0.0.tar.gz
├── pants
├── pants.toml
├── pants_plugins
│   ├── BUILD
│   └── macros.py <- This is where I have put the macro
├── pyproject.toml
├── setup.cfg
└── src
    └── python
        ├── library-1
        │   ├── BUILD
        │   ├── README.md
        │   ├── pyproject.toml
        │   ├── src
        │   │   ├── BUILD
        │   │   └── library-1.py
        │   └── test
        │       ├── BUILD
        │       └── test_library-1.py
        ├── library-2
        │   ├── BUILD
        │   ├── README.md
        │   ├── pyproject.toml
        │   └── src
        │       ├── BUILD
        │       ├── library-2.py
        │       ├── test_something_else_library-2.py
        │       └── test_library-2.py
        ├── library-3
        │   ├── BUILD
        │   ├── README.md
        │   ├── pyproject.toml
        │   └── src
        │       ├── BUILD
        │       ├── __init__.py
        │       ├── library-3.py
        │       └── test_library-3.py
        └── ppl_library-4
            ├── BUILD
            ├── README.md
            ├── pyproject.toml
            └── src
                ├── BUILD
                ├── ppl_library-4.py
                └── test_library-4.py
and the only root source config in the pants.toml I got so far (but all seems to be working) is this:
Copy code
[source]
root_patterns = ['/src/python/*/src', '/']
And, this also in the pants.toml to configure the macro:
Copy code
build_file_prelude_globs = ["pants_plugins/macros.py"]
Be aware I am just playing with this projects for evaluation. The setup.cfg file has the flake8 configuration. I can paste it if you require it but I don’t think is relevant (I plan to move it into the pants.toml file at some point). Thanks in advance!
h
That
poetry_distribution
macro is pretty neat!
👍 1
So am I understanding correctly that you want to bump the version in a
pyproject.toml
when that project's code changes, and then also change the references to that project in its dependers?
t
More or less. The idea would be that if one of the pyproject.toml changes. The dependers will also need to increase their pyproject.toml version. An example. If I got 3 pyproject.toml that then I publish as libraries, called A,B and C. Assuming dependencies goes like this C -> B -> A. Meaning, B depends on A and C depends on B. • If A changes, I would like the version number for A, B and C to increase. • If B changes, I would like the version of B and C to change. • If C changes, Then I would like only the version in C to change. Does this make sense? A bonus extra would be to detect what number to increase depending on the commit (using git commitizen or similar) but I can live without that 😄
h
Thanks for the clarification. Could you open a ticket for this at https://github.com/pantsbuild/pants/issues/new/choose ?
With all of the detail you've provided above?
👍 1
t
I will. Not sure when but I will 😄 Thanks agian!
done it https://github.com/pantsbuild/pants/issues/18179 The more I think about it, the more I see it as needing for a plugin (or maybe the shell command can do some magic). I suspect is not that difficult to detect and increase one of the numbers, the commitizen stuff is an extra but will be a great addition IMO.