From d79e6145e4ba3bfc34b166441461f3d5bb6d39d2 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 21 Oct 2023 11:01:42 +0200 Subject: [PATCH 1/3] chore(ci): bump `test_sdist` python from 3.11 to 3.12 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a091d80..a598aa5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -108,7 +108,7 @@ jobs: strategy: fail-fast: false matrix: - python: ["2.7", "3.6", "3.11"] + python: ["2.7", "3.6", "3.12"] steps: - uses: actions/checkout@v4 From b690942f07f9d9a2615aa5900fb5a47716aaa0e5 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 21 Oct 2023 11:27:01 +0200 Subject: [PATCH 2/3] chore: remove `test_distribution.py` It was always skipped in CI tests and relies on plugins that do not support python 3.12 Remove the file and move the version check to test_ninja. --- docs/update_ninja_version.rst | 6 ++--- noxfile.py | 2 +- requirements-test.txt | 5 ---- scripts/update_ninja_version.py | 4 +-- tests/test_distribution.py | 43 --------------------------------- tests/test_ninja.py | 4 ++- 6 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 tests/test_distribution.py diff --git a/docs/update_ninja_version.rst b/docs/update_ninja_version.rst index 1688495..a188bc2 100644 --- a/docs/update_ninja_version.rst +++ b/docs/update_ninja_version.rst @@ -44,8 +44,8 @@ Classic procedure: Updating README.rst - done Updating docs/update_ninja_version.rst Updating docs/update_ninja_version.rst - done - Updating tests/test_distribution.py - Updating tests/test_distribution.py - done + Updating tests/test_ninja.py + Updating tests/test_ninja.py - done 3. Create a topic named `update-to-ninja-X.Y.Z` and commit the changes. @@ -53,7 +53,7 @@ Classic procedure: release=1.11.1.g95dee.kitware.jobserver-1 git checkout -b update-to-ninja-${release} - git add NinjaUrls.cmake README.rst docs/update_ninja_version.rst tests/test_distribution.py + git add NinjaUrls.cmake README.rst docs/update_ninja_version.rst tests/test_ninja.py git commit -m "Update to Ninja ${release}" 4. Create a `Pull Request`. diff --git a/noxfile.py b/noxfile.py index e21080b..359b425 100644 --- a/noxfile.py +++ b/noxfile.py @@ -102,7 +102,7 @@ def bump(session: nox.Session) -> None: files = ( "NinjaUrls.cmake", "README.rst", - "tests/test_distribution.py", + "tests/test_ninja.py", "docs/update_ninja_version.rst", ) session.run( diff --git a/requirements-test.txt b/requirements-test.txt index 5bc4e09..67d645f 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,8 +1,3 @@ -codecov>=2.0.5 coverage>=4.2 -flake8>=3.0.4 pytest>=4.5.0 pytest-cov>=2.7.1 -pytest-runner>=5.1 -pytest-virtualenv>=1.7.0 -virtualenv>=15.0.3 diff --git a/scripts/update_ninja_version.py b/scripts/update_ninja_version.py index ab32ea6..ef5873d 100644 --- a/scripts/update_ninja_version.py +++ b/scripts/update_ninja_version.py @@ -173,7 +173,7 @@ def update_tests(version): pattern = re.compile(r'expected_version = "\d+.\d+.\d+(\.[\w\-]+)*"') replacement = 'expected_version = "%s"' % version _update_file(os.path.join( - ROOT_DIR, "tests/test_distribution.py"), pattern, replacement) + ROOT_DIR, "tests/test_ninja.py"), pattern, replacement) def main(): @@ -214,7 +214,7 @@ def main(): Complete! Now run: git switch -c update-to-ninja-{release} - git add -u NinjaUrls.cmake docs/index.rst README.rst tests/test_distribution.py docs/update_ninja_version.rst + git add -u NinjaUrls.cmake docs/index.rst README.rst tests/test_ninja.py docs/update_ninja_version.rst git commit -m "Update to Ninja {release}" gh pr create --fill --body "Created by update_ninja_version.py" """ diff --git a/tests/test_distribution.py b/tests/test_distribution.py deleted file mode 100644 index bdd5e57..0000000 --- a/tests/test_distribution.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -import os - -import pytest -from path import Path, matchers - -DIST_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../dist')) - - -def _check_ninja_install(virtualenv): - expected_version = "1.11.1.git.kitware.jobserver-1" - - for executable_name in ["ninja"]: - output = virtualenv.run( - "%s --version" % executable_name, capture=True).splitlines()[0] - assert output == "%s" % expected_version - - -@pytest.mark.skipif(not Path(DIST_DIR).exists(), reason="dist directory does not exist") -def test_source_distribution(virtualenv): - sdists = Path(DIST_DIR).files(match=matchers.CaseInsensitive("*.tar.gz")) - if not sdists: - pytest.skip("no source distribution available") - assert len(sdists) == 1 - - virtualenv.run("pip install scikit-build") - virtualenv.run("pip install %s" % sdists[0]) - assert "ninja" in virtualenv.installed_packages() - - _check_ninja_install(virtualenv) - - -@pytest.mark.skipif(not Path(DIST_DIR).exists(), reason="dist directory does not exist") -def test_wheel(virtualenv): - wheels = Path(DIST_DIR).files(match=matchers.CaseInsensitive("*.whl")) - if not wheels: - pytest.skip("no wheel available") - assert len(wheels) == 1 - - virtualenv.run("pip install %s" % wheels[0]) - assert "ninja" in virtualenv.installed_packages() - - _check_ninja_install(virtualenv) diff --git a/tests/test_ninja.py b/tests/test_ninja.py index 1f6aaa9..57085b3 100644 --- a/tests/test_ninja.py +++ b/tests/test_ninja.py @@ -22,4 +22,6 @@ def test_ninja_module(): def test_ninja_package(): - subprocess.check_call([sys.executable, "-m", "ninja", "--version"]) + expected_version = "1.11.1.git.kitware.jobserver-1" + output = subprocess.check_output([sys.executable, "-m", "ninja", "--version"]).decode("ascii") + assert output.splitlines()[0] == expected_version From f704f435962ee620d6859d98b048f400addb2287 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 21 Oct 2023 13:49:07 +0200 Subject: [PATCH 3/3] chore: add test for `ninja` script --- requirements-test.txt | 1 + tests/test_ninja.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/requirements-test.txt b/requirements-test.txt index 67d645f..bd793e9 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,4 @@ coverage>=4.2 +importlib_metadata>=2.0 pytest>=4.5.0 pytest-cov>=2.7.1 diff --git a/tests/test_ninja.py b/tests/test_ninja.py index 57085b3..57ddf85 100644 --- a/tests/test_ninja.py +++ b/tests/test_ninja.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- +import os import subprocess import sys +import sysconfig import pytest +from importlib_metadata import distribution import ninja @@ -17,6 +20,16 @@ def _run(program, args): assert excinfo.value.code == 0 +def _get_scripts(): + dist = distribution("ninja") + scripts_paths = [os.path.abspath(sysconfig.get_path("scripts", scheme)) for scheme in sysconfig.get_scheme_names()] + scripts = [] + for file in dist.files: + if os.path.abspath(str(file.locate().parent)) in scripts_paths: + scripts.append(file.locate().resolve(strict=True)) + return scripts + + def test_ninja_module(): _run("ninja", ["--version"]) @@ -25,3 +38,12 @@ def test_ninja_package(): expected_version = "1.11.1.git.kitware.jobserver-1" output = subprocess.check_output([sys.executable, "-m", "ninja", "--version"]).decode("ascii") assert output.splitlines()[0] == expected_version + + +def test_ninja_script(): + expected_version = "1.11.1.git.kitware.jobserver-1" + scripts = _get_scripts() + assert len(scripts) == 1 + assert scripts[0].stem == "ninja" + output = subprocess.check_output([str(scripts[0]), "--version"]).decode("ascii") + assert output.splitlines()[0] == expected_version