bndr / pipreqs

pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.
Apache License 2.0
6.38k stars 388 forks source link

remove duplication of version in __init__ and remove not used variables #422

Open alan-barzilay opened 10 months ago

alan-barzilay commented 10 months ago

probably something like: __version__ = importlib.metadata.version('pipreqs')

refs: https://docs.python.org/3/library/importlib.html https://github.com/python-poetry/poetry/issues/273

alan-barzilay commented 10 months ago

actually, this might be better:

import importlib.metadata
import tomllib

try:
    with open("pyproject.toml", "rb") as f:
        pyproject = tomllib.load(f)
    __version__ = pyproject["tool"]["poetry"]["version"]
except Exception as e:
    __version__ = importlib.metadata.version('pipreqs')

(tomlib is new from version 3.11)

alan-barzilay commented 10 months ago

this may be useful in #411