From 3e189227ea982f9cf48b617a3860c7e2897be948 Mon Sep 17 00:00:00 2001 From: Luca Bello <36242061+lucabello@users.noreply.github.com> Date: Fri, 28 Apr 2023 16:33:32 +0200 Subject: [PATCH] use ruff instead of flake8 (#30) * use ruff instead of flake8 * remove complexity lint --- pyproject.toml | 27 ++++++++++----------------- src/charm.py | 6 +++--- tests/unit/test_charm.py | 3 +-- tox.ini | 17 ++++------------- 4 files changed, 18 insertions(+), 35 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 45b03d3..63e7a2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,26 +13,19 @@ show_missing = true line-length = 99 target-version = ["py38"] -[tool.isort] -profile = "black" - # Linting tools configuration -[tool.flake8] -max-line-length = 99 -max-doc-length = 99 -max-complexity = 10 -exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"] -select = ["E", "W", "F", "C", "N", "R", "D", "H"] -# Ignore W503, E501 because using black creates errors with this +[tool.ruff] +line-length = 99 +extend-exclude = ["__pycache__", "*.egg_info"] +select = ["E", "W", "F", "C", "N", "R", "D", "I001"] +# Ignore E501 because using black creates errors with this # Ignore D107 Missing docstring in __init__ -ignore = ["W503", "E501", "D107"] +ignore = ["E501", "D107", "RET504"] # D100, D101, D102, D103: Ignore missing docstrings in tests -per-file-ignores = ["tests/*:D100,D101,D102,D103"] -docstring-convention = "google" -# Check for properly formatted copyright header in each file -copyright-check = "True" -copyright-author = "Canonical Ltd." -copyright-regexp = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+%(author)s" +per-file-ignores = {"tests/*" = ["D100","D101","D102","D103"]} + +[tool.ruff.pydocstyle] +convention = "google" # Static analysis tools configuration [tool.mypy] diff --git a/src/charm.py b/src/charm.py index 7074471..06e51df 100755 --- a/src/charm.py +++ b/src/charm.py @@ -90,7 +90,7 @@ def _on_install(self, _) -> None: def _has_metrics_providers(self): """Are any metrics providers available. - Returns + Returns: ------- True if at least one metrics provider is related to this charm, False otherwise. @@ -103,7 +103,7 @@ def _has_metrics_providers(self): def _has_metrics_consumers(self): """Are any metrics consumers available. - Returns + Returns: ------- True if at least one metrics consumer is related to this charm, False otherwise. @@ -196,7 +196,7 @@ def _prometheus_configurations(self): charm. The scrape jobs (including associated alert rules) are returned. - Returns + Returns: ------- A dictionary with keys "scrape_jobs" and "alert_rules". """ diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index c8927a8..e97809a 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -7,12 +7,11 @@ import typing import unittest +from charm import PrometheusScrapeConfigCharm from charms.observability_libs.v0.juju_topology import JujuTopology from ops.model import ActiveStatus, BlockedStatus, WaitingStatus from ops.testing import Harness -from charm import PrometheusScrapeConfigCharm - class TestCharm(unittest.TestCase): @classmethod diff --git a/tox.ini b/tox.ini index e278f43..406cd28 100644 --- a/tox.ini +++ b/tox.ini @@ -29,29 +29,20 @@ passenv = description = Apply coding style standards to code deps = black - isort + ruff commands = - isort {[vars]all_path} + ruff --fix {[vars]all_path} black {[vars]all_path} [testenv:lint] description = Check code against coding style standards deps = black - flake8 < 5 - flake8-docstrings - flake8-copyright - flake8-builtins - pyproject-flake8 - pep8-naming - isort + ruff codespell commands = codespell . --skip .git --skip .tox --skip build --skip lib --skip venv --skip .mypy_cache --skip *.svg - - # pflake8 wrapper supports config from pyproject.toml - pflake8 {[vars]all_path} - isort --check-only --diff {[vars]all_path} + ruff {[vars]all_path} black --check --diff {[vars]all_path} [testenv:static-charm]