Skip to content

Commit

Permalink
Use ruff instead of flake8 and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Mar 17, 2024
1 parent 86b9312 commit 4de89f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ jobs:
- name: Launch tests
run: python -m pytest
- name: Check coding style
run: python -m flake8 --exclude tests/css-parsing-tests
- name: Check imports order
run: python -m isort . --check --diff
run: python -m ruff check
6 changes: 3 additions & 3 deletions cssselect2/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def __init__(self, parsed_selector):
self.requires_lang_attr = True


def FALSE(_el):
def FALSE(_el): # noqa: N802
return 0


def TRUE(_el):
def TRUE(_el): # noqa: N802
return 1


Expand Down Expand Up @@ -425,7 +425,7 @@ def count_func(el):
# Matches if a positive or zero integer n exists so that:
# x = a*n + b-1
# x = a*n + B
B = b - 1
B = b - 1 # noqa: N806
if a == 0:
# x = B
return lambda el: count_func(el) == B
Expand Down
7 changes: 3 additions & 4 deletions cssselect2/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
cached_property = functools.cached_property
else:
# Python 3.7
class cached_property:
class cached_property: # noqa: N801
# Borrowed from Werkzeug
# https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/utils.py

Expand Down Expand Up @@ -132,8 +132,7 @@ def ancestors(self):
"""
if self._ancestors is None:
self._ancestors = (
() if self.parent is None else
self.parent.ancestors + (self.parent,))
() if self.parent is None else (*self.parent.ancestors, self.parent))
return self._ancestors

@property
Expand All @@ -147,7 +146,7 @@ def previous_siblings(self):
if self._previous_siblings is None:
self._previous_siblings = (
() if self.previous is None else
self.previous.previous_siblings + (self.previous,))
(*self.previous.previous_siblings, self.previous))
return self._previous_siblings

def iter_ancestors(self):
Expand Down
9 changes: 3 additions & 6 deletions docs/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ You can launch tests using the following command::

venv/bin/python -m pytest

cssselect2 also uses isort_ to check imports and flake8_ to check the coding
style::
cssselect2 also uses ruff_ to check the coding style::

venv/bin/python -m isort . --check --diff
venv/bin/python -m flake8 --exclude tests/css-parsing-tests
venv/bin/python -m ruff check

.. _pytest: https://docs.pytest.org/
.. _isort: https://pycqa.github.io/isort/
.. _flake8: https://flake8.pycqa.org/
.. _ruff: https://docs.astral.sh/ruff/


Documentation
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Donation = 'https://opencollective.com/courtbouillon'

[project.optional-dependencies]
doc = ['sphinx', 'sphinx_rtd_theme']
test = ['pytest', 'isort', 'flake8']
test = ['pytest', 'ruff']

[tool.flit.sdist]
exclude = ['.*']
Expand All @@ -53,6 +53,9 @@ include = ['tests/*', 'cssselect2/*']
exclude_lines = ['pragma: no cover', 'def __repr__', 'raise NotImplementedError']
omit = ['.*']

[tool.isort]
default_section = 'FIRSTPARTY'
multi_line_output = 4
[tool.ruff.lint]
select = ['E', 'W', 'F', 'I', 'N', 'RUF']
ignore = ['RUF001', 'RUF002', 'RUF003']

[tool.ruff.lint.extend-per-file-ignores]
'docs/example.py' = ['I001']
3 changes: 2 additions & 1 deletion tests/test_cssselect2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"""

import xml.etree.ElementTree as etree
import xml.etree.ElementTree as etree # noqa: N813
from pathlib import Path

import pytest

from cssselect2 import ElementWrapper, SelectorError, compile_selector_list

from .w3_selectors import invalid_selectors, valid_selectors
Expand Down

0 comments on commit 4de89f6

Please sign in to comment.