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 modulelib.metadata, which works if it is installed (and finding pyproject.toml will not in this case)
  • second look in pyproject.toml

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.3.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.1.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: project_version_finder-0.1.3.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.1.3.tar.gz
Algorithm Hash digest
SHA256 39b14cf65e7348e42b19687288ff27a78839e0446f1d376f214d63774898ec03
MD5 5dfad2d137dee44ce6ac988e7bb55555
BLAKE2b-256 f0463e64ba7b355c8bc182df6a7c5fc28a8120b49cb42d27fe8accc9b2332ddc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for project_version_finder-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 211dd0051a5dcc94ea22796e42df5fd6abdcea68b099e7663f24a71aee931c90
MD5 87ea8c510d5100f567df1f7c0ea05fa3
BLAKE2b-256 97afdeb4f2cf849f15ebfa24a5dacc128cee94059a3e60b572b6604237a62f1c

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