From 70f100c56588e4119eca5d00ddb101911a4cd50e Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Mon, 17 May 2021 23:38:17 -0400 Subject: [PATCH] chore: Use newer setuptools_scm for versioning (#1450) * Update to a modern version of setuptools_scm to support pyproject-based Python packages - Use local_scheme = "no-local-version" to continue uploading to TestPyPI - c.f. https://github.com/pypa/setuptools_scm/blob/v6.0.1/README.rst#version-number-construction * Remove src/pyhf/version.py in favor of generating at build time - Remove setup.cfg and src/pyhf/version.py from bump2version control * Set fetch depth:0 in CI to get full history and tags to generate version number - c.f. https://github.com/scikit-hep/pyhf/issues/1465 --- .bumpversion.cfg | 4 ---- .github/workflows/ci.yml | 2 ++ .github/workflows/dependencies-head.yml | 10 ++++++++++ .github/workflows/docker.yml | 3 ++- .github/workflows/lower-bound-requirements.yml | 2 ++ .gitignore | 1 + docs/conf.py | 3 +-- pyproject.toml | 6 +++++- setup.cfg | 4 ---- src/pyhf/__init__.py | 2 +- src/pyhf/cli/cli.py | 2 +- src/pyhf/version.py | 5 ----- tests/test_public_api.py | 4 ++-- 13 files changed, 27 insertions(+), 21 deletions(-) delete mode 100644 src/pyhf/version.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 6ec96b588f..6f84a45b72 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -3,10 +3,6 @@ current_version = 0.6.1 commit = True tag = True -[bumpversion:file:setup.cfg] - -[bumpversion:file:src/pyhf/version.py] - [bumpversion:file:src/pyhf/utils.py] [bumpversion:file:README.rst] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f85de609b..5a39fdd584 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: diff --git a/.github/workflows/dependencies-head.yml b/.github/workflows/dependencies-head.yml index 6b7cde39a3..fb9cadd5aa 100644 --- a/.github/workflows/dependencies-head.yml +++ b/.github/workflows/dependencies-head.yml @@ -17,6 +17,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -43,6 +45,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -69,6 +73,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -94,6 +100,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -119,6 +127,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d104bf778f..a8b13a2d8a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,7 +23,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - + with: + fetch-depth: 0 - name: Prepare id: prep run: | diff --git a/.github/workflows/lower-bound-requirements.yml b/.github/workflows/lower-bound-requirements.yml index dddcc87b91..50382ace74 100644 --- a/.github/workflows/lower-bound-requirements.yml +++ b/.github/workflows/lower-bound-requirements.yml @@ -18,6 +18,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: diff --git a/.gitignore b/.gitignore index d884c02787..724abf3958 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +src/pyhf/version.py MANIFEST build dist diff --git a/docs/conf.py b/docs/conf.py index 3087ee17f4..17b9636843 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,8 +19,7 @@ import sys from pkg_resources import get_distribution -sys.path.insert(0, str(Path('../src').resolve())) -sys.path.insert(1, str(Path('./exts').resolve())) +sys.path.insert(0, str(Path('./exts').resolve())) def setup(app): diff --git a/pyproject.toml b/pyproject.toml index 34c4adb067..e16a744c8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,12 @@ [build-system] # Minimum requirements for the build system to execute. -requires = ["wheel", "setuptools>=30.3.0", "attrs>=17.1", "setuptools_scm"] +requires = ["wheel", "setuptools>=30.3.0", "attrs>=17.1", "setuptools_scm[toml]>=3.4"] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +write_to = "src/pyhf/version.py" +local_scheme = "no-local-version" + [tool.black] line-length = 88 target-version = ['py37', 'py38'] diff --git a/setup.cfg b/setup.cfg index 5a01829e36..d3ce6ba2f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [metadata] name = pyhf -version = 0.6.1 description = pure-Python HistFactory implementation with tensors and autodiff long_description = file: README.rst long_description_content_type = text/x-rst @@ -27,9 +26,6 @@ classifiers = Programming Language :: Python :: Implementation :: CPython [options] -setup_requires = - setuptools_scm>=1.15.0 - setuptools_scm_git_archive>=1.0 package_dir = = src packages = find: diff --git a/src/pyhf/__init__.py b/src/pyhf/__init__.py index b53d363b4a..7ea51365da 100644 --- a/src/pyhf/__init__.py +++ b/src/pyhf/__init__.py @@ -1,6 +1,6 @@ from .tensor import BackendRetriever as tensor from .optimize import OptimizerRetriever as optimize -from .version import __version__ +from .version import version as __version__ from .exceptions import InvalidBackend, InvalidOptimizer, Unsupported from . import events diff --git a/src/pyhf/cli/cli.py b/src/pyhf/cli/cli.py index c5fd7569ba..dd196bf312 100644 --- a/src/pyhf/cli/cli.py +++ b/src/pyhf/cli/cli.py @@ -3,7 +3,7 @@ import click -from ..version import __version__ +from .. import __version__ from . import rootio, spec, infer, patchset, complete from ..contrib import cli as contrib from .. import utils diff --git a/src/pyhf/version.py b/src/pyhf/version.py deleted file mode 100644 index 4cb9d254fb..0000000000 --- a/src/pyhf/version.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Define pyhf version information.""" - -# Use semantic versioning (https://semver.org/) -# The version number is controlled through bumpversion.cfg -__version__ = '0.6.1' diff --git a/tests/test_public_api.py b/tests/test_public_api.py index c064538aa5..a3aa440aed 100644 --- a/tests/test_public_api.py +++ b/tests/test_public_api.py @@ -8,7 +8,7 @@ def model_setup(backend): np.random.seed(0) n_bins = 100 # TODO: Simplify after pyhf v0.6.2 released - if tuple(int(part) for part in pyhf.__version__.split(".")) < (0, 6, 2): + if tuple(int(part) for part in pyhf.__version__.split(".")[:3]) < (0, 6, 2): model = pyhf.simplemodels.hepdata_like( [10] * n_bins, [50] * n_bins, [1] * n_bins ) @@ -211,7 +211,7 @@ def test_pdf_batched_deprecated_api(backend): # TODO: Remove skipif after pyhf v0.6.2 released @pytest.mark.skipif( - tuple(int(part) for part in pyhf.__version__.split(".")) < (0, 6, 2), + tuple(int(part) for part in pyhf.__version__.split(".")[:3]) < (0, 6, 2), reason="requires pyhf v0.6.2+", ) def test_pdf_batched(backend):