diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a07530eca..d3193b468 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,18 +18,8 @@ repos: - id: trailing-whitespace - id: fix-encoding-pragma -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: "v0.0.253" hooks: - - id: isort - -- repo: https://github.com/asottile/pyupgrade - rev: v2.38.2 - hooks: - - id: pyupgrade - -- repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear] + - id: ruff + args: [--fix, --show-fixes] diff --git a/docs/conf.py b/docs/conf.py index 2c42ae9e8..d201f63d8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # CMake Python Distributions documentation build configuration file, created by diff --git a/pyproject.toml b/pyproject.toml index ad0717088..fb20c9391 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,5 +49,44 @@ environment = { SKBUILD_CONFIGURE_OPTIONS = "-DOPENSSL_ROOT_DIR:PATH=/usr/local/ [tool.cibuildwheel.macos.environment] MACOSX_DEPLOYMENT_TARGET = "10.10" -[tool.isort] -profile = "black" + +[tool.ruff] +select = [ + "E", "F", "W", # flake8 + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet +] +extend-ignore = [ + "PLR", # Design related pylint codes + "E501", # Line too long + "RUF005", # Python 3 needed + "B904", # Python 3 needed + "SIM105", # Python 3 needed +] +src = ["src"] +unfixable = [ + "T20", # Removes print statements + "F841", # Removes unused variables +] +exclude = ["versioneer.py", "src/cmake/_version.py"] +flake8-unused-arguments.ignore-variadic-names = true + +[tool.ruff.per-file-ignores] +"docs/conf.py" = ["E402"] +"*.pyi" = ["ARG001"] +"noxfile.py" = ["PLW0603"] # Could be fixed if Python 2 dropped diff --git a/scripts/convert_to_generic_platform_wheel.py b/scripts/convert_to_generic_platform_wheel.py index 0a0598d5c..efc64f564 100644 --- a/scripts/convert_to_generic_platform_wheel.py +++ b/scripts/convert_to_generic_platform_wheel.py @@ -4,9 +4,8 @@ import os import sys from itertools import product -from os.path import abspath, basename, dirname, isfile +from os.path import abspath, basename, dirname, isfile, splitext from os.path import join as pjoin -from os.path import splitext try: from wheel.install import WheelFile @@ -78,7 +77,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms) platform_tags = fparts['plat'].split('.') logger.debug('Previous platform tags: %s', ', '.join(platform_tags)) if additional_platforms: - platform_tags = list(sorted(set(platform_tags + [p for p in additional_platforms]))) + platform_tags = sorted(set(platform_tags + list(additional_platforms))) fparts['plat'] = '.'.join(platform_tags) logger.debug('New platform tags ....: %s', ', '.join(platform_tags)) else: @@ -98,7 +97,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms) if py2_py3: if len({"py2", "py3"} & set(pyver_tags)) == 0: raise ValueError("pyver_tags does not contain py2 nor py3") - pyver_tags = list(sorted(set(pyver_tags + ["py2", "py3"]))) + pyver_tags = sorted(set(pyver_tags + ["py2", "py3"])) if pyver_tags != original_pyver_tags: logger.debug('New pyver tags ....: %s', ', '.join(pyver_tags)) fparts['pyver'] = '.'.join(pyver_tags) @@ -160,7 +159,7 @@ def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_orig ctx.out_wheel = _convert_to_generic_platform_wheel(ctx, py2_py3, additional_platforms) if remove_original: - logger.info('Removed original wheel %s' % wheel_path) + logger.info('Removed original wheel %s', wheel_path) os.remove(wheel_path) diff --git a/scripts/repair_wheel.py b/scripts/repair_wheel.py index 703a0e8f6..cd5149834 100755 --- a/scripts/repair_wheel.py +++ b/scripts/repair_wheel.py @@ -45,13 +45,11 @@ def main(): if os_ == "linux": subprocess.run(["auditwheel", "repair", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE) elif os_ == "macos": - # delocate does not pass for now: https://github.com/matthew-brett/delocate/issues/105 - # subprocess.run( - # ["delocate-wheel", "--require-archs", "arm64,x86_64", "-w", str(tmpdir), str(file)], - # check=True, - # stdout=subprocess.PIPE, - # ) - shutil.copyfile(file, tmpdir / file.name) + subprocess.run( + ["delocate-wheel", "--require-archs", "arm64,x86_64", "-w", str(tmpdir), str(file)], + check=True, + stdout=subprocess.PIPE, + ) elif os_ == "windows": # no specific tool, just copy shutil.copyfile(file, tmpdir / file.name) diff --git a/scripts/update_cmake_version.py b/scripts/update_cmake_version.py index eaaf924ab..4f1e76c4e 100755 --- a/scripts/update_cmake_version.py +++ b/scripts/update_cmake_version.py @@ -111,7 +111,7 @@ def generate_cmake_variables(urls_and_sha256s): template_inputs["%s_url" % var_prefix] = urls_and_sha256s_values[0] template_inputs["%s_sha256" % var_prefix] = urls_and_sha256s_values[1] - cmake_variables = textwrap.dedent( + return textwrap.dedent( """ #----------------------------------------------------------------------------- # CMake sources @@ -144,8 +144,6 @@ def generate_cmake_variables(urls_and_sha256s): """ ).format(**template_inputs) - return cmake_variables - def update_cmake_urls_script(version): content = generate_cmake_variables(get_cmake_archive_urls_and_sha256s(version)) diff --git a/setup.cfg b/setup.cfg index 9c05375ed..6376f3192 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,3 @@ -[flake8] -max-line-length: 130 -# Whether to display the pep8 instructions on failure (can be quite verbose) -show-pep8: False -# Whether to show source code for each failure -show-source: True -# Maximum cyclomatic complexity allowed -max-complexity: 14 -format: pylint -exclude: .git,.idea,.eggs,__pycache__,.tox,docs/conf.py,_skbuild,CMake-src,versioneer.py,_version.py,.venv,.nox - [tool:pytest] testpaths = tests addopts = -v --cov --cov-report xml diff --git a/setup.py b/setup.py index 706e0a9eb..d0434f8e2 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def parse_requirements(filename): test_requirements = parse_requirements('requirements-test.txt') -try: # noqa: C901 +try: setup( name='cmake', diff --git a/src/cmake/__init__.pyi b/src/cmake/__init__.pyi index 4aba0de7b..7bb53539f 100644 --- a/src/cmake/__init__.pyi +++ b/src/cmake/__init__.pyi @@ -1,4 +1,4 @@ -from typing import NoReturn +from typing import Iterator, NoReturn __version__: tuple[int, int, int] | tuple[int, int, int, str, str] diff --git a/tests/test_cmake.py b/tests/test_cmake.py index 4c71f1a36..db4a0e5b9 100644 --- a/tests/test_cmake.py +++ b/tests/test_cmake.py @@ -13,7 +13,7 @@ def _run(program, args): args = ["%s.py" % program] + args with push_argv(args), pytest.raises(SystemExit) as excinfo: func() - assert 0 == excinfo.value.code + assert excinfo.value.code == 0 def test_cmake_module():