Skip to content

Commit

Permalink
Merge pull request #2133 from Kozea/ruff
Browse files Browse the repository at this point in the history
Use ruff to replace flake8 and isort
  • Loading branch information
liZe authored Apr 24, 2024
2 parents f599742 + 29597ab commit e901ff7
Show file tree
Hide file tree
Showing 53 changed files with 191 additions and 186 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ jobs:
env:
DYLD_FALLBACK_LIBRARY_PATH: /opt/homebrew/lib
- name: Check coding style
run: python -m flake8
- name: Check imports order
run: python -m isort . --check --diff
run: python -m ruff check
9 changes: 3 additions & 6 deletions docs/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ You can launch tests using the following command::

venv/bin/python -m pytest

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

venv/bin/python -m isort . --check --diff
venv/bin/python -m flake8
venv/bin/python -m ruff check

.. _pytest: https://docs.pytest.org/
.. _Ghostscript: https://www.ghostscript.com/
.. _DejaVu fonts: https://dejavu-fonts.github.io/
.. _isort: https://pycqa.github.io/isort/
.. _flake8: https://flake8.pycqa.org/
.. _ruff: https://docs.astral.sh/ruff/


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

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

[project.scripts]
weasyprint = 'weasyprint.__main__:main'
Expand All @@ -68,6 +68,6 @@ include = ['tests/*', 'weasyprint/*']
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']
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import pytest
from PIL import Image

from weasyprint import HTML
from weasyprint.document import Document

Expand Down
4 changes: 2 additions & 2 deletions tests/css/test_common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Test the CSS parsing, cascade, inherited and computed values."""


import pytest

from weasyprint import CSS, default_url_fetcher
from weasyprint.css import find_stylesheets, get_all_computed_styles
from weasyprint.urls import path2url

from ..testing_utils import (
from ..testing_utils import ( # isort:skip
BASE_URL, FakeHTML, assert_no_logs, capture_logs, resource_path)


Expand Down
2 changes: 1 addition & 1 deletion tests/css/test_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from ..testing_utils import (
from ..testing_utils import ( # isort:skip
FakeHTML, assert_no_logs, assert_tree, parse_all, render_pages)

RENDER = FakeHTML(string='')._ua_counter_style()[0].render_value
Expand Down
1 change: 1 addition & 0 deletions tests/css/test_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
import tinycss2

from weasyprint.css import preprocess_stylesheet
from weasyprint.css.validation.descriptors import preprocess_descriptors

Expand Down
1 change: 1 addition & 0 deletions tests/css/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test CSS errors and warnings."""

import pytest

from weasyprint import CSS

from ..testing_utils import assert_no_logs, capture_logs, render_pages
Expand Down
1 change: 1 addition & 0 deletions tests/css/test_expanders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
import tinycss2
from tinycss2.color3 import parse_color

from weasyprint.css import preprocess_declarations
from weasyprint.css.properties import INITIAL_VALUES, ZERO_PIXELS
from weasyprint.css.validation.expanders import EXPANDERS
Expand Down
1 change: 1 addition & 0 deletions tests/css/test_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from math import isclose

import pytest

from weasyprint import CSS
from weasyprint.css import get_all_computed_styles
from weasyprint.css.computed_values import strut_layout
Expand Down
7 changes: 3 additions & 4 deletions tests/css/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import pytest
import tinycss2

from weasyprint import CSS
from weasyprint.css import (
PageType, get_all_computed_styles, parse_page_selectors)
from weasyprint.css import PageType, get_all_computed_styles, parse_page_selectors
from weasyprint.layout.page import set_page_type_computed_styles

from ..testing_utils import (
FakeHTML, assert_no_logs, render_pages, resource_path)
from ..testing_utils import FakeHTML, assert_no_logs, render_pages, resource_path


@assert_no_logs
Expand Down
29 changes: 16 additions & 13 deletions tests/css/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
import tinycss2

