diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 14a64fb..9dde2e5 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -16,10 +16,10 @@ jobs: with: fail-on-error: "true" - lint-unit: - name: Lint Unit + lint-unit-uv: + name: Lint / Unit Tests uses: charmed-kubernetes/workflows/.github/workflows/lint-unit.yaml@main with: - python: "['3.8', '3.9', '3.10', '3.11']" + with-uv: true needs: - call-inclusive-naming-check diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 65e1721..0000000 --- a/mypy.ini +++ /dev/null @@ -1,11 +0,0 @@ -[mypy] -warn_unused_ignores = True -warn_unused_configs = True -warn_unreachable = True -disallow_untyped_defs = True -; Due to python 3.5 support we can't enforce variable type annotations -disable_error_code = var-annotated - -# Ignore unsupported imports -[mypy-charms.*] -ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4080ffe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,82 @@ +[lint] +ignore = ["E501", "D107"] +extend-ignore = [ + "D203", + "D204", + "D213", + "D215", + "D400", + "D404", + "D406", + "D407", + "D408", + "D409", + "D413", +] +per-file-ignores = {"tests/*" = ["D100","D101","D102","D103","D104"]} + +[lint.mccabe] +max-complexity = 10 + + + +# Testing tools configuration +[tool.coverage.run] +branch = true + +# Formatting tools configuration +[tool.black] +line-length = 99 +target-version = ["py38"] + +[tool.coverage.report] +show_missing = true + + +[tool.isort] +line_length=99 +multi_line_output=3 +include_trailing_comma = true +use_parentheses = true + +[tool.mypy] +warn_unused_ignores = true +warn_unused_configs = true +warn_unreachable = true +disallow_untyped_defs = true +# Due to python 3.5 support we can't enforce variable type annotations +disable_error_code = "var-annotated" + +[[tool.mypy.overrides]] +module = "charms.*" +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "lightkube.*" +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "ops.*" +ignore_missing_imports = true + +[tool.pytest.ini_options] +minversion = "6.0" + +# Linting tools configuration +[tool.ruff] +# line-length = 99 +# select = ["E", "W", "F", "C", "N", "D", "I001"] +extend-exclude = ["__pycache__", "*.egg_info"] + +[tool.codespell] +skip = "build,lib,venv,icon.svg,.tox,.git,.mypy_cache,.ruff_cache,.coverage" + +[tool.pyright] +extraPaths = ["./lib"] + +[project] +name = "ceph-csi" +dynamic = ["version"] +dependencies = [ + "tox-uv" +] \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index 4230a71..4f3dede 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,3 +8,4 @@ tox isort black types-PyYAML +uv diff --git a/requirements-test.txt b/requirements-test.txt index 493e1a5..fb97a91 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -2,3 +2,4 @@ coverage pytest pytest-operator +uv \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index 963d96b..0a381ea 100755 --- a/src/charm.py +++ b/src/charm.py @@ -303,7 +303,7 @@ def check_kube_config(self) -> None: def check_namespace(self) -> None: self.unit.status = ops.MaintenanceStatus("Evaluating namespace") try: - self._client.get(Namespace, name=self.stored.namespace) # type: ignore + self._client.get(Namespace, name=self.stored.namespace) except ApiError as e: if "not found" in str(e.status.message): status.add(ops.BlockedStatus(f"Missing namespace '{self.stored.namespace}'")) diff --git a/tox.ini b/tox.ini index 9144a04..80e23a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] skipsdist=True envlist = lint, unit -requires = - pip >= 20.3 +; requires = +; pip >= 20.3 [vars] cov_path = {toxinidir}/htmlcov @@ -24,18 +24,18 @@ deps = -r{toxinidir}/requirements-dev.txt [testenv:lint] basepython = python3 commands = - codespell {[vars]all_path} - ruff check {[vars]all_path} - isort --check-only --diff {[vars]all_path} - black -l 99 --check --diff {[vars]all_path} - mypy --namespace-packages {[vars]src_path} + uvx codespell {[vars]all_path} + uvx ruff check {[vars]all_path} + uvx isort --check-only --diff {[vars]all_path} + uvx black -l 99 --check --diff {[vars]all_path} + uvx mypy --namespace-packages {[vars]src_path} [testenv:unit] basepython = python3 deps = -r{toxinidir}/requirements-test.txt commands = - coverage run --source={toxinidir}/src -m pytest {toxinidir}/tests/unit/ {posargs} - coverage report -m --fail-under=97 + uv run coverage run --source={toxinidir}/src -m pytest {toxinidir}/tests/unit/ {posargs} + uv run coverage report -m --fail-under=97 [testenv:integration] basepython = python3 @@ -45,16 +45,17 @@ passenv = TEST_HTTPS_PROXY deps = -r{toxinidir}/requirements-test.txt commands = - pytest --log-cli-level=INFO \ + uv run pytest --log-cli-level=INFO \ + --asyncio-mode=auto \ {posargs} \ {toxinidir}/tests/functional/ [testenv:format] basepython = python3 commands = - isort {[vars]all_path} - black -l 99 {[vars]all_path} - ruff check --fix {[vars]all_path} + uvx isort {[vars]all_path} + uvx black -l 99 {[vars]all_path} + uvx ruff check --fix {[vars]all_path} [testenv:update] deps = @@ -64,12 +65,6 @@ commands = python {toxinidir}/upstream/update.py {posargs} -[isort] -line_length=99 -multi_line_output=3 -include_trailing_comma=True -use_parentheses=True - [coverage:report] exclude_lines = pragma: no cover