← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/lpcraft:run-one-output-directory into lpcraft:main

 

Colin Watson has proposed merging ~cjwatson/lpcraft:run-one-output-directory into lpcraft:main.

Commit message:
Fix handling of run-one --output-directory option

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/lpcraft/+git/lpcraft/+merge/419519

This was missed when the --output option was renamed to --output-directory.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/lpcraft:run-one-output-directory into lpcraft:main.
diff --git a/NEWS.rst b/NEWS.rst
index 90344ac..7af8154 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -9,6 +9,9 @@ Version history
   tree, in order to make life easier for build systems such as
   ``dpkg-buildpackage`` that write output files to their parent directory.
 
+- Fix handling of the ``--output-directory`` option to the ``run-one``
+  command.
+
 0.0.8   (2022-04-13)
 ====================
 
diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
index 5a7530f..e5bc296 100644
--- a/lpcraft/commands/run.py
+++ b/lpcraft/commands/run.py
@@ -390,7 +390,9 @@ def run_one(args: Namespace) -> int:
     provider.ensure_provider_is_available()
 
     try:
-        _run_job(args.job, job, provider, getattr(args, "output", None))
+        _run_job(
+            args.job, job, provider, getattr(args, "output_directory", None)
+        )
     finally:
         should_clean_environment = getattr(args, "clean", False)
 
diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
index 08e9803..b5ae1db 100644
--- a/lpcraft/commands/tests/test_run.py
+++ b/lpcraft/commands/tests/test_run.py
@@ -1970,6 +1970,72 @@ class TestRunOne(RunBaseTestCase):
             stderr=ANY,
         )
 
+    @patch("lpcraft.env.get_managed_environment_project_path")
+    @patch("lpcraft.commands.run.get_provider")
+    @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
+    def test_copies_output_paths(
+        self,
+        mock_get_host_architecture,
+        mock_get_provider,
+        mock_get_project_path,
+    ):
+        def fake_pull_file(source: Path, destination: Path) -> None:
+            destination.touch()
+
+        target_path = Path(self.useFixture(TempDir()).path)
+        launcher = Mock(spec=launch)
+        provider = makeLXDProvider(lxd_launcher=launcher)
+        mock_get_provider.return_value = provider
+        execute_run = LocalExecuteRun(self.tmp_project_path)
+        launcher.return_value.execute_run = execute_run
+        mock_get_project_path.return_value = self.tmp_project_path
+        launcher.return_value.pull_file.side_effect = fake_pull_file
+        config = dedent(
+            """
+            pipeline:
+                - build
+
+            jobs:
+                build:
+                    series: focal
+                    architectures: amd64
+                    run: |
+                        true
+                    output:
+                        paths: ["*.tar.gz", "*.whl"]
+            """
+        )
+        Path(".launchpad.yaml").write_text(config)
+        Path("test_1.0.tar.gz").write_bytes(b"")
+        Path("test_1.0.whl").write_bytes(b"")
+        result = self.run_command(
+            "run-one", "--output-directory", str(target_path), "build", "0"
+        )
+
+        self.assertEqual(0, result.exit_code)
+        job_output = target_path / "build" / "focal" / "amd64"
+        self.assertEqual(
+            [
+                call(
+                    source=self.tmp_project_path / "test_1.0.tar.gz",
+                    destination=job_output / "files" / "test_1.0.tar.gz",
+                ),
+                call(
+                    source=self.tmp_project_path / "test_1.0.whl",
+                    destination=job_output / "files" / "test_1.0.whl",
+                ),
+            ],
+            launcher.return_value.pull_file.call_args_list,
+        )
+        self.assertEqual(
+            ["files", "properties"],
+            sorted(path.name for path in job_output.iterdir()),
+        )
+        self.assertEqual(
+            ["test_1.0.tar.gz", "test_1.0.whl"],
+            sorted(path.name for path in (job_output / "files").iterdir()),
+        )
+
     @patch("lpcraft.commands.run.get_provider")
     @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
     @patch("lpcraft.providers._lxd.LXDProvider.clean_project_environments")