Proper project structure
pyproject.tomlshould be the single source of truth, especially for package versioning- Good reference: https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
- Clear segregation of classes and functions
Currently blocked by the release of cx-freeze==6.14.0 (for customizing configurations in pyproject.toml)
Single-sourcing via pyproject.toml is blocked by poetry
Reference: https://github.com/python-poetry/poetry/issues/3332
Single-sourcing via pyproject.toml is blocked by poetry Reference: https://github.com/python-poetry/poetry/issues/3332
The poetry itself uses a work around to versioning single source of truth while managing metadata using poetry implementation
See:
https://github.com/python-poetry/poetry/blob/master/src/poetry/version.py#L5
from poetry.utils._compat import metadata
https://github.com/python-poetry/poetry/blob/master/src/poetry/version.py#L12-L16
# The metadata.version that we import for Python 3.7 is untyped, work around
# that.
version: Callable[[str], str] = metadata.version
__version__ = version("poetry")
https://github.com/python-poetry/poetry/blob/master/src/poetry/utils/_compat.py#L18-L22
if sys.version_info < (3, 10):
# compatibility for python <3.10
import importlib_metadata as metadata
else:
from importlib import metadata
This approach is also showed in the source link you've mentioned:
https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
import sys
if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata
assert metadata.version('pip') == '1.2.0'