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.

Output only the version number with `poetry version`

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

Running poetry version outputs something to the nature of Project (<name>) version is 0.1.0. There seems to be no way to only obtain the version (i.e. 0.1.0), which is what I personally expect poetry version to output. It makes it a little bit more cumbersome to do automated version updates in continuous delivery server (e.g. get the current version number after a version update so that a repo can be tagged).

I would like to suggest either:

  1. poetry version --number (or another acceptable option name since not everyone uses numbers for versions) outputs only the version and not the project information
  2. poetry version outputs only the version number and poetry version -l prints out the more descriptive version information.
  3. Updating the FAQ with an example of how to get the version number by parsing stdout (along with an associated unit test). I’d feel more confident implementing a solution around parsing stdout if we can rely on the stdout not changing.

I’m happy to implement this solution however the maintainers see fit if the community believes it would make automated scripts around the package version easier. And I’m also open to writing an extension/plugin if poetry supports that.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
wesleykendallcommented, Sep 25, 2019

@etijskens sure, one can do this in Python, but hardcoding the project path, including a separate python script in your repo just to print a version, and also ensuring that a toml parser is installed is not a simple solution at all. Especially if you are scripting a pipeline for continuous delivery and publishing of many different python projects.

Poetry’s main use case is for packaging and publishing, which as a result means that the version number is needed for many other things related to publishing the library (tagging the repo, adding the version string to the automated docs, etc).

For example, a script to do an automated version bump might look like:

latest_tag = `git describe --abbrev=0 --tags`
# Set the version to the latest tag
poetry version latest_tag
# Patch the version
poetry version patch
# Get the new version and tag the repo
new_version = `poetry version | some regex parsing to parse output`
git tag new_version
...

In order to get the current version of the repo, I have to parse the output of poetry version, which is a sentence of text and not some sort of delimited structured text (like an ls -l for example). It is strange that I can do complex semantic versioning commands to update the version (e.g. poetry version major), but I can’t do something as simple as get the version after it is updated without resorting to parsing text.

Again, I appreciate the suggested solution in Python, but the purpose of this was to suggest it as a feature since getting the package version is a core aspect of publishing python projects. If the maintainers are happy with any of my suggested approaches, I’m more than happy to open a PR

5reactions
muppetjonescommented, Jul 1, 2020

Hello @funkyfuture ,

since version 1.0.0b6 the output of poety version has changed to a more simple format (#1591), that can be easily parsed. Are you fine with this?

fin swimmer

It’s better. It would still be nice to have an option to just print the version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Output only the version number with poetry version #1407
Running poetry version outputs something to the nature of Project (<name>) version is 0.1.0 . There seems to be no way to only...
Read more >
Commands | Documentation | Poetry - Python dependency ...
--short (-s) : Output the version number only. --dry-run : Do not update pyproject.toml file. export #. This command exports the lock file...
Read more >
Dependency version syntax for Python Poetry - Stack Overflow
The tilde ~ character tells Poetry to allow minor updates. If you specify a major, minor, and patch version, only patch-level changes are ......
Read more >
poetry-dynamic-versioning - PyPI
Poetry's typical version setting is still required in [tool.poetry] , but you are encouraged to use version = "0.0.0" as a standard placeholder....
Read more >
Dependency Management With Python Poetry
In the output, you should see a message that the installation is complete. You can run poetry --version in your terminal to see...
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