Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
use ruff instead of flake8 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabello authored Apr 28, 2023
1 parent 8c63a72 commit 3ba136a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
27 changes: 10 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,19 @@ asyncio_mode = "auto"
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,D104"]
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","D104"]}

[tool.ruff.pydocstyle]
convention = "google"

[tool.mypy]
pretty = true
Expand Down
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from ops.charm import CharmBase
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, Relation, Unit

from types_ import TraefikConfig, UnitConfig

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -259,7 +258,7 @@ def _is_ready(self):
if not ipu_relation:
self.unit.status = BlockedStatus("Awaiting to be related via ingress-per-unit.")
return False
elif not self.ingress_per_unit.is_ready(ipu_relation):
if not self.ingress_per_unit.is_ready(ipu_relation):
self.unit.status = BlockedStatus("ingress-per-unit relation is not ready.")
return False

Expand All @@ -286,6 +285,7 @@ def _on_ingress_data_provided(self, event: IngressDataReadyEvent):
)
self._update()
self.unit.status = ActiveStatus()
return None

def _config_for_unit(self, unit_data: RequirerData) -> RouteConfig:
"""Get the _RouteConfig for the provided `unit_data`."""
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import json

import pytest as pytest
from charm import TraefikRouteK8SCharm
from ops import framework, storage
from ops.testing import Harness

from charm import TraefikRouteK8SCharm

MODEL_NAME = "model"
REMOTE_APP_NAME = "remote" # the app requesting ingress
REMOTE_UNIT_NAME = f"{REMOTE_APP_NAME}/0" # the unit requesting ingress
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import pytest
import yaml
from charm import TraefikRouteK8SCharm
from charms.harness_extensions.v0.capture_events import capture
from charms.traefik_k8s.v1.ingress_per_unit import IngressDataReadyEvent
from ops.model import ActiveStatus, BlockedStatus
from ops.testing import Harness

from charm import TraefikRouteK8SCharm
from tests.unit.conftest import (
REMOTE_UNIT_NAME,
SAMPLE_INGRESS_DATA,
Expand Down
16 changes: 4 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,23 @@ 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==4.0.1
flake8-docstrings
flake8-copyright
flake8-builtins
pyproject-flake8
pep8-naming
isort
ruff
codespell
commands =
# uncomment the following line if this charm owns a lib
codespell {[vars]lib_path}
codespell . --skip .git --skip .tox --skip build --skip lib --skip venv* \
--skip .mypy_cache --skip icon.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,lib,unit,integration}]
Expand Down

0 comments on commit 3ba136a

Please sign in to comment.