From 1621141381c708640d50e7e54ae36962f1e1dc7a Mon Sep 17 00:00:00 2001 From: Lukas Berbuer Date: Fri, 17 Feb 2023 19:24:27 +0100 Subject: [PATCH] Use ruff instead of isort, pylint and flake8 --- .github/workflows/ci.yml | 6 ++-- .pre-commit-config.yaml | 23 +++--------- README.md | 1 + pyproject.toml | 58 +++++++++++++++--------------- src/conan_check_updates/cli.py | 2 +- src/conan_check_updates/conan.py | 4 +-- src/conan_check_updates/version.py | 1 - tests/test_cli.py | 1 - tests/test_color.py | 1 - tests/test_conan.py | 1 - tests/test_conan_e2e.py | 3 +- tests/test_filter.py | 1 - tests/test_main.py | 1 - tests/test_version.py | 1 - 14 files changed, 39 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f8ebc9..447ddaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,8 @@ jobs: run: pip install tox - name: Run black run: tox -e black - - name: Run isort - run: tox -e isort - - name: Run pylint - run: tox -e pylint + - name: Run ruff + run: tox -e ruff - name: Run mypy run: tox -e mypy - name: Run pytest (Conan v1) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ea39765..34b3cb5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,26 +10,11 @@ repos: rev: 22.12.0 hooks: - id: black - - repo: "https://github.com/PyCQA/isort" - rev: 5.11.2 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.247 hooks: - - id: isort - - repo: "https://github.com/PyCQA/flake8" - rev: 6.0.0 - hooks: - - id: flake8 - args: [--max-line-length=100] - additional_dependencies: - - flake8-bugbear - - flake8-builtins - - flake8-comprehensions - - flake8-logging-format - - flake8-pytest-style - - flake8-simplify - - repo: "https://github.com/PyCQA/pylint" - rev: v2.15.8 - hooks: - - id: pylint + - id: ruff + args: [--fix, --exit-non-zero-on-fix] - repo: "https://github.com/pre-commit/mirrors-mypy" rev: v0.991 hooks: diff --git a/README.md b/README.md index 9dad431..c2fdbf1 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![PyPI](https://img.shields.io/pypi/v/conan-check-updates)](https://pypi.org/project/conan-check-updates) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/conan-check-updates)](https://pypi.org/project/conan-check-updates) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff) Check for updates of your `conanfile.txt` / `conanfile.py` requirements. diff --git a/pyproject.toml b/pyproject.toml index b76f26e..39d8c09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,28 +70,33 @@ Issues = "https://github.com/lukasberbuer/conan-check-updates/issues" line-length = 100 -[tool.isort] -profile = "black" - - -[tool.pylint.format] -max-line-length = 100 - -[tool.pylint.message_control] -good-names=[ - "e", "i", "j", "n", "r", "v", "it" +[tool.ruff] +line-length = 100 +select = [ + "F", # pyflakes + "E", "W", # pycodestyle + "I", # isort + "N", # pep8 naming + "B", # flake8 bugbear + "A", # flake8 builtins + "C4", # flake8 comprehensions + "G", # flake8 logging format + "PIE", # flake8 pie + "RET", # flake8 return + "SIM", # flake8 simplify + "PT", # flake8 pytest style + "PL", # pylint + "RUF", # ruff specific rules ] -disable = [ - "import-error", - "missing-module-docstring", - "missing-class-docstring", - "missing-function-docstring", - "too-few-public-methods", - "too-many-arguments", +ignore = [ + "PLR0911", # too many return statements ] -[tool.pylint.similarities] -min-similarity-lines = 6 +[tool.ruff.per-file-ignores] +"tests/*" = [ + "PLR0913", # too many arguments + "PLR2004", # magic value +] [tool.mypy] @@ -119,8 +124,7 @@ legacy_tox_ini = """ [tox] envlist = black - isort - pylint + ruff mypy py{37, 38, 39, 310, 311}-{v1, v2} coverage-report @@ -132,17 +136,11 @@ commands = black --diff . black --check . -[testenv:isort] +[testenv:ruff] skip_install = true -deps = isort +deps = ruff commands = - isort --diff . - isort --check-only . - -[testenv:pylint] -skip_install = true -deps = pylint -commands = pylint ./src/ + ruff check . [testenv:mypy] skip_install = true diff --git a/src/conan_check_updates/cli.py b/src/conan_check_updates/cli.py index c079443..c279eba 100644 --- a/src/conan_check_updates/cli.py +++ b/src/conan_check_updates/cli.py @@ -171,7 +171,7 @@ def highlighted_version_difference(version: VersionLike, compare: VersionLike) - version = str(version) compare = str(compare) i_first_diff = next( - (i for i, (s1, s2) in enumerate(zip(version, compare)) if s1 != s2), + (i for i, (s1, s2) in enumerate(zip(version, compare)) if s1 != s2), # noqa: B905 None, ) if i_first_diff is None: diff --git a/src/conan_check_updates/conan.py b/src/conan_check_updates/conan.py index 78d85ce..87631ea 100644 --- a/src/conan_check_updates/conan.py +++ b/src/conan_check_updates/conan.py @@ -181,7 +181,7 @@ def get_command(): if conan_version().major == 1: args = chain.from_iterable(("-a", attr) for attr in _REQUIRES_ATTRIBUTES) return ("conan", "inspect", str(conanfile), *args) - if conan_version().major == 2: + if conan_version().major == 2: # noqa: PLR2004 return ("conan", "inspect", str(conanfile)) raise RuntimeError(f"Conan version {str(conan_version())} not supported") @@ -257,7 +257,7 @@ async def search( def get_command(): if conan_version().major == 1: return ("conan", "search", pattern, "--remote", "all", "--raw") - if conan_version().major == 2: + if conan_version().major == 2: # noqa: PLR2004 return ("conan", "search", pattern) raise RuntimeError(f"Conan version {str(conan_version())} not supported") diff --git a/src/conan_check_updates/version.py b/src/conan_check_updates/version.py index 047a78b..5f0d374 100644 --- a/src/conan_check_updates/version.py +++ b/src/conan_check_updates/version.py @@ -125,7 +125,6 @@ def __eq__(self, other) -> bool: return self.astuple() == other.astuple() def __lt__(self, other) -> bool: - # pylint: disable=too-many-return-statements # semver precedence: https://semver.org/#spec-item-11 if isinstance(other, str): other = Version(other, loose=self._loose) diff --git a/tests/test_cli.py b/tests/test_cli.py index 3f1e5af..4a7cf53 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,7 +1,6 @@ from pathlib import Path import pytest - from conan_check_updates.cli import parse_args from conan_check_updates.version import VersionPart diff --git a/tests/test_color.py b/tests/test_color.py index ded5f89..0893a9b 100644 --- a/tests/test_color.py +++ b/tests/test_color.py @@ -1,5 +1,4 @@ import pytest - from conan_check_updates.color import AnsiCodes, colored diff --git a/tests/test_conan.py b/tests/test_conan.py index fed0a43..0d5ba1f 100644 --- a/tests/test_conan.py +++ b/tests/test_conan.py @@ -12,7 +12,6 @@ ... # skip tests for Python < 3.8 import pytest - from conan_check_updates.conan import ( ConanError, ConanReference, diff --git a/tests/test_conan_e2e.py b/tests/test_conan_e2e.py index 691fd03..3642464 100644 --- a/tests/test_conan_e2e.py +++ b/tests/test_conan_e2e.py @@ -3,8 +3,6 @@ from unittest.mock import patch import pytest -from test_conan import parse_requires_conanfile_json - from conan_check_updates.conan import ( ConanReference, conan_version, @@ -12,6 +10,7 @@ search_versions_parallel, ) from conan_check_updates.version import Version +from test_conan import parse_requires_conanfile_json HERE = Path(__file__).parent diff --git a/tests/test_filter.py b/tests/test_filter.py index 97b8c66..e92fd11 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,5 +1,4 @@ import pytest - from conan_check_updates.filter import matches_any diff --git a/tests/test_main.py b/tests/test_main.py index 7dcfc24..a4010db 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,7 +2,6 @@ from unittest.mock import Mock, call, patch import pytest - from conan_check_updates.conan import ConanReference, ConanSearchVersionsResult from conan_check_updates.main import CheckUpdateResult, check_updates, upgrade_conanfile from conan_check_updates.version import Version, VersionLike, VersionPart diff --git a/tests/test_version.py b/tests/test_version.py index cd31b6e..544b708 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -2,7 +2,6 @@ from typing import List, Optional import pytest - from conan_check_updates.version import ( Version, VersionError,