question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InvalidVersion: Inconsistency in version handling

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

I’m using Poetry in a Github Actions pipeline to set the version based on the git tag, and then to build and publish my project. My pipeline is configured like this but effectively runs:

poetry version <git tag>
poetry publish -n --build --username __token__ --password ${{ secrets.pypi_password }}

The git tag is a semver with an optional trailing name and the poetry version command succeeds in setting the version, but then poetry publish rejects the version. In this case the version is 0.9.4-poetry5 and it yields the following output:

# Run poetry version 0.9.4-poetry5
Bumping version from 0.0.0 to 0.9.4-poetry5

# Run poetry publish -n --build --username __token__ --password ***

[InvalidVersion]
Invalid version: '0.9.4-poetry5'
##[error]Process completed with exit code 1.

Full output of the pipeline is available.

Why does Poetry accept the version in poetry version and later reject it in poetry publish? Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
eikevonscommented, Sep 25, 2020

IMHO, restricting versions to the PEP 440 regex excludes a lot of use-cases.

3reactions
alexifmcommented, Aug 8, 2020

I think I have a similar problem. I want to publish a temporary branch version with this: X.Y.Z-<branch>+<build>

poetry version has no problem with that but poetry build can’t handle it.

Here are a couple of tests:

$ poetry build -vvv
Using virtualenv: /Users/alexifm/.pyenv/versions/3.7.7/envs/test
Building test_package (0.2.2-dev+1596889372)
 - Building sdist
 - Adding: test_package/__init__.py
 - Adding: pyproject.toml
 - Built test_package-0.2.2.dev0+1596889372.tar.gz

 - Building wheel
 - Adding: /var/folders/qh/sgf65ggd7z91nhh8hx8fffyw0000gp/T/tmp1u8dp4ad/test_package-0.2.2.dev0+1596889372/test_package/__init__.py
 - Built test_package-0.2.2.dev0+1596889372-py3-none-any.whl
$ poetry build -vvv
Using virtualenv: /Users/alexifm/.pyenv/versions/3.7.7/envs/test
Building test_package (0.2.2-test+1596889372)

[InvalidVersion]
Invalid version: '0.2.2-test+1596889372'

Traceback (most recent call last):
  File "/usr/local/Cellar/poetry/1.0.10/libexec/vendor/lib/python3.8/site-packages/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/vendor/lib/python3.8/site-packages/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/vendor/lib/python3.8/site-packages/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/vendor/lib/python3.8/site-packages/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/usr/local/Cellar/poetry/1.0.10/libexec/lib/python3.8/site-packages/poetry/console/commands/build.py", line 30, in handle
    builder.build(fmt)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/lib/python3.8/site-packages/poetry/masonry/builder.py", line 19, in build
    builder = self._FORMATS[fmt](self._poetry, self._env, self._io)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/lib/python3.8/site-packages/poetry/masonry/builders/builder.py", line 71, in __init__
    self._meta = Metadata.from_package(self._package)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/lib/python3.8/site-packages/poetry/masonry/metadata.py", line 46, in from_package
    meta.version = normalize_version(package.version.text)
  File "/usr/local/Cellar/poetry/1.0.10/libexec/lib/python3.8/site-packages/poetry/utils/helpers.py", line 34, in normalize_version
    return str(Version(version))
  File "/usr/local/Cellar/poetry/1.0.10/libexec/lib/python3.8/site-packages/poetry/version/version.py", line 56, in __init__
    raise InvalidVersion("Invalid version: '{0}'".format(version))

It’s coming from here: https://github.com/python-poetry/poetry/blob/1.0.10/poetry/utils/helpers.py#L33-L34 https://github.com/python-poetry/poetry/blob/1.0.10/poetry/version/version.py#L14-L56

The regex has a particularly demanding format because while official SemVer says the prerelease component can be an arbitrary string, Python opts for this particular form which Poetry is using: https://semver.org/#spec-item-9 https://www.python.org/dev/peps/pep-0440/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update module to > v2 - HUGO
invalid version : module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2.
Read more >
Receiving 404 "Invalid version: graph.microsoft.com" for 80 ...
Hi,. Our code for querying https://graph.microsoft.com/v1.0/me stopped working suddenly today. We request the users details with the OAuth ...
Read more >
Version Handling - Packaging
InvalidVersion – When the version string is not a valid version. This class abstracts handling of a project's versions. A Version instance is...
Read more >
Inconsistency in production version - SAP Community
i am facing this problem with all new product codes created from last months period change. because of this i am not able...
Read more >
Core version key in module's .info.yml doesn't respect ... - Drupal
Determine if profiles .info.yml files should be handled in a ... Could not parse version constraint 8.nonsense: Invalid version string ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found