Skip to content

Commit

Permalink
style: fix linting issues in main code
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Dec 12, 2024
1 parent 310be71 commit ed1bf9c
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 40 deletions.
8 changes: 5 additions & 3 deletions craft_application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion craft_application/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion craft_application/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion craft_application/launchpad/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions craft_application/launchpad/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion craft_application/launchpad/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions craft_application/launchpad/models/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions craft_application/launchpad/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions craft_application/launchpad/models/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion craft_application/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion craft_application/remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions craft_application/remote/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions craft_application/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion craft_application/services/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions craft_application/services/remotebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
7 changes: 2 additions & 5 deletions craft_application/services/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ed1bf9c

Please sign in to comment.