Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e021c26

Browse files
authored
Merge pull request #24406 from charris/backport-24196
MAINT: Remove versioneer
2 parents 1fe7e66 + 7eb8cd9 commit e021c26

24 files changed

+169
-2987
lines changed

.gitattributes

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ numpy/core/src/common/dlpack/dlpack.h linguist-vendored
1717
# Mark some files as generated
1818
numpy/linalg/lapack_lite/f2c_*.c linguist-generated
1919
numpy/linalg/lapack_lite/lapack_lite_names.h linguist-generated
20-
numpy/_version.py linguist-generated
2120

22-
# versioneer config
23-
numpy/_version.py export-subst
21+
# version generated from pyproject.toml during build
22+
numpy/version.py linguist-generated
2423

2524
# Configuration files
2625
*.ini text

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ doc/source/savefig/
119119

120120
# Things specific to this project #
121121
###################################
122+
# The line below should change to numpy/_version.py for NumPy 2.0
123+
numpy/version.py
122124
numpy/core/__svn_version__.py
123125
doc/numpy.scipy.org/_build
124126
numpy/__config__.py

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exclude azure-*.yml
1616
include .coveragerc
1717

1818
# Sub-directories. Included are: numpy/, doc/, benchmarks/, tools/
19-
include numpy/_version.py
19+
include numpy/version.py
2020
recursive-include numpy/random *.pyx *.pxd *.pyx.in *.pxd.in
2121
include numpy/py.typed
2222
include numpy/random/include/*

doc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ gitwash-update:
8181
#
8282

8383
#SPHINXBUILD="LANG=C sphinx-build"
84-
NUMPYVER:=$(shell $(PYTHON) -c "import numpy; print(numpy.version.git_revision[:10])" 2>/dev/null)
85-
GITVER ?= $(shell cd ..; $(PYTHON) -c "import versioneer as v; print(v.get_versions()['full-revisionid'][:10])")
84+
NUMPYVER:=$(shell $(PYTHON) -c "import numpy; print(numpy.version.git_revision[:7])" 2>/dev/null)
85+
GITVER ?= $(shell (cd ..; set -o pipefail && git rev-parse HEAD 2>/dev/null | cut -c1-7) || echo Unknown)
8686

8787
version-check:
8888
ifeq "$(GITVER)" "Unknown"

generate_version.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

meson.build

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
project(
22
'NumPy',
33
'c', 'cpp', 'cython',
4-
# Note that the git commit hash cannot be added dynamically here
5-
# It is dynamically added upon import by versioneer
6-
# See `numpy/__init__.py`
7-
version: '1.26.0.dev0',
4+
version: run_command(
5+
# This should become `numpy/_version.py` in NumPy 2.0
6+
['python', 'numpy/_build_utils/gitversion.py'],
7+
check: true).stdout().strip(),
88
license: 'BSD-3',
99
meson_version: '>=1.2.99', # version in vendored-meson is 1.2.99
1010
default_options: [
@@ -62,23 +62,5 @@ if cc.get_id() == 'clang'
6262
)
6363
endif
6464

65-
# Generate version number. Note that this will not (yet) update the version
66-
# number seen by pip or reflected in wheel filenames. See
67-
# https://github.com/mesonbuild/meson-python/issues/159 for that.
68-
versioneer = files('generate_version.py')
69-
if fs.exists('_version_meson.py')
70-
py.install_sources('_version_meson.py', subdir: 'numpy')
71-
else
72-
custom_target('write_version_file',
73-
output: '_version_meson.py',
74-
command: [py, versioneer, '-o', '@OUTPUT@'],
75-
build_by_default: true,
76-
build_always_stale: true,
77-
install: true,
78-
install_dir: py.get_install_dir() / 'numpy'
79-
)
80-
meson.add_dist_script(py, versioneer, '-o', '_version_meson.py')
81-
endif
82-
8365
subdir('meson_cpu')
8466
subdir('numpy')

numpy/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@
108108
ComplexWarning, ModuleDeprecationWarning, VisibleDeprecationWarning,
109109
TooHardError, AxisError)
110110

111+
112+
# If a version with git hash was stored, use that instead
113+
from . import version
114+
from .version import __version__
115+
111116
# We first need to detect if we're being called as part of the numpy setup
112117
# procedure itself in a reliable manner.
113118
try:
@@ -447,8 +452,5 @@ def _pyinstaller_hooks_dir():
447452
del os
448453

449454

450-
# get the version using versioneer
451-
from .version import __version__, git_revision as __git_version__
452-
453455
# Remove symbols imported for internal use
454456
del sys, warnings

numpy/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ class _SupportsWrite(Protocol[_AnyStr_contra]):
666666
__all__: list[str]
667667
__path__: list[str]
668668
__version__: str
669-
__git_version__: str
670669
test: PytestTester
671670

672671
# TODO: Move placeholders to their respective module once

numpy/_build_utils/gitversion.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import os
2+
import textwrap
3+
4+
5+
def init_version():
6+
init = os.path.join(os.path.dirname(__file__), '../../pyproject.toml')
7+
data = open(init).readlines()
8+
9+
version_line = next(
10+
line for line in data if line.startswith('version =')
11+
)
12+
13+
version = version_line.strip().split(' = ')[1]
14+
version = version.replace('"', '').replace("'", '')
15+
16+
return version
17+
18+
19+
def git_version(version):
20+
# Append last commit date and hash to dev version information,
21+
# if available
22+
23+
import subprocess
24+
import os.path
25+
26+
try:
27+
p = subprocess.Popen(
28+
['git', 'log', '-1', '--format="%H %aI"'],
29+
stdout=subprocess.PIPE,
30+
stderr=subprocess.PIPE,
31+
cwd=os.path.dirname(__file__),
32+
)
33+
except FileNotFoundError:
34+
pass
35+
else:
36+
out, err = p.communicate()
37+
if p.returncode == 0:
38+
git_hash, git_date = (
39+
out.decode('utf-8')
40+
.strip()
41+
.replace('"', '')
42+
.split('T')[0]
43+
.replace('-', '')
44+
.split()
45+
)
46+
47+
# Only attach git tag to development versions
48+
if 'dev' in version:
49+
version += f'+git{git_date}.{git_hash[:7]}'
50+
else:
51+
git_hash = ''
52+
53+
return version, git_hash
54+
55+
56+
if __name__ == "__main__":
57+
import argparse
58+
59+
parser = argparse.ArgumentParser()
60+
parser.add_argument('--write', help="Save version to this file")
61+
parser.add_argument(
62+
'--meson-dist',
63+
help='Output path is relative to MESON_DIST_ROOT',
64+
action='store_true'
65+
)
66+
args = parser.parse_args()
67+
68+
version, git_hash = git_version(init_version())
69+
70+
# For NumPy 2.0, this should only have one field: `version`
71+
template = textwrap.dedent(f'''
72+
version = "{version}"
73+
__version__ = version
74+
full_version = version
75+
76+
git_revision = "{git_hash}"
77+
release = 'dev' not in version and '+' not in version
78+
short_version = version.split("+")[0]
79+
''')
80+
81+
if args.write:
82+
outfile = args.write
83+
if args.meson_dist:
84+
outfile = os.path.join(
85+
os.environ.get('MESON_DIST_ROOT', ''),
86+
outfile
87+
)
88+
89+
# Print human readable output path
90+
relpath = os.path.relpath(outfile)
91+
if relpath.startswith('.'):
92+
relpath = outfile
93+
94+
with open(outfile, 'w') as f:
95+
print(f'Saving version to {relpath}')
96+
f.write(template)
97+
else:
98+
print(version)

0 commit comments

Comments
 (0)