Skip to content

Commit 14658da

Browse files
authored
chore: switch to ruff (#334)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 39ae35c commit 14658da

File tree

10 files changed

+58
-46
lines changed

10 files changed

+58
-46
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,8 @@ repos:
1818
- id: trailing-whitespace
1919
- id: fix-encoding-pragma
2020

21-
- repo: https://github.com/PyCQA/isort
22-
rev: 5.12.0
21+
- repo: https://github.com/charliermarsh/ruff-pre-commit
22+
rev: "v0.0.253"
2323
hooks:
24-
- id: isort
25-
26-
- repo: https://github.com/asottile/pyupgrade
27-
rev: v2.38.2
28-
hooks:
29-
- id: pyupgrade
30-
31-
- repo: https://github.com/PyCQA/flake8
32-
rev: 6.0.0
33-
hooks:
34-
- id: flake8
35-
additional_dependencies: [flake8-bugbear]
24+
- id: ruff
25+
args: [--fix, --show-fixes]

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# -*- coding: utf-8 -*-
32
#
43
# CMake Python Distributions documentation build configuration file, created by

pyproject.toml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,44 @@ environment = { SKBUILD_CONFIGURE_OPTIONS = "-DOPENSSL_ROOT_DIR:PATH=/usr/local/
4949
[tool.cibuildwheel.macos.environment]
5050
MACOSX_DEPLOYMENT_TARGET = "10.10"
5151

52-
[tool.isort]
53-
profile = "black"
52+
53+
[tool.ruff]
54+
select = [
55+
"E", "F", "W", # flake8
56+
"B", # flake8-bugbear
57+
"I", # isort
58+
"ARG", # flake8-unused-arguments
59+
"C4", # flake8-comprehensions
60+
"ICN", # flake8-import-conventions
61+
"ISC", # flake8-implicit-str-concat
62+
"G", # flake8-logging-format
63+
"PGH", # pygrep-hooks
64+
"PIE", # flake8-pie
65+
"PL", # pylint
66+
"PT", # flake8-pytest-style
67+
"RET", # flake8-return
68+
"RUF", # Ruff-specific
69+
"SIM", # flake8-simplify
70+
"EXE", # flake8-executable
71+
"NPY", # NumPy specific rules
72+
"PD", # pandas-vet
73+
]
74+
extend-ignore = [
75+
"PLR", # Design related pylint codes
76+
"E501", # Line too long
77+
"RUF005", # Python 3 needed
78+
"B904", # Python 3 needed
79+
"SIM105", # Python 3 needed
80+
]
81+
src = ["src"]
82+
unfixable = [
83+
"T20", # Removes print statements
84+
"F841", # Removes unused variables
85+
]
86+
exclude = ["versioneer.py", "src/cmake/_version.py"]
87+
flake8-unused-arguments.ignore-variadic-names = true
88+
89+
[tool.ruff.per-file-ignores]
90+
"docs/conf.py" = ["E402"]
91+
"*.pyi" = ["ARG001"]
92+
"noxfile.py" = ["PLW0603"] # Could be fixed if Python 2 dropped

scripts/convert_to_generic_platform_wheel.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import os
55
import sys
66
from itertools import product
7-
from os.path import abspath, basename, dirname, isfile
7+
from os.path import abspath, basename, dirname, isfile, splitext
88
from os.path import join as pjoin
9-
from os.path import splitext
109

1110
try:
1211
from wheel.install import WheelFile
@@ -78,7 +77,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms)
7877
platform_tags = fparts['plat'].split('.')
7978
logger.debug('Previous platform tags: %s', ', '.join(platform_tags))
8079
if additional_platforms:
81-
platform_tags = list(sorted(set(platform_tags + [p for p in additional_platforms])))
80+
platform_tags = sorted(set(platform_tags + list(additional_platforms)))
8281
fparts['plat'] = '.'.join(platform_tags)
8382
logger.debug('New platform tags ....: %s', ', '.join(platform_tags))
8483
else:
@@ -98,7 +97,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms)
9897
if py2_py3:
9998
if len({"py2", "py3"} & set(pyver_tags)) == 0:
10099
raise ValueError("pyver_tags does not contain py2 nor py3")
101-
pyver_tags = list(sorted(set(pyver_tags + ["py2", "py3"])))
100+
pyver_tags = sorted(set(pyver_tags + ["py2", "py3"]))
102101
if pyver_tags != original_pyver_tags:
103102
logger.debug('New pyver tags ....: %s', ', '.join(pyver_tags))
104103
fparts['pyver'] = '.'.join(pyver_tags)
@@ -160,7 +159,7 @@ def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_orig
160159
ctx.out_wheel = _convert_to_generic_platform_wheel(ctx, py2_py3, additional_platforms)
161160

