Skip to content

Commit

Permalink
use ruff instead of flake8 (#154)
Browse files Browse the repository at this point in the history
* use ruff instead of flake8

* correct comment

* remove complexity lint
  • Loading branch information
lucabello authored Apr 28, 2023
1 parent 2117f2c commit f8397e7
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 49 deletions.
27 changes: 10 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", "N818", "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]
Expand Down
2 changes: 1 addition & 1 deletion src/alertmanager_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _open(url: str, data: Optional[bytes], timeout: float) -> bytes:
response = urllib.request.urlopen(url, data, timeout)
if response.code == 200 and response.reason == "OK":
return response.read()
elif retry == 0:
if retry == 0:
raise AlertmanagerBadResponse(
f"Bad response (code={response.code}, reason={response.reason})"
)
Expand Down
3 changes: 1 addition & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from urllib.parse import urlparse

import yaml
from alertmanager_client import Alertmanager, AlertmanagerBadResponse
from charms.alertmanager_k8s.v0.alertmanager_dispatch import AlertmanagerProvider
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import (
RemoteConfigurationRequirer,
Expand Down Expand Up @@ -45,8 +46,6 @@
)
from ops.pebble import ChangeError, ExecError, Layer, PathError, ProtocolError

from alertmanager_client import Alertmanager, AlertmanagerBadResponse

logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_config_changed_modifies_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

import pytest
import yaml
from alertmanager_client import Alertmanager
from helpers import get_unit_address, is_alertmanager_up
from pytest_operator.plugin import OpsTest

from alertmanager_client import Alertmanager

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_external_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

import pytest
import yaml
from alertmanager_client import Alertmanager
from helpers import get_unit_address, is_alertmanager_up
from pytest_operator.plugin import OpsTest

from alertmanager_client import Alertmanager

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

import pytest
import yaml
from alertmanager_client import Alertmanager
from helpers import get_unit_address, is_alertmanager_up, uk8s_group
from pytest_operator.plugin import OpsTest

from alertmanager_client import Alertmanager

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

import pytest
import yaml
from alertmanager_client import Alertmanager
from helpers import get_unit_address, is_alertmanager_up
from pytest_operator.plugin import OpsTest
from werkzeug.wrappers import Request, Response

from alertmanager_client import Alertmanager

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import ops
import yaml
from charm import Alertmanager, AlertmanagerCharm
from helpers import FakeProcessVersionCheck, k8s_resource_multipatch, tautology
from ops import pebble
from ops.model import ActiveStatus, BlockedStatus, Container
from ops.testing import Harness

from charm import Alertmanager, AlertmanagerCharm

ops.testing.SIMULATE_CAN_CONNECT = True


Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_external_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

import ops
import yaml
from charm import Alertmanager, AlertmanagerCharm
from helpers import FakeProcessVersionCheck, cli_arg, k8s_resource_multipatch, tautology
from ops.model import ActiveStatus, BlockedStatus, Container
from ops.testing import Harness

from charm import Alertmanager, AlertmanagerCharm

logger = logging.getLogger(__name__)

ops.testing.SIMULATE_CAN_CONNECT = True
Expand Down Expand Up @@ -55,7 +54,7 @@ def get_cluster_args(self):
plan = self.harness.get_container_pebble_plan(CONTAINER_NAME).to_dict()
args = plan["services"][SERVICE_NAME]["command"].split()
cluster_args = filter(lambda s: s.startswith("--cluster.peer="), args)
cluster_args = sorted(map(lambda s: s.split("=")[1], cluster_args))
cluster_args = sorted((s.split("=")[1] for s in cluster_args))
return cluster_args

def is_service_running(self) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_push_config_to_workload_on_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import ops
import validators
import yaml
from charm import Alertmanager, AlertmanagerCharm
from helpers import FakeProcessVersionCheck, k8s_resource_multipatch, tautology
from hypothesis import given
from ops.model import ActiveStatus, BlockedStatus, Container
from ops.testing import Harness

from charm import Alertmanager, AlertmanagerCharm

logger = logging.getLogger(__name__)
ops.testing.SIMULATE_CAN_CONNECT = True
CONTAINER_NAME = "alertmanager"
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_remote_configuration_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from unittest.mock import Mock, PropertyMock, patch

import yaml
from charm import AlertmanagerCharm
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import (
DEFAULT_RELATION_NAME,
)
Expand All @@ -16,8 +17,6 @@
from ops import testing
from ops.model import BlockedStatus

from charm import AlertmanagerCharm

logger = logging.getLogger(__name__)

testing.SIMULATE_CAN_CONNECT = True
Expand Down
16 changes: 4 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,21 @@ 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 {[vars]lib_path}
codespell . --skip .git --skip .tox --skip build --skip lib --skip venv --skip .mypy_cache
# 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,lib,unit,integration}]
Expand Down

0 comments on commit f8397e7

Please sign in to comment.