From ed1bf9c5abdd2128b7c3214c091ae584a33bb290 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Wed, 11 Dec 2024 23:22:44 -0500 Subject: [PATCH] style: fix linting issues in main code --- craft_application/application.py | 8 +++++--- craft_application/fetch.py | 2 +- craft_application/grammar.py | 2 +- craft_application/launchpad/models/__init__.py | 2 +- craft_application/launchpad/models/base.py | 4 ++-- craft_application/launchpad/models/build.py | 3 ++- craft_application/launchpad/models/code.py | 5 +++-- craft_application/launchpad/models/project.py | 8 ++++---- craft_application/launchpad/models/recipe.py | 7 ++++--- craft_application/models/project.py | 2 +- craft_application/remote/__init__.py | 2 +- craft_application/remote/utils.py | 7 +++---- craft_application/services/config.py | 4 ++-- craft_application/services/init.py | 5 ++++- craft_application/services/remotebuild.py | 13 +++++-------- craft_application/services/request.py | 7 ++----- 16 files changed, 41 insertions(+), 40 deletions(-) diff --git a/craft_application/application.py b/craft_application/application.py index d415e650..db76d1a6 100644 --- a/craft_application/application.py +++ b/craft_application/application.py @@ -246,9 +246,11 @@ def _merge_defaults( merged_commands.append(default_command) # append remaining commands from the application - for app_command in app_commands.commands: - if app_command.name not in processed_command_names: - merged_commands.append(app_command) + merged_commands.extend( + app_command + for app_command in app_commands.commands + if app_command.name not in processed_command_names + ) return craft_cli.CommandGroup( name=default_commands.name, diff --git a/craft_application/fetch.py b/craft_application/fetch.py index c37fcfac..e2819650 100644 --- a/craft_application/fetch.py +++ b/craft_application/fetch.py @@ -427,7 +427,7 @@ def _obtain_certificate() -> tuple[pathlib.Path, pathlib.Path]: if cert.is_file() and key.is_file(): # Certificate and key already generated - # TODO check that the certificate hasn't expired + # TODO check that the certificate hasn't expired # noqa: FIX002 return cert, key # At least one is missing, regenerate both diff --git a/craft_application/grammar.py b/craft_application/grammar.py index bdd0d7c7..3b5f07ef 100644 --- a/craft_application/grammar.py +++ b/craft_application/grammar.py @@ -116,7 +116,7 @@ def self_check(value: Any) -> bool: # noqa: ANN401 value == value # pylint: disable=comparison-with-itself # noqa: PLR0124 ) - # TODO: make checker optional in craft-grammar. + # TODO: make checker optional in craft-grammar. # noqa: FIX002 processor = GrammarProcessor(arch=arch, target_arch=target_arch, checker=self_check) for part_name, part_data in parts_yaml_data.items(): diff --git a/craft_application/launchpad/models/__init__.py b/craft_application/launchpad/models/__init__.py index 772bf80c..0094feb6 100644 --- a/craft_application/launchpad/models/__init__.py +++ b/craft_application/launchpad/models/__init__.py @@ -2,7 +2,7 @@ from .base import LaunchpadObject, InformationType -from ..util import Architecture +from craft_application.launchpad.util import Architecture from .build import BuildTypes, BuildState, Build from .code import GitRepository from .distro import DistroSeries diff --git a/craft_application/launchpad/models/base.py b/craft_application/launchpad/models/base.py index e63945d3..8f9104b8 100644 --- a/craft_application/launchpad/models/base.py +++ b/craft_application/launchpad/models/base.py @@ -36,10 +36,10 @@ from lazr.restfulclient.resource import Entry # type: ignore[import-untyped] from typing_extensions import Any -from .. import errors, util +from craft_application.launchpad import errors, util if TYPE_CHECKING: - from ..launchpad import Launchpad + from craft_application.launchpad import Launchpad class InformationType(enum.Enum): diff --git a/craft_application/launchpad/models/build.py b/craft_application/launchpad/models/build.py index 9eee7b7f..a8d045aa 100644 --- a/craft_application/launchpad/models/build.py +++ b/craft_application/launchpad/models/build.py @@ -31,7 +31,8 @@ import lazr.restfulclient.errors # type: ignore[import-untyped] from typing_extensions import Self -from .. import errors, util +from craft_application.launchpad import errors, util + from . import distro from .base import LaunchpadObject diff --git a/craft_application/launchpad/models/code.py b/craft_application/launchpad/models/code.py index c903a253..53595ec3 100644 --- a/craft_application/launchpad/models/code.py +++ b/craft_application/launchpad/models/code.py @@ -36,11 +36,12 @@ from typing_extensions import Self -from .. import errors +from craft_application.launchpad import errors + from .base import InformationType, LaunchpadObject if TYPE_CHECKING: - from ..launchpad import Launchpad + from craft_application.launchpad import Launchpad class _BaseRepository(LaunchpadObject, metaclass=ABCMeta): diff --git a/craft_application/launchpad/models/project.py b/craft_application/launchpad/models/project.py index cac18741..40615986 100644 --- a/craft_application/launchpad/models/project.py +++ b/craft_application/launchpad/models/project.py @@ -38,12 +38,12 @@ from typing_extensions import Self, Any from typing import TYPE_CHECKING -from ..models.base import InformationType, LaunchpadObject -from .. import errors -from ...util import retry +from craft_application.launchpad.models.base import InformationType, LaunchpadObject +from craft_application.launchpad import errors +from craft_application.util import retry if TYPE_CHECKING: - from .. import Launchpad + from craft_application.launchpad import Launchpad class ProjectType(enum.Enum): diff --git a/craft_application/launchpad/models/recipe.py b/craft_application/launchpad/models/recipe.py index 7e3f70b0..dd6b6e9e 100644 --- a/craft_application/launchpad/models/recipe.py +++ b/craft_application/launchpad/models/recipe.py @@ -37,13 +37,14 @@ import lazr.restfulclient.errors # type: ignore[import-untyped] from typing_extensions import Any, Self, TypedDict, override -from ...util import retry -from .. import errors, util +from craft_application.launchpad import errors, util +from craft_application.util import retry + from . import build from .base import LaunchpadObject, Pocket if TYPE_CHECKING: - from .. import Launchpad + from craft_application.launchpad import Launchpad class RecipeType(enum.Enum): diff --git a/craft_application/models/project.py b/craft_application/models/project.py index b7b92286..4ad2072f 100644 --- a/craft_application/models/project.py +++ b/craft_application/models/project.py @@ -60,7 +60,7 @@ class DevelBaseInfo: # A list of DevelBaseInfo objects that define an OS's current devel base and devel base. DEVEL_BASE_INFOS = [ DevelBaseInfo( - # TODO: current_devel_base should point to 24.10, which is not available yet + # current_devel_base should point to 25.04, which is not available yet current_devel_base=craft_providers.bases.ubuntu.BuilddBaseAlias.DEVEL, devel_base=craft_providers.bases.ubuntu.BuilddBaseAlias.DEVEL, ), diff --git a/craft_application/remote/__init__.py b/craft_application/remote/__init__.py index 13b9bf3a..1c470ceb 100644 --- a/craft_application/remote/__init__.py +++ b/craft_application/remote/__init__.py @@ -14,7 +14,7 @@ """Remote-build and related utilities.""" -# TODO: below import should be removed in next incompatible release +# Git imports should be removed in next incompatible release from craft_application.git import GitRepo, GitError, GitType, get_git_repo_type, is_repo from .errors import ( RemoteBuildError, diff --git a/craft_application/remote/utils.py b/craft_application/remote/utils.py index 30fa66b8..8378457d 100644 --- a/craft_application/remote/utils.py +++ b/craft_application/remote/utils.py @@ -36,10 +36,9 @@ def validate_architectures(architectures: list[str]) -> None: :raises UnsupportedArchitectureError: if any architecture in the list in not supported for remote building. """ - unsupported_archs: list[str] = [] - for arch in architectures: - if arch not in _SUPPORTED_ARCHS: - unsupported_archs.append(arch) + unsupported_archs: list[str] = [ + arch for arch in architectures if arch not in _SUPPORTED_ARCHS + ] if unsupported_archs: raise UnsupportedArchitectureError(architectures=unsupported_archs) diff --git a/craft_application/services/config.py b/craft_application/services/config.py index 6b8c4e48..cbddb738 100644 --- a/craft_application/services/config.py +++ b/craft_application/services/config.py @@ -135,7 +135,7 @@ def get_raw(self, item: str) -> Any: self._cache[item] = field.default return field.default if field.default_factory is not None: - # TODO: remove the type ignore after pydantic/pydantic#10945 is fixed + # Remove the type ignore after pydantic/pydantic#10945 is fixed default = field.default_factory() # type: ignore[call-arg] self._cache[item] = default return default @@ -185,7 +185,7 @@ def get(self, item: str) -> Any: # noqa: ANN401 for handler in self._handlers: try: value = handler.get_raw(item) - except KeyError: + except KeyError: # noqa: PERF203 continue else: break diff --git a/craft_application/services/init.py b/craft_application/services/init.py index dfdd5eae..02e50be9 100644 --- a/craft_application/services/init.py +++ b/craft_application/services/init.py @@ -29,8 +29,11 @@ from craft_application.errors import InitError from craft_application.git import GitError, GitRepo, is_repo, parse_describe +from craft_application.models.constraints import ( + MESSAGE_INVALID_NAME, + PROJECT_NAME_COMPILED_REGEX, +) -from ..models.constraints import MESSAGE_INVALID_NAME, PROJECT_NAME_COMPILED_REGEX from . import base if typing.TYPE_CHECKING: # pragma: no cover diff --git a/craft_application/services/remotebuild.py b/craft_application/services/remotebuild.py index 48f33ef9..096ce911 100644 --- a/craft_application/services/remotebuild.py +++ b/craft_application/services/remotebuild.py @@ -210,18 +210,15 @@ def cancel_builds(self) -> None: raise RuntimeError( "RemoteBuildService must be set up using start_builds or resume_builds before cancelling builds." ) - cancel_failed = [] + cancel_failed: list[str] = [] for build in self._builds: try: build.cancel() - except launchpad.errors.BuildError as exc: - cancel_failed.append( # pyright: ignore[reportUnknownMemberType] - exc.args[0] - ) + # We have to try-except in a loop here. + except launchpad.errors.BuildError as exc: # noqa: PERF203 + cancel_failed.append(exc.args[0]) if cancel_failed: - raise errors.CancelFailedError( - cancel_failed # pyright: ignore[reportUnknownArgumentType] - ) + raise errors.CancelFailedError(cancel_failed) def cleanup(self) -> None: """Clean up the recipe and repository.""" diff --git a/craft_application/services/request.py b/craft_application/services/request.py index 75fee724..0cce18b1 100644 --- a/craft_application/services/request.py +++ b/craft_application/services/request.py @@ -104,11 +104,8 @@ def download_files_with_progress( with craft_cli.emit.progress_bar(title, total_size) as progress: while downloads: for dl in downloads.copy(): - try: - chunk_size = next(dl) - except StopIteration: - downloads.remove(dl) - else: + for chunk_size in dl: progress.advance(chunk_size) + downloads.remove(dl) return files