162161
if remove_original:
163-
logger.info('Removed original wheel %s' % wheel_path)
162+
logger.info('Removed original wheel %s', wheel_path)
164163
os.remove(wheel_path)
165164

166165

scripts/repair_wheel.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ def main():
4545
if os_ == "linux":
4646
subprocess.run(["auditwheel", "repair", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE)
4747
elif os_ == "macos":
48-
# delocate does not pass for now: https://github.com/matthew-brett/delocate/issues/105
49-
# subprocess.run(
50-
# ["delocate-wheel", "--require-archs", "arm64,x86_64", "-w", str(tmpdir), str(file)],
51-
# check=True,
52-
# stdout=subprocess.PIPE,
53-
# )
54-
shutil.copyfile(file, tmpdir / file.name)
48+
subprocess.run(
49+
["delocate-wheel", "--require-archs", "arm64,x86_64", "-w", str(tmpdir), str(file)],
50+
check=True,
51+
stdout=subprocess.PIPE,
52+
)
5553
elif os_ == "windows":
5654
# no specific tool, just copy
5755
shutil.copyfile(file, tmpdir / file.name)

scripts/update_cmake_version.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def generate_cmake_variables(urls_and_sha256s):
111111
template_inputs["%s_url" % var_prefix] = urls_and_sha256s_values[0]
112112
template_inputs["%s_sha256" % var_prefix] = urls_and_sha256s_values[1]
113113

114-
cmake_variables = textwrap.dedent(
114+
return textwrap.dedent(
115115
"""
116116
#-----------------------------------------------------------------------------
117117
# CMake sources
@@ -144,8 +144,6 @@ def generate_cmake_variables(urls_and_sha256s):
144144
"""
145145
).format(**template_inputs)
146146

147-
return cmake_variables
148-
149147

150148
def update_cmake_urls_script(version):
151149
content = generate_cmake_variables(get_cmake_archive_urls_and_sha256s(version))

setup.cfg

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
[flake8]
2-
max-line-length: 130
3-
# Whether to display the pep8 instructions on failure (can be quite verbose)
4-
show-pep8: False
5-
# Whether to show source code for each failure
6-
show-source: True
7-
# Maximum cyclomatic complexity allowed
8-
max-complexity: 14
9-
format: pylint
10-
exclude: .git,.idea,.eggs,__pycache__,.tox,docs/conf.py,_skbuild,CMake-src,versioneer.py,_version.py,.venv,.nox
11-
121
[tool:pytest]
132
testpaths = tests
143
addopts = -v --cov --cov-report xml

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def parse_requirements(filename):
2929

3030
test_requirements = parse_requirements('requirements-test.txt')
3131

32-
try: # noqa: C901
32+
try:
3333
setup(
3434
name='cmake',
3535

src/cmake/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import NoReturn
1+
from typing import Iterator, NoReturn
22

33
__version__: tuple[int, int, int] | tuple[int, int, int, str, str]
44

tests/test_cmake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def _run(program, args):
1313
args = ["%s.py" % program] + args
1414
with push_argv(args), pytest.raises(SystemExit) as excinfo:
1515
func()
16-
assert 0 == excinfo.value.code
16+
assert excinfo.value.code == 0
1717

1818

1919
def test_cmake_module():

0 commit comments

Comments
 (0)