Skip to content

Commit

Permalink
style: autoformat and lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Feb 13, 2024
1 parent fa20f50 commit 7936d72
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
16 changes: 13 additions & 3 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
from snapcraft.commands import unimplemented
from snapcraft.models import Architecture
from snapcraft.providers import SNAPCRAFT_BASE_TO_PROVIDER_BASE
from snapcraft.utils import get_host_architecture
from snapcraft.utils import get_effective_base, get_host_architecture


class SnapcraftBuildPlanner(craft_application.models.BuildPlanner):
"""A project model that creates build plans."""

def get_build_plan(self) -> List[BuildInfo]:
"""Get the build plan for this project."""
build_plan: List[BuildInfo] = []

architectures = cast(List[Architecture], self.architectures)
architectures = cast(List[Architecture], getattr(self, "architectures", []))

for arch in architectures:
# build_for will be a single element list
Expand All @@ -58,7 +59,16 @@ def get_build_plan(self) -> List[BuildInfo]:

# build on will be a list of archs
for build_on in arch.build_on:
base = SNAPCRAFT_BASE_TO_PROVIDER_BASE[self.get_effective_base()]
base = SNAPCRAFT_BASE_TO_PROVIDER_BASE[
str(
get_effective_base(
base=getattr(self, "base", None),
build_base=getattr(self, "build_base", None),
name=getattr(self, "name", None),
project_type=getattr(self, "type", None),
)
)
]
build_plan.append(
BuildInfo(
platform=f"ubuntu@{base.value}",
Expand Down
28 changes: 28 additions & 0 deletions snapcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,34 @@ def get_build_for_arch_triplet(self) -> Optional[str]:

return None

def get_build_plan(self) -> List[BuildInfo]:
"""Get the build plan for this project."""
build_plan: List[BuildInfo] = []

architectures = cast(List[Architecture], self.architectures)

for arch in architectures:
# build_for will be a single element list
build_for = cast(list, arch.build_for)[0]

# TODO: figure out when to filter `all`
if build_for == "all":
build_for = get_host_architecture()

# build on will be a list of archs
for build_on in arch.build_on:
base = SNAPCRAFT_BASE_TO_PROVIDER_BASE[self.get_effective_base()]
build_plan.append(
BuildInfo(
platform=f"ubuntu@{base.value}",
build_on=build_on,
build_for=build_for,
base=bases.BaseName("ubuntu", base.value),
)
)

return build_plan


class _GrammarAwareModel(pydantic.BaseModel):
class Config:
Expand Down

0 comments on commit 7936d72

Please sign in to comment.