Skip to content

Commit

Permalink
ENH: move to ruff
Browse files Browse the repository at this point in the history
PR #277
  • Loading branch information
FFY00 committed Jan 30, 2023
1 parent 5d68ce6 commit ac8bfb0
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ repos:
rev: 5.11.4
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.236
hooks:
- id: flake8
language_version: python3.8
- id: ruff
args: [--fix, --format, grouped]
12 changes: 6 additions & 6 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
TextIO, Tuple, Type, TypeVar, Union
)

import pyproject_metadata # noqa: F401
import pyproject_metadata

from mesonpy._compat import Iterator, Literal, ParamSpec, Path

Expand Down Expand Up @@ -278,7 +278,7 @@ def is_pure(self) -> bool:
return True

@property
def wheel(self) -> bytes: # noqa: F811
def wheel(self) -> bytes:
"""Return WHEEL file for dist-info."""
return textwrap.dedent('''
Wheel-Version: 1.0
Expand Down Expand Up @@ -331,7 +331,7 @@ def _stable_abi(self) -> Optional[str]:
soext = sorted(_EXTENSION_SUFFIXES, key=len)[0]
abis = []

for path, src in self._wheel_files['platlib']:
for path, _ in self._wheel_files['platlib']:
if path.suffix == soext:
match = re.match(r'^[^.]+(.*)$', path.name)
assert match is not None
Expand Down Expand Up @@ -710,7 +710,7 @@ def __init__( # noqa: C901
self._pep621 = 'project' in self._config
if self.pep621:
try:
import pyproject_metadata # noqa: F811
import pyproject_metadata
except ModuleNotFoundError: # pragma: no cover
self._metadata = None
else:
Expand Down Expand Up @@ -987,7 +987,7 @@ def metadata(self) -> bytes:
return data.encode()

# re-import pyproject_metadata to raise ModuleNotFoundError if it is really missing
import pyproject_metadata # noqa: F401, F811
import pyproject_metadata # noqa: F401
assert self._metadata

core_metadata = self._metadata.as_rfc822()
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
return func(*args, **kwargs)
except Error as exc:
print('{red}meson-python: error:{reset} {msg}'.format(msg=str(exc), **_STYLES))
raise SystemExit(1)
raise SystemExit(1) from exc
return wrapper


Expand Down
4 changes: 2 additions & 2 deletions mesonpy/_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def debian_python() -> bool:
import distutils
try:
import distutils.command.install
except ModuleNotFoundError:
raise ModuleNotFoundError('Unable to import distutils, please install python3-distutils')
except ModuleNotFoundError as exc:
raise ModuleNotFoundError('Unable to import distutils, please install python3-distutils') from exc
return 'deb_system' in distutils.command.install.INSTALL_SCHEMES
except ModuleNotFoundError:
return False
Expand Down
4 changes: 2 additions & 2 deletions mesonpy/_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def get_abi_tag() -> str:
# https://github.com/pypa/packaging/pull/607.
try:
empty, abi, ext = str(sysconfig.get_config_var('EXT_SUFFIX')).split('.')
except ValueError:
except ValueError as exc:
# CPython <= 3.8.7 on Windows does not implement PEP3149 and
# uses '.pyd' as $EXT_SUFFIX, which does not allow to extract
# the interpreter ABI. Check that the fallback is not hit for
# any other Python implementation.
if sys.implementation.name != 'cpython':
raise NotImplementedError
raise NotImplementedError from exc
return _get_cpython_abi()

# The packaging module initially based his understanding of the
Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ ignore_missing_imports = true
strict = true


[tool.ruff]
line-length = 127
extend-ignore = [
'B019',
]
select = [
'B', # flake8-bugbear
'C4', # flake8-comprehensions
'C9', # mccabe
'E', # pycodestyle
'F', # pyflakes
'W', # pycodestyle
'RUF100', # ruff
]


[tool.ruff.mccabe]
max-complexity = 12


[tool.isort]
lines_between_types = 1
lines_after_imports = 2
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def test_generated_files(sdist_generated_files):
'executable_bit-1.0.0/generate_version.py',
}
with tarfile.open(sdist_generated_files, 'r:gz') as sdist:
assert set(tar.name for tar in sdist.getmembers()) == expected
assert {tar.name for tar in sdist.getmembers()} == expected
4 changes: 2 additions & 2 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@


def test_wheel_tag():
str(mesonpy._tags.Tag()) == f'{INTERPRETER}-{ABI}-{PLATFORM}'
str(mesonpy._tags.Tag(abi='abi3')) == f'{INTERPRETER}-abi3-{PLATFORM}'
assert str(mesonpy._tags.Tag()) == f'{INTERPRETER}-{ABI}-{PLATFORM}'
assert str(mesonpy._tags.Tag(abi='abi3')) == f'{INTERPRETER}-abi3-{PLATFORM}'


@pytest.mark.skipif(platform.system() != 'Darwin', reason='macOS specific test')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_scipy_like(wheel_scipy_like):
def test_contents(package_library, wheel_library):
artifact = wheel.wheelfile.WheelFile(wheel_library)

for name, regex in zip(sorted(wheel_contents(artifact)), [
for name, regex in zip(sorted(wheel_contents(artifact)), [ # noqa: B905
re.escape('.library.mesonpy.libs/libexample.so'),
re.escape('library-1.0.0.data/headers/examplelib.h'),
re.escape('library-1.0.0.data/scripts/example'),
Expand Down

0 comments on commit ac8bfb0

Please sign in to comment.