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

Adding a __version__ attribute #190

Open
rasbt opened this issue Sep 10, 2023 · 4 comments
Open

Adding a __version__ attribute #190

rasbt opened this issue Sep 10, 2023 · 4 comments

Comments

@rasbt
Copy link

rasbt commented Sep 10, 2023

It would be nice to add a __version__ attribute similar to other Python projects, so that we can easily query the version for reproducibility reasons. I.e.,

import tiktoken
print(tiktoken.__version__)
@hauntsaninja
Copy link
Collaborator

Sure, I could consider adding this. Note you can use importlib.metadata.version("tiktoken")

@rasbt
Copy link
Author

rasbt commented Sep 12, 2023

Thanks for the response. Yes, this works. I was just mentioning the additional .__version__ attribute since it is a common convention in the Python scientific computing ecosystem (SciPy, PyTorch, NumPy, matplotlib, ...).

Since you are using a .toml, it's actually probably best to use the following code you suggested itself

import importlib.metadata

__version__ = importlib.metadata.version("mypackage")

and just add it to the __init__.py

@rasbt
Copy link
Author

rasbt commented Sep 12, 2023

I added a PR for your convenience here: #191

@pamelafox
Copy link

FYI- In the Flask community, we've been removing version from packages now that importlib is around. Maybe scientific packages are keeping it around, but web packages are moving away from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants