Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry 2.0 compatibility #201

Closed
dalito opened this issue Jan 5, 2025 · 7 comments
Closed

Poetry 2.0 compatibility #201

dalito opened this issue Jan 5, 2025 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@dalito
Copy link

dalito commented Jan 5, 2025

Today poetry 2.0 came out and it seems that your plugin does not yet work with PEP-621 pyproject.toml where for example the project name is in the [project] section.

[project]
# Storing project metadata in pyproject.toml 
name = "mything"

I get an unbound local error with poetry-dynamic-versioning version 1.4.1:

 UnboundLocalError

  cannot access local variable 'name' where it is not associated with a value

  at ~\.local\pipx\venvs\poetry\Lib\site-packages\poetry_dynamic_versioning\__init__.py:668 in _get_and_apply_version
      664│         name = pyproject["project"]["name"]
      665│         original = pyproject["project"].get("version")
      666│         dynamic_index = pyproject["project"]["dynamic"].index("version")
      667│     else:
    → 668│         return name if name in _state.projects else None
      669│
      670│     if name in _state.projects:
      671│         return name
      672│
@edgarrmondragon
Copy link
Contributor

@dalito how did you declare the version?

@mtkennerly
Copy link
Owner

Hi! The plugin does support PEP-621 (at least based on a pre-release version of Poetry - I'll re-test with 2.0), but your pyproject.toml must:

  • not define tool.poetry.name
  • define project.name
  • define project.dynamic to include "version"
  • not define project.version

@rayrapetyan
Copy link

rayrapetyan commented Jan 5, 2025

There is a more general incompatibility issue:

Because no versions of poetry-dynamic-versioning match >1.4.1,<2.0.0
 and poetry-dynamic-versioning[plugin] (1.4.1) depends on poetry (>=1.2.0,<2.0.0), poetry-dynamic-versioning[plugin] (>=1.4.1,<2.0.0) requires poetry (>=1.2.0,<2.0.0).
So, because poetry-instance depends on both poetry (2.0.0) and poetry-dynamic-versioning[plugin] (^1.4.1), version solving failed.

Hardcoding 1.x version solves the issue:

curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.5 python3 -

@dalito
Copy link
Author

dalito commented Jan 5, 2025

I added poetry-dynamic-versioning to poetry 2.0.0 by injecting it with pipx.

First, I still had a version under [project]. Once I replaced this by dynamic = ["version"], poetry check starts complaining about the missing version instead of the missing name:

The Poetry configuration is invalid:
- Either [project.version] or [tool.poetry.version] is required in package mode.

My pyproject.toml is here: https://github.com/nfdi4cat/pid4cat-model/pull/36/files - @mtkennerly I think it matches the points you listed above.

@dalito
Copy link
Author

dalito commented Jan 5, 2025

If I add a version under tool.poetry,

[tool.poetry]
requires-poetry = ">=2.0"
version = "0.0.0"

poetry checks passes but gives a warning

Warning: [project.version] and [tool.poetry.version] are both set. The latter will be ignored.
If you want to set the version dynamically via `poetry build --local-version` or you are using a plugin, which sets the version dynamically, you should define the version in [tool.poetry] and add 'version' to [project.dynamic].

It still a bit confusing. Which config would work without warning?

@mtkennerly
Copy link
Owner

@rayrapetyan

poetry-dynamic-versioning[plugin] (1.4.1) depends on poetry (>=1.2.0,<2.0.0), poetry-dynamic-versioning[plugin] (>=1.4.1,<2.0.0) requires poetry (>=1.2.0,<2.0.0).

Thanks for bringing that up. The master branch already uses poetry = ">=1.2.0", which should fix that, but the latest release still uses poetry = "^1.2.0".

@dalito

Warning: [project.version] and [tool.poetry.version] are both set. The latter will be ignored. If you want to set the version dynamically via `poetry build --local-version` or you are using a plugin, which sets the version dynamically, you should define the version in [tool.poetry] and add 'version' to [project.dynamic].

Looks like this changed since the beta versions of 2.0. I'll need to update the plugin to account for this logic 👍

@mtkennerly
Copy link
Owner

This should be fixed now in 1.5.0: https://github.com/mtkennerly/poetry-dynamic-versioning/releases/tag/v1.5.0

I also added a section at the bottom of the README about the conditions for the plugin to use PEP 621 mode.

Please let me know if you still run into any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants