Skip to content

Prefer _version.py over importlib.metadata at import time - #457

Open
jstepgoogle wants to merge 1 commit into
astanin:masterfrom
jstepgoogle:lazy-version
Open

jstepgoogle wants to merge 1 commit into
astanin:masterfrom
jstepgoogle:lazy-version

Conversation

@jstepgoogle

Copy link
Copy Markdown

Try importing the build-time generated tabulate._version module first, and only import importlib.metadata as a fallback when _version.py is not present (e.g. in an unbuilt git checkout).

Since pyproject.toml configures flit_scm / setuptools_scm with write_to = "tabulate/_version.py", standard wheels and sdists already include _version.py. Importing it directly avoids loading importlib.metadata (and its transitive zipfile, email, pathlib, and csv imports) and scanning sys.path for .dist-info directories on every import tabulate.

Try importing the build-time generated tabulate._version module first,
and only import importlib.metadata as a fallback when _version.py is
not present (e.g. in an unbuilt git checkout).

Since pyproject.toml configures flit_scm / setuptools_scm with
write_to = "tabulate/_version.py", standard wheels and sdists
already include _version.py. Importing it directly avoids loading
importlib.metadata (and its transitive zipfile, email, pathlib, and
csv imports) and scanning sys.path for .dist-info directories on
every import tabulate.
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 this pull request may close these issues.

1 participant