Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update to craft-application latest #4659

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
attrs==23.1.0
catkin-pkg==0.5.2
click==8.1.7
craft-application @ git+https://github.com/canonical/craft-application@main
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.1
Expand Down
5 changes: 2 additions & 3 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ def __init__(self, *args, **kwargs):
os.environ[craft_var] = env_val

@override
def _configure_services(self, platform: str | None, build_for: str | None) -> None:
def _configure_services(self, provider_name: str | None) -> None:
self.services.set_kwargs(
"package",
platform=platform,
build_plan=self._build_plan,
snapcraft_yaml_path=self._snapcraft_yaml_path,
)

super()._configure_services(platform, build_for)
super()._configure_services(provider_name)

@property
def command_groups(self):
Expand Down
11 changes: 11 additions & 0 deletions snapcraft/commands/unimplemented.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
"""Overridden to always return False, for now."""
return False

def provider_name(
self,
parsed_args: argparse.Namespace, # noqa: ARG002 (the unused argument is for subclasses)
) -> str | None:
"""Name of the provider where the command should be run inside of.

By default returns None. Subclasses can override this method to change this,
including by inspecting the arguments in `parsed_args`.
"""
return None

Check warning on line 63 in snapcraft/commands/unimplemented.py

View check run for this annotation

Codecov / codecov/patch

snapcraft/commands/unimplemented.py#L63

Added line #L63 was not covered by tests

always_load_project: bool = False


Expand Down
14 changes: 8 additions & 6 deletions snapcraft/services/package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2023 Canonical Ltd.
# Copyright 2023-2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
Expand Down Expand Up @@ -50,13 +50,13 @@ def __init__( # noqa: PLR0913 (Too many arguments)
*,
project: models.Project,
snapcraft_yaml_path: pathlib.Path,
platform: str | None,
build_plan: list[BuildInfo],
) -> None:
super().__init__(app, services, project=project)
self._platform = platform
self._build_for = build_plan[0].build_for
self._snapcraft_yaml_path = snapcraft_yaml_path
self._build_plan = build_plan
self._platform = build_plan[0].platform
self._build_for = build_plan[0].build_for

@override
def pack(self, prime_dir: pathlib.Path, dest: pathlib.Path) -> list[pathlib.Path]:
Expand All @@ -81,7 +81,7 @@ def pack(self, prime_dir: pathlib.Path, dest: pathlib.Path) -> list[pathlib.Path
compression=self._project.compression,
name=self._project.name,
version=process_version(self._project.version),
target_arch=self._build_for,
target_arch=self._build_plan[0].build_for,
)
)
]
Expand Down Expand Up @@ -137,7 +137,9 @@ def write_metadata(self, path: pathlib.Path) -> None:
def metadata(self) -> snap_yaml.SnapMetadata:
"""Get the metadata model for this project."""
return snap_yaml.get_metadata_from_project(
self._project, self._services.lifecycle.prime_dir, arch=self._build_for
self._project,
self._services.lifecycle.prime_dir,
arch=self._build_plan[0].build_for,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ execute: |
export SNAPCRAFT_IMAGE_INFO='{"test-var": "value"}'

# If this next line fails, delete it and replace it with the one following it
snapcraft --use-lxd 2>&1 | MATCH 'unrecognized arguments: --use-lxd'; exit 0
# snapcraft --use-lxd
snapcraft --use-lxd

unsquashfs manifest_0.1_*.snap
grep '^ test-var: value' squashfs-root/snap/manifest.yaml
Expand Down
4 changes: 1 addition & 3 deletions tests/spread/core24/remove-hook/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ execute: |
unset SNAPCRAFT_BUILD_ENVIRONMENT

# create a base instance by running snapcraft
# If this next line fails, delete it and replace it with the one following it
snapcraft pull --use-lxd --verbosity=trace 2>&1 | MATCH 'Error: unrecognized arguments: --use-lxd'; exit 0
# snapcraft pull --use-lxd --verbosity=trace
snapcraft pull --use-lxd --verbosity=trace

# verify base instance was created
instances="$(lxc list --project=snapcraft --format=csv --columns="n")"
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,20 @@ def default_factory(default_project):

@pytest.fixture()
def default_build_plan():
from craft_application import util
from craft_application.models import BuildInfo
from craft_providers import bases

# Set the build info base to match the host's, so we can test in destructive
# mode with no issues.
arch = util.get_host_architecture()
base = util.get_host_base()

return [
BuildInfo(
platform="generic-x86-64",
build_on="amd64",
build_for="amd64",
base=bases.BaseName("ubuntu", "24.04"),
build_on=arch,
build_for=arch,
base=base,
)
]

Expand Down Expand Up @@ -475,7 +480,6 @@ def package_service(
project=default_project,
services=default_factory,
snapcraft_yaml_path=file_path,
platform="amd64",
build_plan=default_build_plan,
)

Expand Down
1 change: 0 additions & 1 deletion tests/unit/services/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def test_pack_target_arch(
app=APP_METADATA,
project=default_project,
services=default_factory,
platform="amd64",
build_plan=default_build_plan,
snapcraft_yaml_path=tmp_path / "snapcraft.yaml",
)
Expand Down
Loading