Skip to main content

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.

Repository
PyPI

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

project_version_finder-0.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

project_version_finder-0.1.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

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

Hashes for project_version_finder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 281c65f1511c367d9d514d9dad5aeb439e6fa79bcea56c09657432204987e775
MD5 cd880f7cdb29d1f57d5fde9330dcea6a
BLAKE2b-256 06d675821d95e3b6ebcf4874abc56e0f114e1aec3b58648cfddf9972efbbfd2d

See more details on using hashes here.

File details

Details for the file project_version_finder-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for project_version_finder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c935da130815d042bb8e5fe3e9b420d7299fb8705af40365b28991148224cef
MD5 f1db4995f9ad07c13e15cf6483dd28c0
BLAKE2b-256 5c14a692b6e19902fe6c9541c91796e1f45f2684ce30303183aae9e48e56cbf1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page