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.

How to get version from pyproject.toml from python app?

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.

Question

I have a basic python app, and inside this app there’s a --version flag. I want to show the same version as I have in pyproject.toml, but without duplicating this information.

What should I do here? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:29
  • Comments:38 (4 by maintainers)

github_iconTop GitHub Comments

37reactions
roywescommented, Jul 3, 2018

The pkg_resources module enables package information introspection. Here’s how it can be used to get the version of an installed package.

>>> import pkg_resources
>>> my_version = pkg_resources.get_distribution('my-package-name').version
28reactions
Eric-Arellanocommented, Jan 6, 2020

You can now use importlib.metadata and its backport importlib_metadata: https://docs.python.org/3/library/importlib.metadata.html#distribution-versions.

It has a convenient function importlib.metadata.version('my-distribution') that will return a str read from your pyproject.toml configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify version in only one place when using pyproject ...
So keep the version only in the pyproject.toml and use this in your python code: import importlib.metadata __version__ ...
Read more >
The pyproject.toml file | Documentation | Poetry
The pyproject.toml file The tool.poetry section of the pyproject.toml file is composed of multiple sections. name The name of the package.
Read more >
Single-sourcing the package version
Read the file in setup.py and get the version. ... of setuptools 61.0.0, one can specify the version dynamically in the project's pyproject.toml...
Read more >
7. Releasing and versioning - Python Packages
2 that to use PSR, you need to tell it where your package's version number is stored by defining version_variable = "pyproject.toml:version" under...
Read more >
read-version 0.3.2 - PyPI
Install read_version in your development environment with the toml extra: · Add a pyproject. · Get rid of your boilerplate __version__-finding code in...
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