Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanhphan1147 committed Dec 13, 2023
1 parent 72a100f commit cb85b2a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 54 deletions.
74 changes: 27 additions & 47 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ skips = ["*/*test.py", "*/test_*.py", "*tests/*.py"]
[tool.coverage.run]
branch = true

[tool.coverage.report]
fail_under = 99
show_missing = true

[tool.pytest.ini_options]
minversion = "6.0"
log_cli_level = "INFO"

[tool.pylint.'MESSAGES CONTROL']
extension-pkg-whitelist = "pydantic"

# Formatting tools configuration
[tool.black]
line-length = 99
target-version = ["py38"]
target-version = ["py310"]

[tool.coverage.report]
show_missing = true
[tool.isort]
line_length = 99
profile = "black"

# Linting tools configuration
[tool.flake8]
Expand All @@ -28,54 +40,22 @@ select = ["E", "W", "F", "C", "N", "R", "D", "H"]
# Ignore W503, E501 because using black creates errors with this
# Ignore D107 Missing docstring in __init__
ignore = ["W503", "E501", "D107"]
# D100, D101, D102, D103: Ignore missing docstrings in tests
per-file-ignores = ["tests/*:D100,D101,D102,D103,D104,D205,D212,D415"]
# In tests we can ignore
# D100, D101, D102, D103: missing docstrings
# D205, D212: docstring formatting (1 blank line required, multiline docstring summary)
per-file-ignores = ["tests/*:D100,D101,D102,D103,D104,D205,D212"]
docstring-convention = "google"

[tool.isort]
line_length = 99
profile = "black"
# 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"

[tool.mypy]
ignore_missing_imports = true
explicit_package_bases = true
check_untyped_defs = true
namespace_packages = true
disallow_untyped_defs = true
plugins = ["pydantic.mypy"]

[tool.pylint]
disable = "wrong-import-order"

[tool.pylint.'MESSAGES CONTROL']
extension-pkg-whitelist = "pydantic"

[tool.pytest.ini_options]
minversion = "6.0"
log_cli_level = "INFO"

# Linting tools configuration
[tool.ruff]
line-length = 99
select = ["E", "W", "F", "C", "N", "D", "I001"]
extend-ignore = [
"D203",
"D204",
"D213",
"D215",
"D400",
"D404",
"D406",
"D407",
"D408",
"D409",
"D413",
]
ignore = ["E501", "D107"]
extend-exclude = ["__pycache__", "*.egg_info"]
per-file-ignores = {"tests/*" = ["D100","D101","D102","D103","D104"]}

[tool.ruff.mccabe]
max-complexity = 10

[tool.codespell]
skip = "build,lib,venv,icon.svg,.tox,.git,.mypy_cache,.ruff_cache,.coverage"
[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _on_upgrade_charm(self, event: ops.UpgradeCharmEvent) -> None:
"""
self.reconcile(event)

def reconcile(self, _: ops.EventBase):
def reconcile(self, _: ops.EventBase) -> None:
"""Reconciliation for the jenkins agent charm."""
if not self.model.get_relation(AGENT_RELATION):
self.model.unit.status = ops.WaitingStatus("Waiting for relation.")
Expand Down
14 changes: 8 additions & 6 deletions src/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from charms.operator_libs_linux.v2 import snap

from charm_state import State
from charm_state import Credentials, State

logger = logging.getLogger(__name__)
SNAP_NAME = "jenkins-agent"
Expand Down Expand Up @@ -46,7 +46,7 @@ def is_active(self) -> bool:
service: dict = agent.services.get(SNAP_NAME)
return bool(service.get("active"))

def install(self):
def install(self) -> None:
"""Install and set up the snap.
Raises:
Expand All @@ -55,20 +55,22 @@ def install(self):
try:
cache = snap.SnapCache()
agent = cache[SNAP_NAME]

if not agent.present:
agent.ensure(snap.SnapState.Latest, classic=False, channel="latest/edge")
except snap.SnapError as exc:
raise SnapInstallError("Error installing the agent charm") from exc

def start(self):
def start(self) -> None:
"""Start the agent service."""
cache = snap.SnapCache()
agent = cache[SNAP_NAME]
credentials = self.state.agent_relation_credentials
if not credentials:
credentials = Credentials(address="", secret="")
agent.set(
{
"jenkins.token": self.state.agent_relation_credentials.secret,
"jenkins.url": self.state.agent_relation_credentials.address,
"jenkins.token": credentials.secret,
"jenkins.url": credentials.address,
"jenkins.agent": self.state.agent_meta.name,
}
)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ deps =
requests
types-PyYAML
types-requests
jenkinsapi>=0.3,<1
-r{toxinidir}/requirements.txt
commands =
pydocstyle {[vars]src_path}
Expand Down

0 comments on commit cb85b2a

Please sign in to comment.