From e768e59400f2138f547173932ed2b4287b4aa9d3 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Wed, 11 Oct 2023 13:21:17 +0200 Subject: [PATCH] switch to setuptools_scm --- .github/workflows/ci-tests.yml | 2 ++ .gitignore | 2 ++ MANIFEST.in | 2 +- build-cwltool-docker.sh | 7 +++--- cwltool.Dockerfile | 3 ++- gittaggers.py | 42 ---------------------------------- pyproject.toml | 4 ++++ setup.py | 14 ++---------- 8 files changed, 17 insertions(+), 59 deletions(-) delete mode 100644 gittaggers.py diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 82b8510ec1..98566a0c00 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -249,6 +249,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: record cwltool version + run: pip install -U setuptools wheel && pip install setuptools_scm[toml] && python setup.py --version - name: build & test cwltool_module container run: ./build-cwltool-docker.sh diff --git a/.gitignore b/.gitignore index 7a280f0df8..5941627f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,8 @@ value .python-version +cwltool/_version.py + # Folder created when using make cwltool_deps docs/_build/ diff --git a/MANIFEST.in b/MANIFEST.in index 6b533819d4..92f65cfe58 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,7 +2,7 @@ include README.rst CODE_OF_CONDUCT.md CONTRIBUTING.md include MANIFEST.in include LICENSE.txt include *requirements.txt mypy.ini tox.ini -include gittaggers.py Makefile cwltool.py +include Makefile cwltool.py recursive-include mypy-stubs *.pyi *.py include tests/* include tests/cwl-conformance/cwltool-conftest.py diff --git a/build-cwltool-docker.sh b/build-cwltool-docker.sh index 97910069aa..a70fdf4dfc 100755 --- a/build-cwltool-docker.sh +++ b/build-cwltool-docker.sh @@ -1,9 +1,10 @@ #!/bin/bash set -ex -docker build --file=cwltool.Dockerfile --tag=quay.io/commonwl/cwltool_module --target module . -docker build --file=cwltool.Dockerfile --tag=quay.io/commonwl/cwltool . +engine=${ENGINE:-docker} # example: `ENGINE=podman ./build-cwltool-docker.sh` +${engine} build --file=cwltool.Dockerfile --tag=quay.io/commonwl/cwltool_module --target module . +${engine} build --file=cwltool.Dockerfile --tag=quay.io/commonwl/cwltool . -docker run -t -v /var/run/docker.sock:/var/run/docker.sock \ +${engine} run -t -v /var/run/docker.sock:/var/run/docker.sock \ -v /tmp:/tmp \ -v "$PWD":/tmp/cwltool \ quay.io/commonwl/cwltool_module /bin/sh -c \ diff --git a/cwltool.Dockerfile b/cwltool.Dockerfile index 306c2997cf..4fa76b1264 100644 --- a/cwltool.Dockerfile +++ b/cwltool.Dockerfile @@ -4,7 +4,8 @@ RUN apk add --no-cache git gcc python3-dev libxml2-dev libxslt-dev libc-dev linu WORKDIR /cwltool COPY . . -RUN CWLTOOL_USE_MYPYC=1 MYPYPATH=mypy-stubs pip wheel --no-binary schema-salad \ +RUN export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CWLTOOL=$(grep __version__ cwltool/_version.py | awk -F\' '{ print $2 }') ; \ + CWLTOOL_USE_MYPYC=1 MYPYPATH=mypy-stubs pip wheel --no-binary schema-salad \ --wheel-dir=/wheels .[deps] # --verbose RUN rm /wheels/schema_salad* RUN pip install "black~=22.0" diff --git a/gittaggers.py b/gittaggers.py deleted file mode 100644 index c25dbe1af7..0000000000 --- a/gittaggers.py +++ /dev/null @@ -1,42 +0,0 @@ -import subprocess -import sys -import time - -import importlib.metadata - -from typing import Any - -from setuptools.command.egg_info import egg_info - -SETUPTOOLS_VER = importlib.metadata.version("setuptools").split(".") - -RECENT_SETUPTOOLS = ( - int(SETUPTOOLS_VER[0]) > 40 - or (int(SETUPTOOLS_VER[0]) == 40 and int(SETUPTOOLS_VER[1]) > 0) - or (int(SETUPTOOLS_VER[0]) == 40 and int(SETUPTOOLS_VER[1]) == 0 and int(SETUPTOOLS_VER[2]) > 0) -) - - -class EggInfoFromGit(egg_info): - """Tag the build with git commit timestamp. - - If a build tag has already been set (e.g., "egg_info -b", building - from source package), leave it alone. - """ - - def git_timestamp_tag(self) -> str: - gitinfo = subprocess.check_output( - ["git", "log", "--first-parent", "--max-count=1", "--format=format:%ct", "."] - ).strip() - return time.strftime(".%Y%m%d%H%M%S", time.gmtime(int(gitinfo))) - - def tags(self) -> Any: - if self.tag_build is None: - try: - self.tag_build = self.git_timestamp_tag() - except subprocess.CalledProcessError: - pass - return egg_info.tags(self) # type: ignore[no-untyped-call] - - if RECENT_SETUPTOOLS: - vtags = property(tags) diff --git a/pyproject.toml b/pyproject.toml index 90c1bbc4eb..530185163a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = [ "setuptools>=45", + "setuptools_scm[toml]>=8.0.4,<9", "mypy==1.6.0", # also update mypy-requirements.txt "types-requests", "types-psutil", @@ -14,6 +15,9 @@ requires = [ ] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +write_to = "cwltool/_version.py" + [tool.black] line-length = 100 target-version = [ "py38" ] diff --git a/setup.py b/setup.py index 1502aa5ce4..24cd357fbe 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,7 @@ import os import sys import warnings -from typing import Type -import setuptools.command.egg_info as egg_info_cmd from setuptools import setup if os.name == "nt": @@ -25,13 +23,6 @@ SETUP_DIR = os.path.dirname(__file__) README = os.path.join(SETUP_DIR, "README.rst") -try: - import gittaggers - - Tagger: Type[egg_info_cmd.egg_info] = gittaggers.EggInfoFromGit -except ImportError: - Tagger = egg_info_cmd.egg_info - NEEDS_PYTEST = {"pytest", "test", "ptr"}.intersection(sys.argv) PYTEST_RUNNER = ["pytest-runner", "pytest-cov"] if NEEDS_PYTEST else [] USE_MYPYC = False @@ -94,7 +85,6 @@ setup( name="cwltool", - version="3.1", description="Common workflow language reference implementation", long_description=open(README).read(), long_description_content_type="text/x-rst", @@ -130,7 +120,8 @@ "deps": ["galaxy-tool-util >= 22.1.2, <23", "galaxy-util <23"], }, python_requires=">=3.8, <4", - setup_requires=PYTEST_RUNNER, + use_scm_version=True, + setup_requires=PYTEST_RUNNER + ["setuptools_scm>=8.0.4,<9"], test_suite="tests", tests_require=[ "bagit >= 1.6.4, < 1.9", @@ -142,7 +133,6 @@ ], entry_points={"console_scripts": ["cwltool=cwltool.main:run"]}, zip_safe=True, - cmdclass={"egg_info": Tagger}, classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console",