Skip to main content

Find __version__ for __init__.py

Project description

Project-Version-Finder

Simple package to provide version informaion. The stratagy is

  • first, use importlib.metadata (or importlib_metadata, if appropriate), which works if it is installed.
  • second look in pyproject.toml

All you should need is

from project_version_finder import get_version
nn
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.2.0.tar.gz (3.0 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.2.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: project_version_finder-0.2.0.tar.gz
  • Upload date:
  • Size: 3.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 e82e256394e821b9537aaed07312f2325fe856e8fab25802a5ac03f247d56ee0
MD5 ba0c52f666d5b55da1cd385b5c9145be
BLAKE2b-256 feb1434d07b3be1e75bdedc56c12a8fac0071c02b609fd5439d2d069a2e5d3c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for project_version_finder-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acd8fe3ccf14aba4dd6f7555605f7644822c97f90873c73798fa50d323044082
MD5 fcb8c6991d44cf09cb7134313109c36c
BLAKE2b-256 d977aa997e5b673e20a2f7d707c6a89094f02eed7710163ba9d8c2486c637304

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