Skip to content

chore: switch to ruff #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# CMake Python Distributions documentation build configuration file, created by
Expand Down
43 changes: 41 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions scripts/convert_to_generic_platform_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
12 changes: 5 additions & 7 deletions scripts/repair_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions scripts/update_cmake_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 0 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parse_requirements(filename):

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

try: # noqa: C901
try:
setup(
name='cmake',

Expand Down
2 changes: 1 addition & 1 deletion src/cmake/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import NoReturn
from typing import Iterator, NoReturn

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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down