Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a __version__ attribute to the package #387

Closed
tmke8 opened this issue Sep 30, 2020 · 4 comments
Closed

Add a __version__ attribute to the package #387

tmke8 opened this issue Sep 30, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@tmke8
Copy link
Member

tmke8 commented Sep 30, 2020

Everyone has this.

@tmke8 tmke8 added the enhancement New feature or request label Sep 30, 2020
@tmke8
Copy link
Member Author

tmke8 commented Mar 17, 2022

Apparently, you can do it this way:

from importlib import metadata
import toml

try:
    __version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
    __version__ = toml.load("pyproject.toml")["tool"]["poetry"]["version"] + "dev"

source: python-poetry/poetry#144 (comment)

@tmke8
Copy link
Member Author

tmke8 commented Mar 17, 2022

There is a backport of importlib.metadata for Python 3.7 here: https://github.com/python/importlib_metadata

With that, the above simplifies to

from importlib import metadata
 __version__ = metadata.version(__package__)

@tmke8
Copy link
Member Author

tmke8 commented Mar 18, 2022

I wanted to use this for sphinx, but I realized that that is a bad idea because sphinx is always run on the main branch, which obviously doesn't have the right version.

@tmke8
Copy link
Member Author

tmke8 commented Mar 18, 2022

I don't think this is needed anymore. The docs now show the correct version, and if someone wants to know the version of EthicML, they can use importlib.metadata.

@tmke8 tmke8 closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant