diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4a6439b..8db49ca3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ Example: ```bash $ python3 -m venv venv $ source venv/bin/activate -$ pip install -r requirements.txt +$ pip install -r requirements_dev.txt ``` diff --git a/flux_local/command.py b/flux_local/command.py index 15652014..7084fbdc 100644 --- a/flux_local/command.py +++ b/flux_local/command.py @@ -109,7 +109,9 @@ async def _run_piped_with_sem(cmds: Sequence[Task]) -> str: try: out = await asyncio.wait_for(cmd.run(stdin), _TIMEOUT) except asyncio.exceptions.TimeoutError as err: - raise cmd.exc(f"Command '{cmd}' timed out") from err + if isinstance(cmd, Command): + raise cmd.exc(f"Command '{cmd}' timed out") from err + raise err stdin = out return out.decode("utf-8") if out else "" diff --git a/flux_local/git_repo.py b/flux_local/git_repo.py index 434fc089..a3a70784 100644 --- a/flux_local/git_repo.py +++ b/flux_local/git_repo.py @@ -633,7 +633,9 @@ async def build_kustomization( ] -def _ready_kustomizations(kustomizations: list[Kustomization], visited: set[str]) -> tuple[Kustomization, Kustomization]: +def _ready_kustomizations( + kustomizations: list[Kustomization], visited: set[str] +) -> tuple[list[Kustomization], list[Kustomization]]: """Split the kustomizations into those that are ready vs pending.""" ready = [] pending = [] @@ -690,7 +692,11 @@ async def update_kustomization(cluster: Cluster) -> None: build_tasks = [] (ready, pending) = _ready_kustomizations(queue, visited) for kustomization in ready: - _LOGGER.debug("Processing kustomization '%s': %s", kustomization.name, kustomization.path) + _LOGGER.debug( + "Processing kustomization '%s': %s", + kustomization.name, + kustomization.path, + ) if kustomization.postbuild_substitute_from: values.expand_postbuild_substitute_reference( @@ -772,7 +778,9 @@ async def update_kustomization(cluster: Cluster) -> None: @contextlib.contextmanager -def create_worktree(repo: git.repo.Repo, existing_branch: str | None = None) -> Generator[Path, None, None]: +def create_worktree( + repo: git.repo.Repo, existing_branch: str | None = None +) -> Generator[Path, None, None]: """Create a ContextManager for a new git worktree in the current repo. This is used to get a fork of the current repo without any local changes diff --git a/flux_local/helm.py b/flux_local/helm.py index 80b00e06..180d1dca 100644 --- a/flux_local/helm.py +++ b/flux_local/helm.py @@ -50,7 +50,7 @@ SECRET_KIND, REPO_TYPE_OCI, HELM_REPOSITORY, - GIT_REPOSITORY + GIT_REPOSITORY, ) from .exceptions import HelmException @@ -68,7 +68,7 @@ def _chart_name(release: HelmRelease, repo: HelmRepository | None) -> str: """Return the helm chart name used for the helm template command.""" if release.chart.repo_kind == HELM_REPOSITORY: - if repo.repo_type == REPO_TYPE_OCI: + if repo and repo.repo_type == REPO_TYPE_OCI: return f"{repo.url}/{release.chart.name}" return release.chart.chart_name elif release.chart.repo_kind == GIT_REPOSITORY: @@ -79,7 +79,6 @@ def _chart_name(release: HelmRelease, repo: HelmRepository | None) -> str: ) - class RepositoryConfig: """Generates a helm repository configuration from flux HelmRepository objects.""" diff --git a/flux_local/kustomize.py b/flux_local/kustomize.py index eaeb0f9d..f3fba196 100644 --- a/flux_local/kustomize.py +++ b/flux_local/kustomize.py @@ -37,6 +37,7 @@ from aiofiles.ospath import isdir import asyncio from contextlib import asynccontextmanager +from collections.abc import AsyncIterator import logging from pathlib import Path import tempfile @@ -70,6 +71,7 @@ # Used to limit access to specific resources _LOCK_MAP: dict[str, asyncio.Lock] = {} + class Kustomize: """Library for issuing a kustomize command.""" @@ -194,9 +196,9 @@ async def run(self, stdin: bytes | None = None) -> bytes: @asynccontextmanager -async def _resource_lock(key: str): +async def _resource_lock(key: str) -> AsyncIterator[None]: """Run while holding a lock for the specified resource. - + This is not threadsafe and expected to be run in the asyncio loop. """ if not (lock := _LOCK_MAP.get(key)): diff --git a/flux_local/manifest.py b/flux_local/manifest.py index cf3efd2c..1bef480c 100644 --- a/flux_local/manifest.py +++ b/flux_local/manifest.py @@ -82,7 +82,7 @@ def parse_yaml(cls, content: str) -> "BaseManifest": def yaml(self, exclude: dict[str, Any] | None = None) -> str: """Return a YAML string representation of compact_dict.""" - return yaml_encode(self, self.__class__) + return yaml_encode(self, self.__class__) # type: ignore[return-value] class Config(BaseConfig): omit_none = True diff --git a/pyproject.toml b/pyproject.toml index fdbf6fa1..8d2b4a41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,14 +14,6 @@ warn_unused_configs = true warn_unused_ignores = true disable_error_code = [ "import-untyped", - # TODO: Fix these warnings - "assignment", - "attr-defined", - "return-value", - "no-untyped-def", - "union-attr", - "assignment", - "arg-type", ] extra_checks = false check_untyped_defs = true diff --git a/script/run-mypy.sh b/script/run-mypy.sh index fc3804b4..eede4d73 100755 --- a/script/run-mypy.sh +++ b/script/run-mypy.sh @@ -2,9 +2,11 @@ set -o errexit -# Change directory to the project root directory. -cd "$(dirname "$0")" +# other common virtualenvs +my_path=$(git rev-parse --show-toplevel) -pip3 install -r requirements_dev.txt --no-input --quiet +if [ -f "${my_path}/venv/bin/activate" ]; then + . "${my_path}/venv/bin/activate" +fi -mypy . +mypy ${my_path} diff --git a/tests/test_command.py b/tests/test_command.py index 2ae75afd..64cae890 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -2,7 +2,8 @@ import pytest -from flux_local.command import Command, CommandException, run, run_piped +from flux_local.command import Command, run, run_piped +from flux_local.exceptions import CommandException async def test_command() -> None: diff --git a/tests/test_git_repo.py b/tests/test_git_repo.py index ee0128f1..71135d53 100644 --- a/tests/test_git_repo.py +++ b/tests/test_git_repo.py @@ -85,7 +85,7 @@ async def test_kustomization_visitor(snapshot: SnapshotAssertion) -> None: query.path.path = TESTDATA stream = io.StringIO() - visits: list[tuple[str, str, str, str]] = [] + visits: list[tuple[str, str, str]] = [] async def write(x: Path, y: Any, cmd: Kustomize | None) -> None: visits.append((str(x), y.namespace, y.name)) @@ -112,7 +112,7 @@ async def test_helm_repo_visitor(snapshot: SnapshotAssertion) -> None: query = ResourceSelector() query.path.path = TESTDATA - visits: list[tuple[str, str, str, str]] = [] + visits: list[tuple[str, str, str]] = [] async def append(x: Path, y: Any, z: Any) -> None: visits.append((str(x), y.namespace, y.name)) @@ -132,7 +132,7 @@ async def test_helm_release_visitor(snapshot: SnapshotAssertion) -> None: query = ResourceSelector() query.path.path = TESTDATA - visits: list[tuple[str, str, str, str]] = [] + visits: list[tuple[str, str, str]] = [] async def append(x: Path, y: Any, z: Any) -> None: visits.append((str(x), y.namespace, y.name))