diff options
| author | Aaron Meurer <asmeurer@gmail.com> | 2021-09-22 17:09:47 -0600 |
|---|---|---|
| committer | Aaron Meurer <asmeurer@gmail.com> | 2021-09-22 17:09:47 -0600 |
| commit | daea42f3e68c4a9ae3cc977f14030082fbb856c5 (patch) | |
| tree | 454fd285cf9aaf95f9498a521d29d3faf0919f32 | |
| parent | 24c4436b38b0507d757b996a4bd54ce2a9585dd0 (diff) | |
| download | numpy-daea42f3e68c4a9ae3cc977f14030082fbb856c5.tar.gz | |
BUG: Only call the get_versions() function once on import
When using an in-place build, this function calls various git commands to get
the version number. Previously it was called three times, making 'import
numpy' take over 3 seconds on my machine (it could be even slower on a slow
filesystem). The code has been refactored to only call this function once in
versions.py. Now 'import numpy' on an in-place build only takes 500 ms, which
is still slower than importing the installed version, but that is expected
when using versioneer.
| -rw-r--r-- | numpy/__init__.py | 10 | ||||
| -rw-r--r-- | numpy/version.py | 3 |
2 files changed, 3 insertions, 10 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 27bedb6c1..ebb124738 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -135,11 +135,7 @@ else: 'VisibleDeprecationWarning'] # get the version using versioneer - from ._version import get_versions - vinfo = get_versions() - __version__ = vinfo.get("closest-tag", vinfo["version"]) - __git_version__ = vinfo.get("full-revisionid") - del get_versions, vinfo + from .version import __version__, git_revision as __git_version__ # mapping of {name: (value, deprecation_msg)} __deprecated_attrs__ = {} @@ -407,7 +403,3 @@ else: # We do this from python, since the C-module may not be reloaded and # it is tidier organized. core.multiarray._multiarray_umath._reload_guard() - -from ._version import get_versions -__version__ = get_versions()['version'] -del get_versions diff --git a/numpy/version.py b/numpy/version.py index 4159a1c0e..2b076349d 100644 --- a/numpy/version.py +++ b/numpy/version.py @@ -1,9 +1,10 @@ from ._version import get_versions -__ALL__ = ['version', 'full_version', 'git_revision', 'release'] +__ALL__ = ['version', '__version__', 'full_version', 'git_revision', 'release'] vinfo = get_versions() version: str = vinfo["version"] +__version__ = vinfo.get("closest-tag", vinfo["version"]) full_version: str = vinfo['version'] git_revision: str = vinfo['full-revisionid'] release = 'dev0' not in version and '+' not in version |
