Closed cmutel closed 1 year ago
This is not a solution for issue #12 . If we don't need a version here, we shouldn't add more code.
Here's another proposition. If we only support python >= 3.8, we could use importlib.metadata to get the version, and not read the file ourselves:
"""{{cookiecutter.package_name}}."""
import importlib.metadata
from typing import Union
def get_version() -> tuple:
def as_integer(x: str) -> Union[int, str]:
try:
return int(x)
except ValueError:
return x
return tuple(
as_integer(v)
for v in importlib.metadata.version("{{ cookiecutter.package_name }}")
.strip()
.split(".")
)
__version__ = get_version()
This can also work with python 3.7, if we add the retro-compatible importlib_metadata
dependency and use the import correctly.
This looks good. Can I merge @cmutel ?
@tngTUDOR Can we merge this?