from weasyprint.css import preprocess_declarations
from weasyprint.css.validation.properties import PROPERTIES
from weasyprint.images import LinearGradient, RadialGradient
Expand Down Expand Up @@ -249,19 +250,21 @@ def test_background_image_invalid(rule):
('bottom 3px left 10%', (('left', (10, '%'), 'bottom', (3, 'px')),)),
('right 10% top 3px', (('right', (10, '%'), 'top', (3, 'px')),)),
('top 3px right 10%', (('right', (10, '%'), 'top', (3, 'px')),)),
) + tuple(
(css_x, (('left', val_x, 'top', (50, '%')),))
for css_x, val_x in (
('left', (0, '%')), ('center', (50, '%')), ('right', (100, '%')),
('4.5%', (4.5, '%')), ('12px', (12, 'px')))
) + tuple(
(f'{css_x} {css_y}', (('left', val_x, 'top', val_y),))
for css_x, val_x in (
('left', (0, '%')), ('center', (50, '%')), ('right', (100, '%')),
('4.5%', (4.5, '%')), ('12px', (12, 'px')))
for css_y, val_y in (
('top', (0, '%')), ('center', (50, '%')), ('bottom', (100, '%')),
('7%', (7, '%')), ('1.5px', (1.5, 'px')))
*tuple(
(css_x, (('left', val_x, 'top', (50, '%')),))
for css_x, val_x in (
('left', (0, '%')), ('center', (50, '%')), ('right', (100, '%')),
('4.5%', (4.5, '%')), ('12px', (12, 'px')))
),
*tuple(
(f'{css_x} {css_y}', (('left', val_x, 'top', val_y),))
for css_x, val_x in (
('left', (0, '%')), ('center', (50, '%')), ('right', (100, '%')),
('4.5%', (4.5, '%')), ('12px', (12, 'px')))
for css_y, val_y in (
('top', (0, '%')), ('center', (50, '%')), ('bottom', (100, '%')),
('7%', (7, '%')), ('1.5px', (1.5, 'px')))
),
))
def test_background_position(rule, value):
assert get_value(f'background-position: {rule}') == value
Expand Down
1 change: 1 addition & 0 deletions tests/css/test_variables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test CSS custom properties, also known as CSS variables."""

import pytest

from weasyprint.css.properties import KNOWN_PROPERTIES

from ..testing_utils import assert_no_logs, capture_logs, render_pages
Expand Down
1 change: 1 addition & 0 deletions tests/draw/svg/test_images.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test how images are drawn in SVG."""

import pytest

from weasyprint.urls import path2url

