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:
- Created 5 years ago
- Reactions:29
- Comments:38 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
pkg_resources
module enables package information introspection. Here’s how it can be used to get the version of an installed package.You can now use
importlib.metadata
and its backportimportlib_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 astr
read from yourpyproject.toml
configuration.