From d0bf87aef8086f591d8050eb84340a11930b5da9 Mon Sep 17 00:00:00 2001 From: Rogdham Date: Sat, 20 Sep 2025 09:57:39 +0200 Subject: [PATCH] chore: use ruff formatter --- .github/workflows/build.yml | 1 - .isort.cfg | 4 ---- .vscode/extensions.json | 7 +++++++ .vscode/settings.json | 9 +++++---- CHANGELOG.md | 1 + dev-requirements.txt | 5 +---- pyproject.toml | 7 +++++++ src/xz/open.py | 9 +++------ src/xz/typing.py | 9 +++------ tests/integration/test_ram_usage.py | 13 ++++++------- tests/integration/test_readme.py | 4 +--- tests/unit/test_block.py | 6 +++--- tox.ini | 14 +++----------- 13 files changed, 40 insertions(+), 49 deletions(-) delete mode 100644 .isort.cfg create mode 100644 .vscode/extensions.json create mode 100644 pyproject.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 035d4fc..1e2299b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,6 @@ jobs: matrix: env: - build - - format - generate-integration-files - lint - type diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index d2106d6..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[settings] -force_sort_within_sections = True -profile = black -src_paths = src diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..8a5d7d4 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "charliermarsh.ruff", + "esbenp.prettier-vscode", + "ms-python.python" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e3e80f..7915221 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,9 @@ ".eggs": true, "**/*.egg-info": true, ".coverage": true, + ".mypy_cache": true, ".pytest_cache": true, + ".ruff_cache": true, ".tox": true }, "editor.detectIndentation": false, @@ -23,8 +25,9 @@ "editor.wordWrapColumn": 88 }, "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", "editor.codeActionsOnSave": { - "source.organizeImports": true + "source.organizeImports": "explicit" } }, "[yaml]": { @@ -32,8 +35,6 @@ "editor.tabSize": 2 }, "python.envFile": "${workspaceFolder}/.vscode/env", - "python.formatting.provider": "black", "python.linting.pylintEnabled": true, - "python.testing.pytestEnabled": true, - "python.sortImports.args": ["-sp .isort.cfg"] + "python.testing.pytestEnabled": true } diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ee4c3..ba60f22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ adheres to [Semantic Versioning](https://semver.org/). - Update GitHub actions dependencies - Add tests for PyPy 3.10 and 3.11 - Improve tox & CI pipelines +- Use ruff as formatter ## [0.5.0] - 2023-02-27 diff --git a/dev-requirements.txt b/dev-requirements.txt index dc656c8..cac6104 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,12 +4,9 @@ # build build==1.3.0 -# format -black==23.1.0 -isort==5.12.0 - # lint pylint==2.16.2 +ruff==0.13.1 # typing mypy==1.0.1 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..35e6c9c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +# +# ruff +# + +[tool.ruff] +src = ["src"] +target-version = "py39" diff --git a/src/xz/open.py b/src/xz/open.py index 1f1e915..4ffb49f 100644 --- a/src/xz/open.py +++ b/src/xz/open.py @@ -79,8 +79,7 @@ def xz_open( encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, -) -> XZFile: - ... # pragma: no cover +) -> XZFile: ... # pragma: no cover @overload @@ -97,8 +96,7 @@ def xz_open( encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, -) -> _XZFileText: - ... # pragma: no cover +) -> _XZFileText: ... # pragma: no cover @overload @@ -115,8 +113,7 @@ def xz_open( encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, -) -> Union[XZFile, _XZFileText]: - ... # pragma: no cover +) -> Union[XZFile, _XZFileText]: ... # pragma: no cover def xz_open( diff --git a/src/xz/typing.py b/src/xz/typing.py index b2e2072..dfbfc7f 100644 --- a/src/xz/typing.py +++ b/src/xz/typing.py @@ -24,11 +24,8 @@ class _BlockReadStrategyType(Protocol): - def on_create(self, block: "XZBlock") -> None: - ... # pragma: no cover + def on_create(self, block: "XZBlock") -> None: ... # pragma: no cover - def on_delete(self, block: "XZBlock") -> None: - ... # pragma: no cover + def on_delete(self, block: "XZBlock") -> None: ... # pragma: no cover - def on_read(self, block: "XZBlock") -> None: - ... # pragma: no cover + def on_read(self, block: "XZBlock") -> None: ... # pragma: no cover diff --git a/tests/integration/test_ram_usage.py b/tests/integration/test_ram_usage.py index 8a17cbb..1363810 100644 --- a/tests/integration/test_ram_usage.py +++ b/tests/integration/test_ram_usage.py @@ -67,8 +67,7 @@ def test_read_linear( while xz_file.read(DEFAULT_BUFFER_SIZE): assert ( # should not use much more memory, take 2 as error margin - ram_usage() - < one_block_memory * 2 + ram_usage() < one_block_memory * 2 ), f"Consumes too much RAM (at {100 * xz_file.tell() / len(xz_file):.0f}%)" @@ -89,9 +88,10 @@ def test_partial_read_each_block( else: assert ( # default strategy is max 8 blocks, take 10 as error margin - ram_usage() - < one_block_memory * 10 - ), f"Consumes too much RAM (at {100 * xz_file.tell() / len(xz_file):.0f}%)" + ram_usage() < one_block_memory * 10 + ), ( + f"Consumes too much RAM (at {100 * xz_file.tell() / len(xz_file):.0f}%)" + ) def test_write( @@ -115,6 +115,5 @@ def test_write( else: assert ( # should not use much more memory, take 2 as error margin - ram_usage() - < one_block_memory * 2 + ram_usage() < one_block_memory * 2 ), f"Consumes too much RAM (at {i / nb_blocks:.0f}%)" diff --git a/tests/integration/test_readme.py b/tests/integration/test_readme.py index c3e5aa9..a122e59 100644 --- a/tests/integration/test_readme.py +++ b/tests/integration/test_readme.py @@ -48,9 +48,7 @@ def _parse_readme() -> List[Tuple[int, str]]: for line_no, code_block in _README_CODE_BLOCKS ], ) -def test_readme( - code_block: str, tmp_path: Path -) -> None: # pylint: disable=redefined-outer-name +def test_readme(code_block: str, tmp_path: Path) -> None: # pylint: disable=redefined-outer-name path = tmp_path / "block.txt" path.write_text(code_block) failure_count, test_count = doctest.testfile( diff --git a/tests/unit/test_block.py b/tests/unit/test_block.py index 3a4acfb..1373079 100644 --- a/tests/unit/test_block.py +++ b/tests/unit/test_block.py @@ -213,7 +213,7 @@ def test_read_wrong_uncompressed_size_too_big( def test_read_wrong_block_padding( - data_pattern_locate: Callable[[bytes], Tuple[int, int]] + data_pattern_locate: Callable[[bytes], Tuple[int, int]], ) -> None: fileobj = IOStatic(BLOCK_BYTES[:-5] + b"\xff" + BLOCK_BYTES[-4:]) block = XZBlock(fileobj, 1, 89, 100) @@ -228,7 +228,7 @@ def test_read_wrong_block_padding( def test_read_wrong_check( - data_pattern_locate: Callable[[bytes], Tuple[int, int]] + data_pattern_locate: Callable[[bytes], Tuple[int, int]], ) -> None: fileobj = IOStatic(BLOCK_BYTES[:-4] + b"\xff" * 4) @@ -261,7 +261,7 @@ def test_read_truncated_data() -> None: def test_read_decompressor_eof( - data_pattern_locate: Callable[[bytes], Tuple[int, int]] + data_pattern_locate: Callable[[bytes], Tuple[int, int]], ) -> None: fileobj = IOStatic( bytes.fromhex( diff --git a/tox.ini b/tox.ini index 748aec3..2b16a82 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ [tox] envlist = py, py39, py310, py311, pypy3 - build, format, generate-integration-files, lint, type + build, generate-integration-files, lint, type [testenv] package = wheel @@ -27,16 +27,6 @@ deps = commands = python -m build -[testenv:format] -basepython = python3.11 -skip_install = true -deps = - black==23.1.0 - isort==5.12.0 -commands = - black {posargs:--check --diff} src tests - isort {posargs:--check --diff} src tests - [testenv:generate-integration-files] basepython = python3.11 deps = @@ -53,7 +43,9 @@ basepython = python3.11 deps = pylint==2.16.2 pytest==7.2.1 # to avoid import errors + ruff==0.13.1 commands = + ruff format --check src tests pylint src pylint -d duplicate-code,too-many-statements,use-implicit-booleaness-not-comparison tests