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.2.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.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file project_version_finder-0.1.2.tar.gz.

File metadata

  • Download URL: project_version_finder-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 7c0b23d8e2a6b14f0d7d7e79cbf17368e2ce0a19f89616390f847abdfbbc71fe
MD5 a58bf296d2ba003ba3f00caebb7b863c
BLAKE2b-256 4b6dac4ddd66642ea45c5bad351315cb3c6159592e5acadec384b09a67a0e65b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for project_version_finder-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b16ade4485ef6a152ddb4ea75d2698792565f763e34a87e7a51af7707717c685
MD5 f7a663490bff8d87a976e71a9643b331
BLAKE2b-256 b047139f4ef034805652584334ae8af74b1fdb4cc5d13ebb38202f5ef43bdd58

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