Skip to content

Commit

Permalink
build(deps): use craft-application from main branch (#4573)
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Feb 14, 2024
1 parent cc5c6fa commit 1366eff
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 45 deletions.
4 changes: 2 additions & 2 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ click==8.1.7
codespell==2.2.6
colorama==0.4.6
coverage==7.4.0
craft-application==1.2.1
craft-application @ git+https://github.com/canonical/craft-application@main
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.2
craft-parts==1.26.1
craft-parts==1.26.2
craft-providers==1.22.0
craft-store==2.6.0
cryptography==41.0.7
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
craft-application==1.2.1
craft-application @ git+https://github.com/canonical/craft-application@main
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.2
craft-parts==1.26.1
craft-parts==1.26.2
craft-providers==1.22.0
craft-store==2.6.0
cryptography==41.0.7
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def recursive_data_files(directory, install_directory):
"attrs",
"catkin-pkg; sys_platform == 'linux'",
"click",
"craft-application",
"craft-application @ git+https://github.com/canonical/craft-application@main",
"craft-archives",
"craft-cli",
"craft-grammar",
Expand Down
75 changes: 55 additions & 20 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,70 @@
import pathlib
import signal
import sys
from typing import Any
from typing import Any, List, cast

import craft_application.commands as craft_app_commands
import craft_application.models
import craft_cli
from craft_application import Application, AppMetadata, util
from craft_application.models import BuildInfo
from craft_cli import emit
from craft_providers import bases
from overrides import override

from snapcraft import cli, errors, models, services
from snapcraft.commands import unimplemented
from snapcraft.models import Architecture
from snapcraft.providers import SNAPCRAFT_BASE_TO_PROVIDER_BASE
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], getattr(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[
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}",
build_on=build_on,
build_for=build_for,
base=bases.BaseName("ubuntu", base.value),
)
)

return build_plan


APP_METADATA = AppMetadata(
name="snapcraft",
summary="Package, distribute, and update snaps for Linux and IoT",
ProjectClass=models.Project,
BuildPlannerClass=SnapcraftBuildPlanner,
source_ignore_patterns=["*.snap"],
)

Expand Down Expand Up @@ -88,20 +137,6 @@ def _get_dispatcher(self) -> craft_cli.Dispatcher:
:returns: A ready-to-run Dispatcher object
"""
# pylint: disable=too-many-statements
# Set the logging level to DEBUG for all craft-libraries. This is OK even if
# the specific application doesn't use a specific library, the call does not
# import the package.
util.setup_loggers(*self._cli_loggers)

craft_cli.emit.init(
mode=craft_cli.EmitterMode.BRIEF,
appname=self.app.name,
greeting=f"Starting {self.app.name}",
log_filepath=self.log_path,
streaming_brief=True,
)

# Handle "multiplexing" of Snapcraft "codebases" depending on the
# project's base (if any). Here, we handle the case where there *is*
# a project and it's core24, which means it should definitely fall into
Expand Down Expand Up @@ -178,13 +213,13 @@ def _get_dispatcher(self) -> craft_cli.Dispatcher:

def main() -> int:
"""Run craft-application based snapcraft with classic fallback."""
util.setup_loggers(
"craft_parts", "craft_providers", "craft_store", "snapcraft.remote"
)

snapcraft_services = services.SnapcraftServiceFactory(app=APP_METADATA)

app = Snapcraft(app=APP_METADATA, services=snapcraft_services)
app = Snapcraft(
app=APP_METADATA,
services=snapcraft_services,
extra_loggers={"snapcraft.remote"},
)

app.add_command_group(
"Lifecycle",
Expand Down
19 changes: 2 additions & 17 deletions snapcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
import pydantic
from craft_application import models
from craft_application.models import BuildInfo, UniqueStrList
from craft_archives import repo
from craft_cli import emit
from craft_grammar.models import GrammarSingleEntryDictList, GrammarStr, GrammarStrList
from craft_providers import bases
from pydantic import PrivateAttr, constr

from snapcraft import parts, utils
from snapcraft import utils
from snapcraft.elf.elf_utils import get_arch_triplet
from snapcraft.errors import ProjectValidationError
from snapcraft.providers import SNAPCRAFT_BASE_TO_PROVIDER_BASE
Expand Down Expand Up @@ -432,7 +431,7 @@ class Project(models.Project):
grade: Optional[Literal["stable", "devel"]]
architectures: List[Union[str, Architecture]] = [get_host_architecture()]
assumes: UniqueStrList = cast(UniqueStrList, [])
package_repositories: List[Dict[str, Any]] = [] # handled by repo
package_repositories: Optional[List[Dict[str, Any]]]
hooks: Optional[Dict[str, Hook]]
passthrough: Optional[Dict[str, Any]]
apps: Optional[Dict[str, App]]
Expand Down Expand Up @@ -589,20 +588,6 @@ def _validate_build_base(cls, build_base, values):
build_base = values.get("base")
return build_base

@pydantic.validator("package_repositories", each_item=True)
@classmethod
def _validate_package_repositories(cls, item):
"""Ensure package-repositories format is correct."""
repo.validate_repository(item)
return item

@pydantic.validator("parts", each_item=True)
@classmethod
def _validate_parts(cls, item):
"""Verify each part (craft-parts will re-validate this)."""
parts.validate_part(item)
return item

@pydantic.validator("epoch")
@classmethod
def _validate_epoch(cls, epoch):
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/parts/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _run_command( # noqa PLR0913 # pylint: disable=too-many-branches, too-many-
base=project.get_effective_base(),
project_base=project.base or "",
confinement=project.confinement,
package_repositories=project.package_repositories,
package_repositories=project.package_repositories or [],
parallel_build_count=parallel_build_count,
part_names=part_names,
adopt_info=project.adopt_info,
Expand Down
2 changes: 1 addition & 1 deletion tests/spread/core24/patchelf/classic-python/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ execute: |
# Build the core24 snap
unset SNAPCRAFT_BUILD_ENVIRONMENT
# If this next line fails, delete it and replace it with the one following it
snapcraft --use-lxd 2>&1 | MATCH '"pack" command is not implemented for core24!'; exit 0
snapcraft --use-lxd 2>&1 | MATCH 'unrecognized arguments: --use-lxd'; exit 0
# snapcraft --use-lxd
# Install the new snap
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/models/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_project_defaults(self, project_yaml_data):
assert project.icon is None
assert project.layout is None
assert project.license is None
assert project.package_repositories == []
assert project.package_repositories is None
assert project.assumes == []
assert project.hooks is None
assert project.passthrough is None
Expand Down

0 comments on commit 1366eff

Please sign in to comment.