poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Doc states that Poetry doesn't enforce

Open alsyia opened this issue 5 years ago • 10 comments

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.

Issue

The doc on the pyproject.toml file states that:

[version] should follow semantic versioning. However it will not be enforced and you remain free to follow another specification.

I have a version looking like this: 0.4.4-11-gc91ab07. I believe it is semver valid, but the poetry build command returns the following error:

  InvalidVersion

  Invalid version: '0.4.4.11.gc91ab07'

  at /opt/poetry/lib/poetry/_vendor/py3.7/poetry/core/version/version.py:61 in __init__
       57│     def __init__(self, version):  # type: (str) -> None
       58│         # Validate the version and parse it into pieces
       59│         match = VERSION_PATTERN.match(version)
       60│         if not match:
    →  61│             raise InvalidVersion("Invalid version: '{0}'".format(version))

I've found tickets saying that Poetry does enforce PEP 440 style for versions, but it's not clear if this is still the current state of things. The doc looks wrong anyway!

I would rather have a choice since PEP 440 and Semver are not compatible and pretty much everyone else (Docker, Helm, helm) uses Semver nowadays...

alsyia avatar Nov 22 '21 14:11 alsyia

I think Poetry shouldn't enforce any version schema, especially not SemVer. I may have use cases where I'd like to pick a certain version name and tools shouldn't unnecessarily prevent me from doing that.

dAnjou avatar Jan 11 '22 16:01 dAnjou

I think we should rewrite the documentation here. It must be something that looks like SemVer or PEP 440 style. The python ecosystem forces to use a PEP 440 compliant version.

finswimmer avatar Jan 11 '22 17:01 finswimmer

This breaks or complicates using e.g. CalVer, which is for a lot of projects a strictly better option than SemVer. "The python ecosystem forces to use a PEP 440 compliant version." does not always make sense, not all projects are released to the cheeseshop - for an internal project on a steady cadence, we'd like to use YYYY.MM_nn, e.g. 2022.01_02 for the second release in January, 2022. We don't want to use 2022.01.02 because that looks like the second of January and probably ise not, and we want the releases to be string-sortable and easy to place on a timeline.

What is the reason Poetry enforces this? Notably, PEP440 specifies what "canonical public version identifiers" must adhere to, but even disregarding that rational people can disagree with PEPs, some project have non-public version identifiers and Poetry will refuse to build them (or change e.g. 1.2v003 to 1.2.post3 when building) - I'd be happy with having to give a flag to say I really want to opt out of PEP440 check or whatever, but I don't think Poetry should dictate what versions it can build.

Edit: even just pushing the check to the publish step would resolve this specific issue.

haard avatar Jan 25 '22 18:01 haard

What is the reason Poetry enforces this?

Poetry is a tool for dependency management and packaging in Python. And as such it will follow PEP standards wherever possible. As you already said PEP 440 says "The canonical public version identifiers MUST comply with the following scheme".

To be able resolve dependencies you must be able to parse and "understand" the version, otherwise you cannot say if a version of a package is in the required range.

We already had a small discussion within the maintainer team a long time ago whether we drop supporting SemVer notation in pyproject.toml at all, because it's sometime confusing for people when the version number is converted to PEP 440 notation on install or build. We decided to leave it for now as it is.

There will be a time where Poetry will move to PEP 621. At that point we have to switch to PEP 440 for the version specifier.

finswimmer avatar Jan 26 '22 12:01 finswimmer

In this case, can the doc be updated? 😃 The sentence This should follow semantic versioning. However it will not be enforced and you remain free to follow another specification. looks inaccurate since Poetry does, in fact, enforce PEP 440 (and not semver).

alsyia avatar Jan 26 '22 19:01 alsyia

I upgraded from Poetry 1.1.13 to 1.2.0b1 and I am no longer able to install SQLAlchemy2 from their repository.

[tool.poetry.dependencies]
sqlalchemy = { git = "https://github.com/sqlalchemy/sqlalchemy", rev = "c2fe4a2" }
$ poetry update

  InvalidVersion

  Invalid PEP 440 version: '2.0.0b1.dev0dev'

  at ~/.local/lib/python3.10/site-packages/poetry/core/version/pep440/parser.py:69 in parse
       65│         cls, value: str, version_class: Optional[Type["PEP440Version"]] = None
       66│     ) -> "PEP440Version":
       67│         match = cls._regex.search(value) if value else None
       68│         if not match:
    →  69│             raise InvalidVersion(f"Invalid PEP 440 version: '{value}'")
       70│ 
       71│         if version_class is None:
       72│             from poetry.core.version.pep440.version import PEP440Version
       73│

In this specific case where SQLAlchemy appears to have incorrectly appended metadata to their correct version specifier, it makes sense to ask for them to conform to the standard. Ideally all Python packages will conform to PEP440 and Poetry could warn about dependencies that don't follow the correct version schema, but to outright error with no possible recourse seems heavy-handed.

jcmdln avatar Mar 19 '22 17:03 jcmdln

Actually. I was wrong. Poetry <1.2 generated the invalid version specifier which was stored in my poetry.lock

[[package]]
name = "SQLAlchemy"
version = "2.0.0b1.dev0dev"
description = "Database Abstraction Library"
category = "main"
optional = false
python-versions = ">=3.7"
develop = false

Deleting and generating the poetry.lock resolved the issue. Based on this outcome, it appears that this is an opportunity to update the documentation and/or handle incompatibilities between Poetry versions.

jcmdln avatar Mar 19 '22 18:03 jcmdln

Poetry is definitely appending strings to package versions:

$ pip install git+https://github.com/sqlalchemy/sqlalchemy
Successfully installed SQLAlchemy-2.0.0b1.dev0

jcmdln avatar Mar 19 '22 18:03 jcmdln

@jcmdln, please see https://github.com/pypa/setuptools/issues/3088 for this case.

finswimmer avatar Mar 19 '22 18:03 finswimmer

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Mar 02 '24 03:03 github-actions[bot]