diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b645bb02b..331790218 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -171,7 +171,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 diff --git a/docs/update_cmake_version.rst b/docs/update_cmake_version.rst index 72593ade9..39de93b47 100644 --- a/docs/update_cmake_version.rst +++ b/docs/update_cmake_version.rst @@ -40,15 +40,15 @@ Classic procedure: Updating docs/index.rst - done Updating README.rst Updating README.rst - done - Updating tests/test_distribution.py - Updating tests/test_distribution.py - done + Updating tests/test_cmake.py + Updating tests/test_cmake.py - done 3. Create a topic named `update-to-cmake-X.Y.Z` and commit the changes. For example:: release=3.27.8 git switch -c update-to-cmake-$release - git add -u CMakeUrls.cmake docs/index.rst README.rst tests/test_distribution.py docs/update_cmake_version.rst + git add -u CMakeUrls.cmake docs/index.rst README.rst tests/test_cmake.py docs/update_cmake_version.rst git commit -m "Update to CMake $release" 4. Push the topic and create a `Pull Request`. diff --git a/noxfile.py b/noxfile.py index f545dea56..f62621c87 100644 --- a/noxfile.py +++ b/noxfile.py @@ -119,7 +119,7 @@ def bump(session: nox.Session) -> None: "CMakeUrls.cmake", "docs/index.rst", "README.rst", - "tests/test_distribution.py", + "tests/test_cmake.py", "docs/update_cmake_version.rst", ) _bump(session, "CMake", "kitware/cmake", "", "scripts/update_cmake_version.py", files) diff --git a/pyproject.toml b/pyproject.toml index f1106c5d4..cd362b076 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ before-all = [ before-build = "pip install -r requirements-repair.txt" repair-wheel-command = "python scripts/repair_wheel.py -w {dest_dir} {wheel}" test-extras = "test" -test-command = "pytest --ignore={project}/tests/test_distribution.py {project}/tests" +test-command = "pytest {project}/tests" build-verbosity = "1" [tool.cibuildwheel.linux] diff --git a/requirements-test.txt b/requirements-test.txt index 0b2a7cf67..45923ba3f 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,11 +1,4 @@ coverage>=4.2 -flake8>=3.0.4 -path.py>=11.5.0 +importlib_metadata>=2.0 pytest>=3.0.3 pytest-cov>=2.4.0 -pytest-runner>=2.9 -pytest-virtualenv>=1.7.0 -scikit-build>=0.10.0 -setuptools>=28.0.0 -virtualenv>=15.0.3 -wheel diff --git a/scripts/update_cmake_version.py b/scripts/update_cmake_version.py index cbdcc3ae5..20785402e 100755 --- a/scripts/update_cmake_version.py +++ b/scripts/update_cmake_version.py @@ -184,7 +184,7 @@ def update_tests(version): pattern = re.compile(r'expected_version = "\d.(\d)+.\d"') replacement = 'expected_version = "%s"' % version _update_file( - os.path.join(ROOT_DIR, "tests/test_distribution.py"), pattern, replacement + os.path.join(ROOT_DIR, "tests/test_cmake.py"), pattern, replacement ) @@ -228,7 +228,7 @@ def main(): Complete! Now run: git switch -c update-to-cmake-{release} - git add -u CMakeUrls.cmake docs/index.rst README.rst tests/test_distribution.py docs/update_cmake_version.rst + git add -u CMakeUrls.cmake docs/index.rst README.rst tests/test_cmake.py docs/update_cmake_version.rst git commit -m "Update to CMake {release}" gh pr create --fill --body "Created by update_cmake_version.py" """ diff --git a/tests/test_cmake.py b/tests/test_cmake.py index db4a0e5b9..f3cf2bdc2 100644 --- a/tests/test_cmake.py +++ b/tests/test_cmake.py @@ -1,12 +1,18 @@ # -*- coding: utf-8 -*- +import os +import subprocess +import sysconfig import textwrap import pytest +from importlib_metadata import distribution import cmake from . import push_argv +all_tools = pytest.mark.parametrize("tool", ["cmake", "cpack", "ctest"]) + def _run(program, args): func = getattr(cmake, program) @@ -16,10 +22,9 @@ def _run(program, args): assert excinfo.value.code == 0 -def test_cmake_module(): - _run("cmake", ["--version"]) - _run("cpack", ["--version"]) - _run("ctest", ["--version"]) +@all_tools +def test_cmake_module(tool): + _run(tool, ["--version"]) def test_cmake_https(tmpdir): @@ -43,3 +48,22 @@ def test_cmake_https(tmpdir): )) _run("cmake", ["-DTMP_DIR:PATH=%s" % str(tmpdir), "-P", str(test_script)]) + + +def _get_scripts(): + dist = distribution("cmake") + 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 + + +@all_tools +def test_cmake_script(tool): + expected_version = "3.27.8" + scripts = [script for script in _get_scripts() if script.stem == tool] + assert len(scripts) == 1 + output = subprocess.check_output([str(scripts[0]), "--version"]).decode("ascii") + assert output.splitlines()[0] == "{} version {}".format(tool, expected_version) diff --git a/tests/test_distribution.py b/tests/test_distribution.py deleted file mode 100644 index 838f4127a..000000000 --- a/tests/test_distribution.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -import os -import textwrap - -import pytest -from path import Path, matchers - -DIST_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../dist')) - - -def _check_cmake_install(virtualenv, tmpdir): - expected_version = "3.27.8" - - for executable_name in ["cmake", "cpack", "ctest"]: - output = virtualenv.run( - "%s --version" % executable_name, capture=True).splitlines()[0] - assert output == "{} version {}".format(executable_name, expected_version) - - test_script = tmpdir.join("test_cmake.cmake") - test_script.write(textwrap.dedent(r""" - message("${CMAKE_COMMAND}") - """)) - - output = virtualenv.run("cmake -P %s" % str(test_script), capture=True) - expected = os.path.realpath(virtualenv.virtualenv).replace(os.sep, "/") - assert output[:len(expected)].lower() == expected.lower() - - -@pytest.mark.skipif(not Path(DIST_DIR).exists(), reason="dist directory does not exist") -def test_source_distribution(virtualenv, tmpdir): - sdists = Path(DIST_DIR).files(match=matchers.CaseInsensitive("*.tar.gz")) - if not sdists: - pytest.skip("no source distribution available") - assert len(sdists) == 1 - - if "SETUP_CMAKE_ARGS" in os.environ: - virtualenv.env["SKBUILD_CONFIGURE_OPTIONS"] = os.environ["SETUP_CMAKE_ARGS"] - virtualenv.run("pip install %s" % sdists[0]) - assert "cmake" in virtualenv.installed_packages() - - _check_cmake_install(virtualenv, tmpdir) - - -@pytest.mark.skipif(not Path(DIST_DIR).exists(), reason="dist directory does not exist") -def test_wheel(virtualenv, tmpdir): - wheels = Path(DIST_DIR).files(match="*.whl") - if not wheels: - pytest.skip("no wheel available") - assert len(wheels) == 1 - print(wheels) - - virtualenv.run("pip install %s" % wheels[0]) - - _check_cmake_install(virtualenv, tmpdir)