From 2d958dc2b6966a5946fdc0ff673e8a01a73b1b00 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Sat, 10 Feb 2024 12:35:09 +0100 Subject: [PATCH] Fixed black styling + fixed CI/justfile --- .github/workflows/python-lint-tests.yml | 2 +- justfile | 3 ++- tests/conftest.py | 6 ++---- tests/test_files.py | 1 + vpype/__init__.py | 1 + vpype/config.py | 18 +++++++++--------- vpype/model.py | 1 + vpype/text.py | 8 +++++--- vpype_cli/__init__.py | 1 + vpype_cli/debug.py | 1 + vpype_viewer/__init__.py | 1 + vpype_viewer/engine.py | 1 + vpype_viewer/qtviewer/viewer.py | 1 + 13 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/python-lint-tests.yml b/.github/workflows/python-lint-tests.yml index 88e1ffe4..8fe18795 100644 --- a/.github/workflows/python-lint-tests.yml +++ b/.github/workflows/python-lint-tests.yml @@ -38,7 +38,7 @@ jobs: - name: Lint and static analysis if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' # no need to run that 9x run: | - poetry run ruff check --show-source vpype vpype_cli vpype_viewer tests + poetry run ruff check --output-format=full vpype vpype_cli vpype_viewer tests poetry run black --check --diff vpype vpype_cli vpype_viewer tests poetry run mypy # needed for tests to work on ubuntu (libEGL.so.1) diff --git a/justfile b/justfile index 609b2e29..af42cada 100644 --- a/justfile +++ b/justfile @@ -12,7 +12,8 @@ test: lint: mypy - ruff check vpype vpype_cli vpype_viewer tests + ruff check --output-format=full vpype vpype_cli vpype_viewer tests + black --check --diff vpype vpype_cli vpype_viewer tests # run previously failed tests test-failed: diff --git a/tests/conftest.py b/tests/conftest.py index 8342fd42..d3fae5aa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,8 +57,7 @@ def _make_config_file(text: str) -> str: class LineCollectionMaker(Protocol): def __call__( self, line_count: int | None = ..., with_metadata: bool = ... - ) -> vp.LineCollection: - ... + ) -> vp.LineCollection: ... @pytest.fixture @@ -95,8 +94,7 @@ def _make_line_collection( class DocumentMaker(Protocol): - def __call__(self, layer_count: int = ...) -> vp.Document: - ... + def __call__(self, layer_count: int = ...) -> vp.Document: ... @pytest.fixture diff --git a/tests/test_files.py b/tests/test_files.py index e282e9ac..80db9ed0 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -1,4 +1,5 @@ """Run a bunch of tests on the svg collection.""" + from __future__ import annotations import difflib diff --git a/vpype/__init__.py b/vpype/__init__.py index 0ef91b82..068d94f5 100644 --- a/vpype/__init__.py +++ b/vpype/__init__.py @@ -1,4 +1,5 @@ """This module contains vpype core and its API.""" + from __future__ import annotations from .config import * diff --git a/vpype/config.py b/vpype/config.py index 8643dfd7..a0d5b854 100644 --- a/vpype/config.py +++ b/vpype/config.py @@ -51,9 +51,9 @@ class PaperConfig: ] #: location on paper of the (0, 0) plotter unit coordinates paper_size: tuple[float, float] | None = None #: X/Y axis convention of the plotter - paper_orientation: None | ( - str - ) = None #: orientation of the plotter coordinate system on paper + paper_orientation: None | (str) = ( + None #: orientation of the plotter coordinate system on paper + ) x_range: tuple[int, int] | None = None #: admissible range of X coordinates y_range: tuple[int, int] | None = None #: admissible range of Y coordinates origin_location_reference: str | None = "topleft" #: reference for ``origin_location`` @@ -61,9 +61,9 @@ class PaperConfig: info: str = "" #: information printed to the user when paper is used rotate_180: bool = False #: if True, the geometries are rotated by 180 degrees on the page set_ps: int | None = None #: if not None, call PS with corresponding value - final_pu_params: None | ( - str - ) = None #: if not None, these params are added to the final PU command + final_pu_params: None | (str) = ( + None #: if not None, these params are added to the final PU command + ) aka_names: list[str] = dataclasses.field( default_factory=list ) #: alternative paper names (will be found by :func:`paper_config` @@ -74,9 +74,9 @@ def from_config(cls, data: dict[str, Any]) -> PaperConfig: name=data["name"], y_axis_up=data["y_axis_up"], origin_location=_convert_length_pair(data["origin_location"]), - paper_size=_convert_length_pair(data["paper_size"]) - if "paper_size" in data - else None, + paper_size=( + _convert_length_pair(data["paper_size"]) if "paper_size" in data else None + ), paper_orientation=data.get("paper_orientation", None), x_range=(data["x_range"][0], data["x_range"][1]) if "x_range" in data else None, y_range=(data["y_range"][0], data["y_range"][1]) if "y_range" in data else None, diff --git a/vpype/model.py b/vpype/model.py index 904895a9..1ef4a970 100644 --- a/vpype/model.py +++ b/vpype/model.py @@ -1,4 +1,5 @@ """Implementation of vpype's data model.""" + from __future__ import annotations import math diff --git a/vpype/text.py b/vpype/text.py index e7fbc939..dff9fd9c 100644 --- a/vpype/text.py +++ b/vpype/text.py @@ -241,9 +241,11 @@ def measure(txt): lines = _word_wrap(paragraph, width, hyphenate, measure) lc_arr = [ - _justify_text(line, font, width) - if justify and not line.endswith("\n") - else _text_line(line, font) + ( + _justify_text(line, font, width) + if justify and not line.endswith("\n") + else _text_line(line, font) + ) for line in lines ] diff --git a/vpype_cli/__init__.py b/vpype_cli/__init__.py index 57af9df2..655a68ff 100644 --- a/vpype_cli/__init__.py +++ b/vpype_cli/__init__.py @@ -1,6 +1,7 @@ """This module implements vpype's CLI interface and the :func:`execute() ` function. """ + # register all commands from __future__ import annotations diff --git a/vpype_cli/debug.py b/vpype_cli/debug.py index c2983fe5..8c48d13a 100644 --- a/vpype_cli/debug.py +++ b/vpype_cli/debug.py @@ -1,4 +1,5 @@ """Hidden debug commands to help testing.""" + from __future__ import annotations import json diff --git a/vpype_viewer/__init__.py b/vpype_viewer/__init__.py index ce175a40..4788162e 100644 --- a/vpype_viewer/__init__.py +++ b/vpype_viewer/__init__.py @@ -2,6 +2,7 @@ rendering of :class:`vpype.Document` instances. It includes a Qt-based interactive backend as well as a Pillow-based offscreen rendering backend. """ + from __future__ import annotations from ._scales import DEFAULT_SCALE_SPEC, UnitType diff --git a/vpype_viewer/engine.py b/vpype_viewer/engine.py index 01eb1a4f..828caa42 100644 --- a/vpype_viewer/engine.py +++ b/vpype_viewer/engine.py @@ -1,4 +1,5 @@ """Generic viewer.""" + from __future__ import annotations import enum diff --git a/vpype_viewer/qtviewer/viewer.py b/vpype_viewer/qtviewer/viewer.py index 0fd51dd8..c899e9bd 100644 --- a/vpype_viewer/qtviewer/viewer.py +++ b/vpype_viewer/qtviewer/viewer.py @@ -1,4 +1,5 @@ """Qt Viewer.""" + from __future__ import annotations import functools