-
Notifications
You must be signed in to change notification settings - Fork 6
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
Generate __version__
at build to avoid slow importlib.metadata
#30
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! The actual importlib.metadata.version
call can be slow too, esp in larger envs (just checked and it was 15ms in a venv I'm in)
I don't want to step in front of the steamroller of progress here, but what is this heavy |
Yep, |
@@ -42,6 +42,9 @@ scripts.blurb = "blurb.blurb:main" | |||
[tool.hatch] | |||
version.source = "vcs" | |||
|
|||
[tool.hatch.build.hooks.vcs] | |||
version-file = "src/blurb/_version.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these two lines tell hatch
to automatically create the _version.py
file that contains __version__ = '...'
on build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right: https://github.com/ofek/hatch-vcs#build-hook-options
__version__
at build to avoid slow importlib.metadata
import__version__
at build to avoid slow importlib.metadata
importlib.metadata
is quite a heavy library to import, and can make CLI use less snappy.It's only used for fetching the version, and we can pre-generate it as part of our regular build instead.
Before
After