diff --git a/pyproject.toml b/pyproject.toml index 0709c92..7297436 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -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 \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index c34c7c3..70bbef8 100755 --- a/src/charm.py +++ b/src/charm.py @@ -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.") diff --git a/src/service.py b/src/service.py index 671748d..7db74d9 100644 --- a/src/service.py +++ b/src/service.py @@ -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" @@ -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: @@ -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, } ) diff --git a/tox.ini b/tox.ini index ea2fca3..d138ba6 100644 --- a/tox.ini +++ b/tox.ini @@ -54,6 +54,7 @@ deps = requests types-PyYAML types-requests + jenkinsapi>=0.3,<1 -r{toxinidir}/requirements.txt commands = pydocstyle {[vars]src_path}