8000 Merge 0cb6e3bc8976dc1950e186eb874357b0e8adc563 into a2bfa54f825c93ad1… · numpy/numpy@d7ba6de · GitHub
[go: up one dir, main page]

Skip to content

Commit d7ba6de

Browse files
authored
Merge 0cb6e3b into a2bfa54
2 parents a2bfa54 + 0cb6e3b commit d7ba6de

22 files changed

+113
-2991
lines changed

.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

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ gitwash-update:
8282

8383
#SPHINXBUILD="LANG=C sphinx-build"
8484
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])")
85+
GITVER ?= $(shell cd ..; git rev-parse --short HEAD || 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: '2.0.0.dev0',
4+
version: run_command(
5+
# This should become `numpy/_version.py` in NumPy 2.0
6+
['python', 'numpy/_build_utils/gitversion.py', '--write', 'numpy/version.py'],
7+
check: true).stdout().strip(),
88
license: 'BSD-3',
99
meson_version: '>= 1.1.0',
1010
default_options: [
@@ -62,22 +62,4 @@ 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('numpy')

numpy/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696

9797
from ._globals import _NoValue, _CopyMode
9898

99+
100+
# If a version with git hash was stored, use that instead
101+
from . import version
102+
from .version import __version__
103+
99104
# We first need to detect if we're being called as part of the numpy setup
100105
# procedure itself in a reliable manner.
101106
try:
@@ -348,8 +353,5 @@ def _pyinstaller_hooks_dir():
348353
return [str(Path(__file__).with_name("_pyinstaller").resolve())]
349354

350355

351-
# get the version using versioneer
352-
from .version import __version__, git_revision as __git_version__
353-
354356
# Remove symbols imported for internal use
355357
del os, sys, warnings

numpy/__init__.pyi

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

671670
# TODO: Move placeholders to their respective module once

numpy/_build_utils/gitversion.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
if 'dev' in version:
21+
# Append last commit date and hash to dev version information,
22+
# if available
23+
24+
import subprocess
25+
import os.path
26+
27+
try:
28+
p = subprocess.Popen(
29+
['git', 'log', '-1', '--format="%H %h %aI"'],
30+
stdout=subprocess.PIPE,
31+
stderr=subprocess.PIPE,
10000
32+
cwd=os.path.dirname(__file__),
33+
)
34+
except FileNotFoundError:
35+
pass
36+
else:
37+
out, err = p.communicate()
38+
if p.returncode == 0:
39+
git_hash, git_hash_short, git_date = (
40+
out.decode('utf-8')
41+
.strip()
42+
.replace('"', '')
43+
.split('T')[0]
44+
.replace('-', '')
45+
.split()
46+
)
47+
48+
version__ = '+'.join(
49+
[tag for tag in version.split('+')
50+
if not tag.startswith('git')]
51+
)
52+
version += f'+git{git_date}.{git_hash_short}'
53+
else:
54+
git_hash = ''
55+
56+
return version, git_hash
57+
58+
59+
if __name__ == "__main__":
60+
import argparse
61+
62+
parser = argparse.ArgumentParser()
63+
parser.add_argument('--write', help="Save version to this file")
64+
args = parser.parse_args()
65+
66+
version, git_hash = git_version(init_version())
67+
68+
# For NumPy 2.0, this should only have one field: `version`
69+
template = textwrap.dedent(f'''
70+
version = "{version}"
71+
__version__ = version
72+
full_version = version
73+
74+
git_revision = "{git_hash}"
75+
release = 'dev' not in version and '+' not in version
76+
short_version = version.split("+")[0]
77+
''')
78+
79+
if args.write:
80+
with open(args.write, 'w') as f:
81+
f.write(template)
82+
83+
print(version)

0 commit comments

Comments
 (0)
0