Skip to content

Commit

Permalink
build(deps): use craft-application 2.0.0 (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Mar 13, 2024
1 parent c6e5d54 commit 212b200
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 32 deletions.
6 changes: 3 additions & 3 deletions charmcraft/application/commands/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"""craft-application based lifecycle commands."""
from __future__ import annotations

import os
import pathlib
import sys
import textwrap
from typing import TYPE_CHECKING, cast

Expand Down Expand Up @@ -168,9 +168,9 @@ def run_managed(self, parsed_args: argparse.Namespace) -> bool:
"""
project_dir = pathlib.Path(getattr(parsed_args, "project_dir", "."))
charmcraft_yaml = utils.load_yaml(project_dir / "charmcraft.yaml")
# Always use a runner on non-posix platforms.
# Always use a runner on non-Linux platforms.
# Craft-parts is not designed to work on non-posix platforms, and most
# notably here, the bundle plugin doesn't work on Windows.
if os.name == "posix" and charmcraft_yaml and charmcraft_yaml.get("type") == "bundle":
if sys.platform == "linux" and charmcraft_yaml and charmcraft_yaml.get("type") == "bundle":
return False
return super().run_managed(parsed_args)
5 changes: 2 additions & 3 deletions charmcraft/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ def _extra_yaml_transform(

return yaml_data

def _configure_services(self, platform: str | None, build_for: str | None) -> None:
super()._configure_services(platform, build_for)
def _configure_services(self, provider_name: str | None) -> None:
super()._configure_services(provider_name)
self.services.set_kwargs(
"package",
project_dir=self.project_dir,
platform=platform,
build_plan=self._build_plan,
)

Expand Down
3 changes: 1 addition & 2 deletions charmcraft/services/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ def __init__(
services: CharmcraftServiceFactory,
*,
project_dir: pathlib.Path,
platform: str | None,
build_plan: list[craft_application.models.BuildInfo],
) -> None:
super().__init__(app, services, project=cast(craft_application.models.Project, project))
self.project_dir = project_dir.resolve(strict=True)
self._platform = platform
self._platform = build_plan[0].platform
self._build_plan = build_plan

def pack(self, prime_dir: pathlib.Path, dest: pathlib.Path) -> list[pathlib.Path]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "charmcraft"
description = "The main tool to build, upload, and develop in general the Juju charms."
dynamic = ["version", "readme"]
dependencies = [
"craft-application @ git+https://github.com/canonical/craft-application@main",
"craft-application~=2.0",
"craft-cli>=2.3.0",
"craft-parts>=1.18",
"craft-providers>=1.23.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
coverage==7.4.2
craft-application @ git+https://github.com/canonical/craft-application@main
craft-application==2.0.0
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.2
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ attrs==23.2.0
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
craft-application @ git+https://github.com/canonical/craft-application@main
craft-application==2.0.0
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.2
Expand Down
20 changes: 17 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2023 Canonical Ltd.
# Copyright 2020-2024 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,11 +30,12 @@
import pytest
import responses as responses_module
import yaml
from craft_application import models
from craft_parts import callbacks, plugins
from craft_providers import Executor, Provider
from craft_providers import Executor, Provider, bases

import charmcraft.parts
from charmcraft import const, deprecations, instrum, parts, services
from charmcraft import const, deprecations, instrum, parts, services, utils
from charmcraft.application.main import APP_METADATA
from charmcraft.bases import get_host_as_base
from charmcraft.models import charmcraft as config_module
Expand Down Expand Up @@ -71,6 +72,19 @@ def service_factory(
return factory


@pytest.fixture()
def default_build_plan():
arch = utils.get_host_architecture()
return [
models.BuildInfo(
base=bases.BaseName("ubuntu", "22.04"),
build_on=arch,
build_for=arch,
platform="distro-1-test64",
)
]


@pytest.fixture()
def fake_project_dir(fs) -> pathlib.Path:
project_dir = pathlib.Path("/root/project")
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/commands/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@pytest.mark.xfail(
sys.platform == "win32", reason="https://github.com/canonical/charmcraft/issues/1552"
sys.platform != "linux", reason="https://github.com/canonical/charmcraft/issues/1552"
)
@pytest.mark.parametrize(
"bundle_yaml",
Expand All @@ -35,15 +35,16 @@
"name: my-bundle",
],
)
def test_build_basic_bundle(monkeypatch, app, new_path, bundle_yaml):
def test_build_basic_bundle(monkeypatch, capsys, app, new_path, bundle_yaml):
(new_path / "charmcraft.yaml").write_text("type: bundle")
(new_path / "bundle.yaml").write_text(bundle_yaml)

monkeypatch.setenv("CRAFT_DEBUG", "1")
monkeypatch.setattr("sys.argv", ["charmcraft", "pack"])

app.configure({})
app.run()
if app.run() != 0:
raise ValueError(capsys.readouterr())

with zipfile.ZipFile("bundle.zip") as bundle_zip:
actual_bundle_yaml = bundle_zip.read("bundle.yaml").decode()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def service_factory():
def app(monkeypatch, service_factory):
monkeypatch.setenv("CRAFT_DEBUG", "1")
app = application.Charmcraft(app=application.APP_METADATA, services=service_factory)
app._configure_services(None, None)
app._configure_services(None)
commands.fill_command_groups(app)

return app
2 changes: 1 addition & 1 deletion tests/integration/services/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def service_factory(fs, fake_path, simple_charm) -> services.CharmcraftServiceFa

app = Charmcraft(app=APP_METADATA, services=factory)

app._configure_services(platform=None, build_for=None)
app._configure_services(provider_name=None)

factory.project = simple_charm

Expand Down
5 changes: 2 additions & 3 deletions tests/integration/services/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@


@pytest.fixture()
def package_service(fake_path, service_factory):
def package_service(fake_path, service_factory, default_build_plan):
fake_project_dir = fake_path
svc = services.PackageService(
app=APP_METADATA,
project=service_factory.project,
services=service_factory,
project_dir=fake_project_dir,
platform="ubuntu-22.04-arm64",
build_plan=[],
build_plan=default_build_plan,
)
service_factory.package = svc
return svc
Expand Down
19 changes: 13 additions & 6 deletions tests/unit/commands/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@
# For further info, check https://github.com/canonical/charmcraft
"""Unit tests for lifecycle commands."""
import argparse
import sys

import pytest

from charmcraft.application.commands import lifecycle


def test_pack_run_managed_bundle_by_os(monkeypatch, new_path):
@pytest.mark.parametrize(
("platform", "expected"),
[
("linux", False),
("macos", True),
("win32", True),
],
)
def test_pack_run_managed_bundle_by_os(monkeypatch, new_path, platform, expected):
"""When packing a bundle, run_managed should return False if and only if we're on posix."""
monkeypatch.setattr("sys.platform", platform)
(new_path / "charmcraft.yaml").write_text("type: bundle")

pack = lifecycle.PackCommand(None)

result = pack.run_managed(argparse.Namespace(destructive_mode=False))

if sys.platform in ("win32",): # non-posix platforms
assert result, "Didn't ask for managed mode on non-posix platform"
else:
assert not result
assert result == expected
7 changes: 3 additions & 4 deletions tests/unit/services/test_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2023-2024 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@


@pytest.fixture()
def package_service(fake_path, simple_charm, service_factory):
def package_service(fake_path, simple_charm, service_factory, default_build_plan):
fake_project_dir = fake_path / "project"
fake_project_dir.mkdir(parents=True)

Expand All @@ -54,8 +54,7 @@ def package_service(fake_path, simple_charm, service_factory):
# The package service doesn't call other services
services=service_factory,
project_dir=fake_project_dir,
platform="distro-1-test64",
build_plan=[],
build_plan=default_build_plan,
)


Expand Down

0 comments on commit 212b200

Please sign in to comment.