8000 MAINT: Remove versioneer by charris · Pull Request #24406 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Remove versioneer #24406

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 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6D47
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: '1.26.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 @@ -108,6 +108,11 @@
ComplexWarning, ModuleDeprecationWarning, VisibleDeprecationWarning,
TooHardError, AxisError)


# 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 @@ -447,8 +452,5 @@ def _pyinstaller_hooks_dir():
del os


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

# Remove symbols imported for internal use
del sys, warnings
1 change: 0 additions & 1 deletion numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,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
0