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

Skip to content

MAINT: Remove versioneer #24196

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

Merged
merged 30 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3577579
Remove versioneer
stefanv Jul 16, 2023
28d3c16
Store git version to disk
stefanv Jul 17, 2023
1592713
Fix version imports
stefanv Jul 17, 2023
f9f4230
Satisfy linter
stefanv Jul 17, 2023
bee36bb
Fix version regex; remove check for removed np.version
stefanv Aug 3, 2023
4550ead
Read version from pyproject.toml
stefanv Aug 8, 2023
0711d75
Update gitignore
stefanv Aug 8, 2023
2afee19
Satisfy linter
stefanv Aug 8, 2023
6b1dc56
Handle missing .git directory
stefanv Aug 8, 2023
2b181ef
Update setuppy pyproject.toml variant
stefanv Aug 8, 2023
f44045d
doc: grab git version using git, not versioneer
stefanv Aug 8, 2023
fbb0254
Remove versioneer from linter exclude
stefanv Aug 8, 2023
79553c8
Fix base version number, should be `.dev0` (with a dot) to be valid
rgommers Aug 9, 2023
27b4c51
Fix and restore tests in `test_numpy_version.py`
rgommers Aug 9, 2023
6a6d63a
Fix CircleCI doc build error due to git hash
rgommers Aug 9, 2023
1fedea3
Always re-generate version.py during the build
stefanv Aug 9, 2023
7d1fc7f
No need to write version in meson config
stefanv Aug 10, 2023
75132ee
git hash is optional in, e.g., sdist build
stefanv Aug 10, 2023
3a9aec1
Always use 7 characters for shortened git hash
stefanv Aug 10, 2023
e0a3f86
Generate version.py as part of sdist
stefanv Aug 10, 2023
f827e86
Make gitversion aware of meson
stefanv Aug 10, 2023
ac1b69a
Run successfully on non-dev builds also
stefanv Aug 10, 2023
e36ab98
Version is not printed on cmd line when writing to file
stefanv Aug 10, 2023
12ed9f0
Calculate git version also for non-dev versions
stefanv Aug 11, 2023
5695abf
Do not generate version.py if it already exists in source tree
stefanv Aug 11, 2023
9ee4da9
Install version.py only when pre-built (build from sdist)
stefanv Aug 11, 2023
4abc3c7
Fix git version query
stefanv Aug 11, 2023
8287648
Merge branch 'main' into rm-versioneer
rgommers Aug 11, 2023
4b81f94
BUG: fix `python setup.py sdist` and the multiarray import error msg
rgommers Aug 11, 2023
6aff0bc
MAINT: revert change to setup.py for sdist/wheel versioning
rgommers Aug 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ numpy/core/src/common/dlpack/dlpack.h linguist-vendored
# Mark some files as generated
numpy/linalg/lapack_lite/f2c_*.c linguist-generated
numpy/linalg/lapack_lite/lapack_lite_names.h linguist-generated
numpy/_version.py linguist-generated

# versioneer config
numpy/_version.py export-subst
# version generated from pyproject.toml during build
numpy/version.py linguist-generated

# Configuration files
*.ini text
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ doc/source/savefig/

# Things specific to this project #
###################################
# The line below should change to numpy/_version.py for NumPy 2.0
numpy/version.py
numpy/core/__svn_version__.py
doc/numpy.scipy.org/_build
numpy/__config__.py
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude azure-*.yml
include .coveragerc

