Skip to content
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

BLD: use setuptools-scm for versioning #1134

Merged
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
4 changes: 3 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ install:
# Install the build and runtime dependencies of the project.
- conda update conda -y
- conda install -q --yes python=%PYTHON_VERSION% conda six pip pytest pytest-xdist pytest-timeout filelock selenium conda-build bzip2
- python -m pip install -U pip
- python -m pip install pytest-rerunfailures

# Check that we have the expected version of Python
- python --version

build_script:
# In-place build
- pip install .
- python -m pip install .
- dir asv

test_script:
- python -m pytest -l --basetemp=%APPVEYOR_BUILD_FOLDER%\\tmp -v --environment-type=conda --webdriver=ChromeHeadless --timeout=1800 --durations=100 test
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
os: ["ubuntu-latest"]
python-version: ["3.7", "3.10", "pypy-3.7", "pypy-3.8"]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

# We need Python 3.7 to always be installed, so tests with
# multiple environments can run.
Expand Down
28 changes: 2 additions & 26 deletions asv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import os
import sys

# This __version__ assignment is parsed by setup.py; keep it in this form.
# Development versions end with ".dev" (suffix is added below).
__version__ = "0.6.dev"
__release__ = not __version__.endswith(".dev")

try:
from ._version import __githash__, __suffix__
except ImportError:
__githash__ = None
__suffix__ = "0"
if not __release__:
__version__ += __suffix__
del __suffix__


if sys.version_info >= (3, 3):
# OS X framework builds of Python 3.3 can not call other 3.3
# virtualenvs as a subprocess because `__PYENV_LAUNCHER__` is
# inherited.
if os.environ.get('__PYVENV_LAUNCHER__'):
os.unsetenv('__PYVENV_LAUNCHER__')

from . import plugin_manager # noqa F401 unused, but required to load plugins
from asv._version import version as __version__
from asv import plugin_manager
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["wheel", "setuptools"]
requires = ["wheel", "setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "asv/_version.py"
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ignore =
W504, # W504: Line break occurred after a binary operator
E741 # E741: Do not use variables named 'I', 'O', or 'l'
exclude = setup.py,
asv/__init__.py
asv/environment.py,
asv/machine.py,
asv/graph.py,
Expand Down
104 changes: 1 addition & 103 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/usr/bin/env python
import os
import subprocess
import ast
from distutils.errors import (DistutilsError, CCompilerError, DistutilsExecError,
DistutilsPlatformError)
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError

from setuptools import setup, Extension
from setuptools.command.test import test as TestCommand
from setuptools.command.sdist import sdist
from setuptools.command.build_ext import build_ext

Expand Down Expand Up @@ -39,92 +36,6 @@ def __check_submodules(self):
raise ValueError('Submodule not clean: %s' % line)


basedir = os.path.abspath(os.path.dirname(__file__))


def get_version():
"""Parse current version number from __init__.py"""
# Grab the first assignment to __version__
version = None
init_py = os.path.join(os.path.dirname(__file__),
'asv', '__init__.py')
with open(init_py, 'r') as f:
source = f.read()
tree = ast.parse(source)
for statement in tree.body:
if (isinstance(statement, ast.Assign) and
len(statement.targets) == 1 and
statement.targets[0].id == '__version__'):
version = statement.value.s
break

if not version:
raise RuntimeError("Failed to parse version from {}".format(init_py))

if 'dev' in version and not version.endswith('.dev'):
raise RuntimeError("Dev version string in {} doesn't end in .dev".format(
init_py))

return version


def get_git_hash():
"""
Get version from asv/__init__.py and generate asv/_version.py
"""
# Obtain git revision
githash = ""
if os.path.isdir(os.path.join(basedir, '.git')):
try:
proc = subprocess.Popen(
['git', '-C', basedir, 'rev-parse', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rev, err = proc.communicate()
if proc.returncode == 0:
githash = rev.strip().decode('ascii')
except OSError:
pass
return githash


def get_git_revision():
"""
Get the number of revisions since the beginning.
"""
revision = "0"
if os.path.isdir(os.path.join(basedir, '.git')):
try:
proc = subprocess.Popen(
['git', '-C', basedir, 'rev-list', '--count', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rev, err = proc.communicate()
if proc.returncode == 0:
revision = rev.strip().decode('ascii')
except OSError:
pass
return revision


def write_version_file(filename, suffix, githash):
# Write revision file (only if it needs to be changed)
content = ('__suffix__ = "{0}"\n'
'__githash__ = "{1}"\n'.format(suffix, githash))

if not githash.strip():
# Not in git repository; probably in sdist, so keep old
# version file
return

old_content = None
if os.path.isfile(filename):
with open(filename, 'r') as f:
old_content = f.read()

if content != old_content:
with open(filename, 'w') as f:
f.write(content)


class BuildFailed(Exception):
pass

Expand Down Expand Up @@ -157,18 +68,6 @@ def initialize_options(self):


def run_setup(build_binary=False):
version = get_version()
git_hash = get_git_hash()

if version.endswith('.dev'):
suffix = '{0}+{1}'.format(get_git_revision(), git_hash[:8])
version += suffix
else:
suffix = ''

write_version_file(os.path.join(basedir, 'asv', '_version.py'),
suffix, git_hash)

ext_modules = []
if build_binary:
ext_modules = ext_modules.append(Extension("asv._rangemedian", ["asv/_rangemedian.cpp"]))
Expand All @@ -179,7 +78,6 @@ def run_setup(build_binary=False):
cmdclass['build_sphinx'] = BuildDoc

setup(
version=version,
ext_modules=ext_modules,
cmdclass=cmdclass,
)
Expand Down