Skip to content

Commit

Permalink
Merge branch 'main' into create-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Aug 21, 2023
2 parents 481ca1c + f2f423e commit ebda752
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
15 changes: 7 additions & 8 deletions charmcraft/commands/pack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 Canonical Ltd.
# Copyright 2020-2023 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 @@ -27,9 +27,8 @@
import yaml
from craft_cli import emit, CraftError, ArgumentParsingError

from charmcraft import env, parts, instrum
from charmcraft import env, parts, instrum, const, package
from charmcraft.cmdbase import BaseCommand
from charmcraft.commands import build
from charmcraft.errors import DuplicateCharmsError
from charmcraft.metafiles.manifest import create_manifest
from charmcraft.parts import Step
Expand Down Expand Up @@ -210,7 +209,7 @@ def _pack_charm(self, parsed_args) -> List[pathlib.Path]:

# build
emit.progress("Packing the charm.")
builder = build.Builder(
builder = package.Builder(
config=self.config,
force=parsed_args.force,
debug=parsed_args.debug,
Expand Down Expand Up @@ -245,7 +244,7 @@ def _pack_bundle(
"""Pack a bundle."""
emit.progress("Packing the bundle.")
if parsed_args.shell:
build.launch_shell()
package.launch_shell()
return []

project = self.config.project
Expand Down Expand Up @@ -289,7 +288,7 @@ def _pack_bundle(
if env.is_charmcraft_running_in_managed_mode():
work_dir = env.get_managed_environment_home_path()
else:
work_dir = project.dirpath / build.BUILD_DIRNAME
work_dir = project.dirpath / const.BUILD_DIRNAME

# run the parts lifecycle
emit.debug(f"Parts definition: {config_parts}")
Expand All @@ -305,7 +304,7 @@ def _pack_bundle(
except (RuntimeError, CraftError) as error:
if parsed_args.debug:
emit.debug(f"Error when running PRIME step: {error}")
build.launch_shell()
package.launch_shell()
raise

# pack everything
Expand All @@ -324,7 +323,7 @@ def _pack_bundle(
emit.message(f"Created {str(zipname)!r}.")

if parsed_args.shell_after:
build.launch_shell()
package.launch_shell()

return [zipname]

Expand Down
7 changes: 1 addition & 6 deletions charmcraft/commands/build.py → charmcraft/package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 Canonical Ltd.
# Copyright 2020-2023 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 All @@ -13,10 +13,7 @@
# limitations under the License.
#
# For further info, check https://github.com/canonical/charmcraft

"""Infrastructure for the 'pack' command."""
# XXX Facundo 2022-06-29: all this functionality will be moved into the
# pack.py file (in a branch with no semantic changes, just move stuff around)

import os
import pathlib
Expand Down Expand Up @@ -48,8 +45,6 @@
from charmcraft.parts import Step
from charmcraft.utils import get_host_architecture

# Some constants that are used through the code.


def _format_run_on_base(base: Base) -> str:
"""Formulate charm string for base section."""
Expand Down
12 changes: 6 additions & 6 deletions tests/commands/test_pack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 Canonical Ltd.
# Copyright 2020-2023 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 @@ -98,7 +98,7 @@ def mock_parts():

@pytest.fixture
def mock_launch_shell():
with patch("charmcraft.commands.build.launch_shell") as mock_shell:
with patch("charmcraft.package.launch_shell") as mock_shell:
yield mock_shell


Expand Down Expand Up @@ -904,7 +904,7 @@ def test_charm_builder_infrastructure_called(config, tmp_path):
measure=measure_filepath,
)
config.set(type="charm")
with patch("charmcraft.commands.build.Builder") as builder_class_mock:
with patch("charmcraft.package.Builder") as builder_class_mock:
builder_class_mock.return_value = builder_instance_mock = MagicMock()
PackCommand(config).run(args)
builder_class_mock.assert_called_with(
Expand All @@ -926,7 +926,7 @@ def test_charm_pack_output_simple(config, emitter, formatted):

builder_instance_mock = MagicMock()
builder_instance_mock.run.return_value = ["mystuff.charm"]
with patch("charmcraft.commands.build.Builder") as builder_class_mock:
with patch("charmcraft.package.Builder") as builder_class_mock:
builder_class_mock.return_value = builder_instance_mock
PackCommand(config).run(args)

Expand All @@ -949,7 +949,7 @@ def test_charm_pack_output_multiple(config, emitter, formatted):

builder_instance_mock = MagicMock()
builder_instance_mock.run.return_value = ["mystuff1.charm", "mystuff2.charm"]
with patch("charmcraft.commands.build.Builder") as builder_class_mock:
with patch("charmcraft.package.Builder") as builder_class_mock:
builder_class_mock.return_value = builder_instance_mock
PackCommand(config).run(args)

Expand All @@ -974,7 +974,7 @@ def test_charm_pack_output_managed_mode(config, emitter, formatted, monkeypatch)
builder_instance_mock = MagicMock()
builder_instance_mock.run.return_value = ["mystuff.charm"]
with patch("charmcraft.env.is_charmcraft_running_in_managed_mode", return_value=True):
with patch("charmcraft.commands.build.Builder") as builder_class_mock:
with patch("charmcraft.package.Builder") as builder_class_mock:
builder_class_mock.return_value = builder_instance_mock
PackCommand(config).run(args)

Expand Down
7 changes: 4 additions & 3 deletions tests/commands/test_build.py → tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 Canonical Ltd.
# Copyright 2020-2023 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 @@ -32,7 +32,8 @@
from charmcraft import linters, instrum
from charmcraft.charm_builder import relativise
from charmcraft.bases import get_host_as_base
from charmcraft.commands.build import BUILD_DIRNAME, Builder, format_charm_file_name, launch_shell
from charmcraft.const import BUILD_DIRNAME
from charmcraft.package import Builder, format_charm_file_name, launch_shell
from charmcraft.models.charmcraft import Base, BasesConfiguration
from charmcraft.config import load
from charmcraft.providers import get_base_configuration
Expand Down Expand Up @@ -176,7 +177,7 @@ def mock_capture_logs_from_instance():

@pytest.fixture
def mock_launch_shell():
with patch("charmcraft.commands.build.launch_shell") as mock_shell:
with patch("charmcraft.package.launch_shell") as mock_shell:
yield mock_shell


Expand Down

0 comments on commit ebda752

Please sign in to comment.