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 v2 doesn't accept version with -SNAPSHOT unless using v1.8-style pyproject.toml #10229

Open
jamcpherson-clgx opened this issue Feb 27, 2025 · 4 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@jamcpherson-clgx
Copy link

Description

My organization's CICD process automatically adds "+SNAPSHOT" to the version string for builds on the development branch. This is consistent across every language we use, Python included.

I discovered yesterday that if I use a Poetry v2 form of the pyproject.toml file, then that extra uppercase word prevents Poetry v2.0.1 from installing or building packages.

CICD logfile excerpt:

16:37:39  ci baseVersion from version.txt file: 1.0.0
16:37:39  [Pipeline] sh
16:37:40  + sed -r -i s/version = "1.0.0"/version = "1.0.0+SNAPSHOT"/ pyproject.toml
16:37:40  [Pipeline] sh
16:37:40  + cat pyproject.toml
16:37:40  + grep version
16:37:40  version = "1.0.0+SNAPSHOT"
16:37:40  [Pipeline] sh
16:37:41  + poetry install -v
16:37:41  
16:37:41    RuntimeError
16:37:41  
16:37:41    The Poetry configuration is invalid:
16:37:41      - project.version must match pattern ^v?((([0-9]+)!)?([0-9]+(\.[0-9]+)*)([-_\.]?(alpha|a|beta|b|preview|pre|c|rc)[-_\.]?([0-9]+)?)?((-([0-9]+))|([-_\.]?(post|rev|r)[-_\.]?([0-9]+)?))?([-_\.]?(dev)[-_\.]?([0-9]+)?)?)(\+([a-z0-9]+([-_\.][a-z0-9]+)*))?$
16:37:41    
16:37:41  
16:37:41    at /usr/local/lib/python3.10/dist-packages/poetry/core/factory.py:59 in create_poetry
16:37:41         55│             message = ""
16:37:41         56│             for error in check_result["errors"]:
16:37:41         57│                 message += f"  - {error}\n"
16:37:41         58│ 
16:37:41      →  59│             raise RuntimeError("The Poetry configuration is invalid:\n" + message)
16:37:41         60│ 
16:37:41         61│         for warning in check_result["warnings"]:
16:37:41         62│             logger.warning(warning)

When using Poetry v1.8.2 to build the package, that additional "+SNAPSHOT" did not prevent the package's dependencies being installed, and did not prevent the package from building.

When I changed the pyproject.toml to use the v1.8.x syntax

ie, from

[project]
name = "package-name"
version = "1.0.0"
description = "package description"
authors = [
    {name = "OP", email = "[email protected]"}
]

to

[tool.poetry]
name = "package-name"
version = "1.0.0"
description = "packages description"
authors = ["OP <[email protected]>"]
readme = "README.md"

then Poetry v2.0.1 built the package correctly with the "+SNAPSHOT" in the input version string, and that was correctly translated in the build package name to be "-snapshot".

Workarounds

If you need to use the local part of the version string, per https://peps.python.org/pep-0440/#local-version-identifiers, then either

  • use a lowercase local version identifier, or
  • use the v1.8.x form of your pyproject.toml

Poetry Installation Method

pip

Operating System

Ubuntu 22.04.5 LTS

Poetry Version

Poetry (version 2.0.1)

Poetry Configuration

cache-dir = "/home/jenkins/.cache/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/jenkins/.cache/pypoetry/virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

It's the standard Python3.10 built by Canonical for Ubuntu 22.04:

$ apt list --installed |grep python3.10

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libpython3.10-minimal/jammy-updates,jammy-security,now 3.10.12-1~22.04.8 amd64 [installed,automatic]
libpython3.10-stdlib/jammy-updates,jammy-security,now 3.10.12-1~22.04.8 amd64 [installed,automatic]
libpython3.10/jammy-updates,jammy-security,now 3.10.12-1~22.04.8 amd64 [installed,automatic]
python3.10-minimal/jammy-updates,jammy-security,now 3.10.12-1~22.04.8 amd64 [installed,automatic]
python3.10/jammy-updates,jammy-security,now 3.10.12-1~22.04.8 amd64 [installed]

Example pyproject.toml

See description

Poetry Runtime Logs

See description

@jamcpherson-clgx jamcpherson-clgx added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 27, 2025
@dimbleby
Copy link
Contributor

Regex is here - submit a merge request!

@finswimmer
Copy link
Member

Hey @jamcpherson-clgx,

thanks for reporting this. For the validation of the [project] section we rely on the json schema provided by https://www.schemastore.org/json/ The given pattern there for the version field seems to be incorrect for the local version part.

We include the schema file directly in our code base so we could fix it there. But I guess it would be better to first raise an issue over here https://github.com/SchemaStore/schemastore/issues and once it is fixed there include the updated schema.

fin swimmer

@jamcpherson-clgx
Copy link
Author

Regex is here - submit a merge request!

Thankyou for the pointer. While I'm not afraid of regexes, that one makes my brain hurt!

@jamcpherson-clgx
Copy link
Author

Hey @jamcpherson-clgx,

thanks for reporting this. For the validation of the [project] section we rely on the json schema provided by https://www.schemastore.org/json/ The given pattern there for the version field seems to be incorrect for the local version part.

We include the schema file directly in our code base so we could fix it there. But I guess it would be better to first raise an issue over here https://github.com/SchemaStore/schemastore/issues and once it is fixed there include the updated schema.

fin swimmer

Thanks for the pointer @finswimmer, I'll have a look at the upstream version and see what's going on there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants