Find __version__ for __init__.py
Project description
Project-Version-Finder
Simple package to provide version informaion. The stratagy is
- first look in pyproject.toml (since that's best if we are doing development, and it could be installed (with an old version) when we are working on it).
- second, use modulelib.metadata, which works if it is installed
- and as a last resort, look for a version.py file in the same directory as init.py. This is REQUIRED if you wish to support python versions < 3.8.
All you should need is
from project_version_finder import get_version
fn dummy():
pass
__version__ = get_version('project-name', dummy.__globals__['__file__'])
(and make project-version-finder a dependancy of your project). The second argment to get_version is the path (as a string) to some file in your package directory. One way to get that path without hard coding it is by getting it from a function defined in your init.py file, or, as shown here, by defining a dummy function for that purpose.
It isn't fool proof, but since you provide the project name, if it finds the wrong pyproject.toml it should only fail if that happens to be for a different project with the same name.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file project_version_finder-0.1.1.tar.gz.
File metadata
- Download URL: project_version_finder-0.1.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
281c65f1511c367d9d514d9dad5aeb439e6fa79bcea56c09657432204987e775
|
|
| MD5 |
cd880f7cdb29d1f57d5fde9330dcea6a
|
|
| BLAKE2b-256 |
06d675821d95e3b6ebcf4874abc56e0f114e1aec3b58648cfddf9972efbbfd2d
|
File details
Details for the file project_version_finder-0.1.1-py3-none-any.whl.
File metadata
- Download URL: project_version_finder-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c935da130815d042bb8e5fe3e9b420d7299fb8705af40365b28991148224cef
|
|
| MD5 |
f1db4995f9ad07c13e15cf6483dd28c0
|
|
| BLAKE2b-256 |
5c14a692b6e19902fe6c9541c91796e1f45f2684ce30303183aae9e48e56cbf1
|