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.

Poetry dynamic versioning not adhering to SemVer 2.0 when setting `style=semver` and `bump=true` but not with `bump=false`

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).
  • OS version and name:
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.19044 N/A Build 19044
  • Poetry version:
pip show poetry
Name: poetry
Version: 1.1.13
Summary: Python dependency management and packaging made easy.
Home-page: https://python-poetry.org/
Author: SΓ©bastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Location: **RECACTED**\venv\lib\site-packages
Requires: cachecontrol, cachy, cleo, clikit, crashtest, html5lib, keyring, packaging, pexpect, pkginfo, poetry-core, requests, requests-toolbelt, shellingham, tomlkit, virtualenv
Required-by:
  • python version: 3.9.12

  • Link of a Gist with the contents of your pyproject.toml file: Relevant configuration from pyrpoject.toml:

[tool.poetry]
...
version = "0.0.0"
...

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

[tool.poetry.scripts]
poetry-dynamic-versioning = 'poetry_dynamic_versioning.__main__:main'

Issue

When building a python project on Windows using Poetry I get below exception when I set bump to true.

Using virtualenv: ***REDACTED***\venv
Building **REDACTED** (1.0.0-rc.2.pre.8+b504267)

  Stack trace:

  9  venv\lib\site-packages\clikit\console_application.py:131 in run
      129β”‚             parsed_args = resolved_command.args
      130β”‚
    β†’ 131β”‚             status_code = command.handle(parsed_args, io)
      132β”‚         except KeyboardInterrupt:
      133β”‚             status_code = 1

  8  venv\lib\site-packages\clikit\api\command\command.py:120 in handle
      118β”‚     def handle(self, args, io):  # type: (Args, IO) -> int
      119β”‚         try:
    β†’ 120β”‚             status_code = self._do_handle(args, io)
      121β”‚         except KeyboardInterrupt:
      122β”‚             if io.is_debug():

  7  venv\lib\site-packages\clikit\api\command\command.py:171 in _do_handle
      169β”‚         handler_method = self._config.handler_method
      170β”‚
    β†’ 171β”‚         return getattr(handler, handler_method)(args, io, self)
      172β”‚
      173β”‚     def __repr__(self):  # type: () -> str

  6  venv\lib\site-packages\cleo\commands\command.py:92 in wrap_handle
       90β”‚         self._command = command
       91β”‚
    β†’  92β”‚         return self.handle()
       93β”‚
       94β”‚     def handle(self):  # type: () -> Optional[int]

  5  venv\lib\site-packages\poetry\console\commands\build.py:36 in handle
      34β”‚
      35β”‚         builder = Builder(self.poetry)
    β†’ 36β”‚         builder.build(fmt, executable=self.env.python)
      37β”‚

  4  venv\lib\site-packages\poetry\core\masonry\builder.py:35 in build
      33β”‚
      34β”‚         for builder in builders:
    β†’ 35β”‚             builder(self._poetry, executable=executable).build()
      36β”‚

  3  venv\lib\site-packages\poetry\core\masonry\builders\builder.py:92 in __init__
       90β”‚         )
       91β”‚
    β†’  92β”‚         self._meta = Metadata.from_package(self._package)
       93β”‚
       94β”‚     @property

  2  venv\lib\site-packages\poetry\core\masonry\metadata.py:52 in from_package
      50β”‚
      51β”‚         meta.name = canonicalize_name(package.name)
    β†’ 52β”‚         meta.version = normalize_version(package.version.text)
      53β”‚         meta.summary = package.description
      54β”‚         if package.readme:

  1  venv\lib\site-packages\poetry\core\utils\helpers.py:35 in normalize_version
       33β”‚
       34β”‚ def normalize_version(version):  # type: (str) -> str
    β†’  35β”‚     return str(Version(version))
       36β”‚
       37β”‚

  InvalidVersion

  Invalid version: '1.0.0-rc.2.pre.8+b504267'

  at venv\lib\site-packages\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))
       62β”‚
       63β”‚         # Store the parsed out pieces of the version
       64β”‚         self._version = _Version(
       65β”‚             epoch=int(match.group("epoch")) if match.group("epoch") else 0,

The generated version number fails to build due to not adhering to SemVer scheme, although with bump to false it seems `` is OK and runs a successful build:

poetry build -vvv
Using virtualenv: **REDACTED**\venv
Building **REDACTED** (1.0.0-rc.1.post.8+b504267)
  - Building sdist
  - Adding: **REDACTED**\runner\__init__.py
  - Adding: **REDACTED**\runner\_version.py
  - Adding: **REDACTED**\runner\config.py
  - Adding: **REDACTED**\runner\constants.py
  - Adding: **REDACTED**\runner\logging.py
  - Adding: **REDACTED**\runner\runner.py
  - Adding: **REDACTED**\runner\utils.py
  - Adding: pyproject.toml
  - Built **REDACTED**-1.0.0rc1.post8+b504267.tar.gz
  - Building wheel
  - Adding: **REDACTED**\runner\__init__.py
  - Adding: **REDACTED**\runner\_version.py
  - Adding: **REDACTED**\runner\config.py
  - Adding: **REDACTED**\runner\constants.py
  - Adding: **REDACTED**\runner\logging.py
  - Adding: **REDACTED**\runner\runner.py
  - Adding: **REDACTED**\runner\utils.py
Skipping: **REDACTED**/COPYING
Skipping: **REDACTED**/LICENSE
  - Built **REDACTED**-1.0.0rc1.post8+b504267-py3-none-any.whl

Expected behavior AFAICT both version numbers adhere to SemVer 2.0 especially item 9 and item 10 so I expect them both to either fail or pass, instead of the current behavior.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
abncommented, May 9, 2022

@jmartens appreciate your details about the issue and your debugging efforts however, style=semver is not a poetry configuration, it is a plugin configuration.

If the plugin, chooses to somehow disable the validation of PEP 440, it may choose to do so somehow. However, Poetry itself normalises the version according to PEP 440 since the build outputs requires to conform to standards. Third-party tools using your build artifacts will likely also fail if you circumvent this.

For example, attempting to parse your version via PyPA’s packaging library, you get this.

$ python -c 'from packaging.version import Version; Version("1.0.0-rc.2.pre.8+b504267")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '1.0.0-rc.2.pre.8+b504267'

However you will note your second generated version is compatible.

$ python -c 'from packaging.version import Version; Version("1.0.0-rc.1.post.8+b504267")'
$

See here for infromation on why these two schemes are not fully compatible.

0reactions
abncommented, May 9, 2022

This is not about PyPA alone, we need artifacts and metadata to play well with other tools too.

On poetry@master, this will fail early.

$ poetry version 1.0.0-rc.2.pre.8+b504267

  InvalidVersion

  Invalid PEP 440 version: '1.0.0-rc.2.pre.8+b504267'
Read more comments on GitHub >

github_iconTop Results From Across the Web

poetry-dynamic-versioning 0.3.2
This package is a plugin for Poetry to enable dynamic versioning based on tags in your version control system, powered by Dunamai. Since...
Read more >
Gitlab CI job should change source code. poetry-dynamic- ...
I would like to run a job which launches poetry-dynamic-versioning and add new version toΒ ...
Read more >
poetry - bytemeta
Poetry dynamic versioning not adhering to SemVer 2.0 when setting `style=semver` and `bump=true` but not with `bump=false`. fazal-kh4n. fazal-kh4n CLOSED.
Read more >
Does this project still supported/maintained? - FiloSottile/Yubikey ...
Poetry dynamic versioning not adhering to SemVer 2.0 when setting `style=semver` and `bump=true` but not with `bump=false`, 9, 2022-05-09, 2022-10-24.
Read more >
Poetry Dynamic Versioning - conda install
License: MIT; Home: https://github.com/mtkennerly/poetry-dynamic-versioning; 16629 total downloads; Last upload: 3 months and 2 days agoΒ ...
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