mtkennerly / poetry-dynamic-versioning

Plugin for Poetry to enable dynamic versioning based on VCS tags
MIT License
605 stars 35 forks source link

mono-repo with multiple linked modules #189

Open wabiloo opened 4 weeks ago

wabiloo commented 4 weeks ago

Hi,

I have a mono repo "mono-repo" which contains 2 subfolders "cli" and "sdk". Both are intrinsically linked (the cli uses the sdk) and therefore I decided to have a common version number (hence the mono-repo, using git tag versions)

However they can be built and deployed independently.

The pyproject.toml for the cli is as follows:

[tool.poetry]
name = "my-cli"
version = "0.0.0"
description = "A command line interface to..."
readme = "README.md"
packages = [{ include = "my-cli" }]

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"

[tool.poetry-dynamic-versioning.substitution]
files = ["*/__init__.py", "*/__version__.py", "*/_version.py"]

[tool.poetry.dependencies]
my-sdk = "0.0.0"
python = "^3.10"
click = "^8.1.3"

[tool.poetry.scripts]
cli = "my_cli.app:safe_entry_point"

[tool.poetry.group.dev.dependencies]
my-sdk = { path = "../my-sdk", develop = true }
pytest = "^7.2.2"
black = "^23.1.0"
isort = "^5.12.0"
flake8 = "^6.0.0"

[build-system]
requires = ["poetry-core", "poetry-dynamic-versioning"]
build-backend = "poetry_dynamic_versioning.backend"

When I try to build it fails due to the first dependency set to 0.0.0 (which does not exist). Is there a way to have this updated as well as the tool.poetry.version?

mtkennerly commented 3 weeks ago

Hi! I just tested this out, and I'm not sure there's a good way to make it work :/ There are a few problems:

I tried doing this, but it doesn't work, because Poetry has already analyzed the versions before this substitution occurs:

[[tool.poetry-dynamic-versioning.substitution.folders]]
path = "."
files = ["pyproject.toml"]
patterns = ["(my-sdk = \")0.0.0(\")"]

It should work if you relax the dependency constraint, but that depends on what backwards compatibility guarantees you're comfortable making:

[tool.poetry.dependencies]
my-sdk = ">= 1.0.0, < 2.0.0"

Maybe the plugin could directly modify the version constraints in memory after Poetry has already parsed them, but I haven't explored how complicated/feasible that would be.

wabiloo commented 3 weeks ago

Unfortunately the dependency constraints are strict. I used to have the SDK and CLI as separate packages and repos, but they’re so tightly integrated that I had to ensure the version was always the same between both and hence more to a mono-repo.

I’ve also tried to change the sdk to just use the local path and not specify a version constraint

[tool.poetry.dependencies]

my-sdk = { path = "../my-sdk", develop = true }

python = "^3.10"
click = "^8.1.3"

[tool.poetry.scripts]
cli = "my_cli.app:safe_entry_point"

[tool.poetry.group.dev.dependencies]

However I have no idea what poetry does when it comes to building / publishing it so that seems incorrect…

Fabre Lambeau

On Sat, 17 Aug 2024 at 00:10, Matthew Kennerly @.***> wrote:

Hi! I just tested this out, and I'm not sure there's a good way to make it work :/ There are a few problems:

I tried doing this, but it doesn't work, because Poetry has already analyzed the versions before this substitution occurs:

[[tool.poetry-dynamic-versioning.substitution.folders]]path = "."files = ["pyproject.toml"]patterns = ["(my-sdk = \")0.0.0(\")"]

It should work if you relax the dependency constraint, but that depends on what backwards compatibility guarantees you're comfortable making:

[tool.poetry.dependencies]my-sdk = ">= 1.0.0, < 2.0.0"

Maybe the plugin could directly modify the version constraints in memory after Poetry has already parsed them, but I haven't explored how complicated/feasible that would be.

— Reply to this email directly, view it on GitHub https://github.com/mtkennerly/poetry-dynamic-versioning/issues/189#issuecomment-2294375060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA66JR5F4EJNM22YGF53H4LZRZ2ENAVCNFSM6AAAAABMSABTPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGM3TKMBWGA . You are receiving this because you authored the thread.Message ID: @.***>

mtkennerly commented 3 weeks ago

Unfortunately, at the moment, I don't think you can use this plugin with your setup 😞

vs-artian commented 2 days ago

I'm trying a very similar setup but I'm also using another plugin https://github.com/gerbenoostra/poetry-plugin-mono-repo-deps/ for a monorepo with multiple python projects that depend on each other. It rewrites the version # of path depenencies prior to build. I'm still working through other issues in my setup but I wonder if it might help to use both.

vs-artian commented 2 days ago

Actually I think I have similar problem. Unfortunately it's writing out the real version to poetry.lock file . So it would be unrealistic to update it every time. If I don't specify version depenency, it gets stuck on the older one.