# Sub-directories. Included are: numpy/, doc/, benchmarks/, tools/
include numpy/_version.py
include numpy/version.py
recursive-include numpy/random *.pyx *.pxd *.pyx.in *.pxd.in
include numpy/py.typed
include numpy/random/include/*
Expand Down
4 changes: 2 additions & 2 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ gitwash-update:
#

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

version-check:
ifeq "$(GITVER)" "Unknown"
Expand Down
40 changes: 0 additions & 40 deletions generate_version.py

This file was deleted.

26 changes: 4 additions & 22 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
project(
'NumPy',
'c', 'cpp', 'cython',
# Note that the git commit hash cannot be added dynamically here
# It is dynamically added upon import by versioneer
# See `numpy/__init__.py`
version: '2.0.0.dev0',
version: run_command(
# This should become `numpy/_version.py` in NumPy 2.0
['python', 'numpy/_build_utils/gitversion.py'],
check: true).stdout().strip(),
license: 'BSD-3',
meson_version: '>=1.2.99', # version in vendored-meson is 1.2.99
default_options: [
Expand Down Expand Up @@ -62,23 +62,5 @@ if cc.get_id() == 'clang'
)
endif

# Generate version number. Note that this will not (yet) update the version
# number seen by pip or reflected in wheel filenames. See
# https://github.com/mesonbuild/meson-python/issues/159 for that.
versioneer = files('generate_version.py')
if fs.exists('_version_meson.py')
py.install_sources('_version_meson.py', subdir: 'numpy')
else
custom_target('write_version_file',
output: '_version_meson.py',
command: [py, versioneer, '-o', '@OUTPUT@'],
build_by_default: true,
build_always_stale: true,
install: true,
install_dir: py.get_install_dir() / 'numpy'
)
meson.add_dist_script(py, versioneer, '-o', '_version_meson.py')
endif

subdir('meson_cpu')
subdir('numpy')
8 changes: 5 additions & 3 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@

from ._globals import _NoValue, _CopyMode


# If a version with git hash was stored, use that instead
from . import version
from .version import __version__

# We first need to detect if we're being called as part of the numpy setup
# procedure itself in a reliable manner.
try:
Expand Down Expand Up @@ -348,8 +353,5 @@ def _pyinstaller_hooks_dir():
return [str(Path(__file__).with_name("_pyinstaller").resolve())]


# get the version using versioneer
from .version import __version__, git_revision as __git_version__

# Remove symbols imported for internal use
del os, sys, warnings
1 change: 0 additions & 1 deletion numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ class _SupportsWrite(Protocol[_AnyStr_contra]):
__all__: list[str]
__path__: list[str]
__version__: str
__git_version__: str
test: PytestTester

# TODO: Move placeholders to their respective module once
Expand Down
98 changes: 98 additions & 0 deletions numpy/_build_utils/gitversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
import textwrap


def init_version():
init = os.path.join(os.path.dirname(__file__), '../../pyproject.toml')
data = open(init).readlines()

version_line = next(
line for line in data if line.startswith('version =')
)

version = version_line.strip().split(' = ')[1]
version = version.replace('"', '').replace("'", '')

return version


def git_version(version):
# Append last commit date and hash to dev version information,
# if available

import subprocess
import os.path

try:
p = subprocess.Popen(
['git', 'log', '-1', '--format="%H %aI"'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.path.dirname(__file__),
)
except FileNotFoundError:
pass
else:
out, err = p.communicate()
if p.returncode == 0:
git_hash, git_date = (
out.decode('utf-8')
.strip()
.replace('"', '')
.split('T')[0]
.replace('-', '')
.split()
)

# Only attach git tag to development versions
if 'dev' in version:
version += f'+git{git_date}.{git_hash[:7]}'
else:
git_hash = ''

return version, git_hash


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--write', help="Save version to this file")
parser.add_argument(
'--meson-dist',
help='Output path is relative to MESON_DIST_ROOT',
action='store_true'
)
args = parser.parse_args()

version, git_hash = git_version(init_version())

# For NumPy 2.0, this should only have one field: `version`
template = textwrap.dedent(f'''
version = "{version}"
__version__ = version
full_version = version

git_revision = "{git_hash}"
release = 'dev' not in version and '+' not in version
short_version = version.split("+")[0]
''')

if args.write:
outfile = args.write
if args.meson_dist:
outfile = os.path.join(
os.environ.get('MESON_DIST_ROOT', ''),
outfile
)

# Print human readable output path
relpath = os.path.relpath(outfile)
if relpath.startswith('.'):
relpath = outfile

with open(outfile, 'w') as f:
print(f'Saving version to {relpath}')
f.write(template)
else:
print(version)
Loading