from ...testing_utils import assert_no_logs, resource_path
Expand Down
38 changes: 19 additions & 19 deletions tests/draw/svg/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@assert_no_logs
def test_path_Hh(assert_pixels):
def test_path_h(assert_pixels):
assert_pixels('''
BBBBBBBB__
BBBBBBBB__
Expand Down Expand Up @@ -35,7 +35,7 @@ def test_path_Hh(assert_pixels):


@assert_no_logs
def test_path_Vv(assert_pixels):
def test_path_v(assert_pixels):
assert_pixels('''
BB____GG__
BB____GG__
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_path_Vv(assert_pixels):


@assert_no_logs
def test_path_Ll(assert_pixels):
def test_path_l(assert_pixels):
assert_pixels('''
______RR__
______RR__
Expand All @@ -93,7 +93,7 @@ def test_path_Ll(assert_pixels):


@assert_no_logs
def test_path_Zz(assert_pixels):
def test_path_z(assert_pixels):
assert_pixels('''
BBBBBBB___
BBBBBBB___
Expand All @@ -120,7 +120,7 @@ def test_path_Zz(assert_pixels):


@assert_no_logs
def test_path_Zz_fill(assert_pixels):
def test_path_z_fill(assert_pixels):
assert_pixels('''
BBBBBBB___
BBBBBBB___
Expand All @@ -147,7 +147,7 @@ def test_path_Zz_fill(assert_pixels):


@assert_no_logs
def test_path_Cc(assert_pixels):
def test_path_c(assert_pixels):
assert_pixels('''
__________
__________
Expand All @@ -174,7 +174,7 @@ def test_path_Cc(assert_pixels):


@assert_no_logs
def test_path_Ss(assert_pixels):
def test_path_s(assert_pixels):
assert_pixels('''
__________
__________
Expand All @@ -201,7 +201,7 @@ def test_path_Ss(assert_pixels):


@assert_no_logs
def test_path_CcSs(assert_pixels):
def test_path_cs(assert_pixels):
assert_pixels('''
__BBBBBB__
__BBBBBBB_
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_path_CcSs(assert_pixels):


@assert_no_logs
def test_path_Qq(assert_pixels):
def test_path_q(assert_pixels):
assert_pixels('''
__________
__________
Expand All @@ -261,7 +261,7 @@ def test_path_Qq(assert_pixels):


@assert_no_logs
def test_path_Tt(assert_pixels):
def test_path_t(assert_pixels):
assert_pixels('''
__________
__________
Expand All @@ -288,7 +288,7 @@ def test_path_Tt(assert_pixels):


@assert_no_logs
def test_path_QqTt(assert_pixels):
def test_path_qt(assert_pixels):
assert_pixels('''
_BBBB_______
BBBBBBB_____
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_path_QqTt(assert_pixels):


@assert_no_logs
def test_path_QqTt2(assert_pixels):
def test_path_qt2(assert_pixels):
assert_pixels('''
_BBBB_______
BBBBBBB_____
Expand Down Expand Up @@ -346,7 +346,7 @@ def test_path_QqTt2(assert_pixels):


@assert_no_logs
def test_path_Aa(assert_pixels):
def test_path_a(assert_pixels):
assert_pixels('''
__BBBB______
_BBBBB______
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_path_Aa(assert_pixels):


@assert_no_logs
def test_path_Aa2(assert_pixels):
def test_path_a2(assert_pixels):
assert_pixels('''
______GGGG__
______GGGGG_
Expand All @@ -402,7 +402,7 @@ def test_path_Aa2(assert_pixels):


@assert_no_logs
def test_path_Aa3(assert_pixels):
def test_path_a3(assert_pixels):
assert_pixels('''
______GGGG__
______GGGGG_
Expand All @@ -429,7 +429,7 @@ def test_path_Aa3(assert_pixels):


@assert_no_logs
def test_path_Aa4(assert_pixels):
def test_path_a4(assert_pixels):
assert_pixels('''
____________
____BBB_____
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_path_Aa4(assert_pixels):


@assert_no_logs
def test_path_Aa5(assert_pixels):
def test_path_a5(assert_pixels):
assert_pixels('''
__BBBBBBBB__
_BBBBBBBBBB_
Expand All @@ -485,7 +485,7 @@ def test_path_Aa5(assert_pixels):


@assert_no_logs
def test_path_Aa6(assert_pixels):
def test_path_a6(assert_pixels):
assert_pixels('''
__BBBBBBBB__
_BBBBBBBBBB_
Expand All @@ -512,7 +512,7 @@ def test_path_Aa6(assert_pixels):


@assert_no_logs
def test_path_Aa7(assert_pixels):
def test_path_a7(assert_pixels):
assert_pixels('''
____________
____________
Expand Down
1 change: 1 addition & 0 deletions tests/draw/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import itertools

import pytest

from weasyprint import HTML

from ..testing_utils import assert_no_logs
Expand Down
3 changes: 1 addition & 2 deletions tests/draw/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import pytest

from ..testing_utils import (
FakeHTML, assert_no_logs, capture_logs, resource_path)
from ..testing_utils import FakeHTML, assert_no_logs, capture_logs, resource_path

centered_image = '''
________
Expand Down
1 change: 1 addition & 0 deletions tests/layout/test_block.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for blocks layout."""

import pytest

from weasyprint.formatting_structure import boxes

from ..testing_utils import assert_no_logs, render_pages
Expand Down
1 change: 1 addition & 0 deletions tests/layout/test_float.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for floating boxes layout."""

import pytest

from weasyprint.formatting_structure import boxes

from ..testing_utils import assert_no_logs, render_pages
Expand Down
Loading

0 comments on commit e901ff7

Please sign in to comment.