launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #28038
[Merge] ~ilasc/lpcraft:add-cofig-path-option into lpcraft:main
Ioana Lasc has proposed merging ~ilasc/lpcraft:add-cofig-path-option into lpcraft:main.
Commit message:
Add opion to configure path to config file
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~ilasc/lpcraft/+git/lpcraft/+merge/414947
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/lpcraft:add-cofig-path-option into lpcraft:main.
diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
index 9a8e3b2..a1523ba 100644
--- a/lpcraft/commands/run.py
+++ b/lpcraft/commands/run.py
@@ -265,7 +265,11 @@ def _run_job(
def run(args: Namespace) -> int:
"""Run a pipeline, launching managed environments as needed."""
- config = Config.load(Path(".launchpad.yaml"))
+ file = getattr(args, "c__config")
+ if file is None:
+ config = Config.load(Path(".launchpad.yaml"))
+ else:
+ config = Config.load(Path(file))
provider = get_provider()
provider.ensure_provider_is_available()
diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
index b74099e..54d0d5a 100644
--- a/lpcraft/commands/tests/test_run.py
+++ b/lpcraft/commands/tests/test_run.py
@@ -66,8 +66,13 @@ class RunBaseTestCase(CommandBaseTestCase):
self.useFixture(TempDir()).join("test-project")
)
self.tmp_project_path.mkdir()
+
cwd = Path.cwd()
os.chdir(self.tmp_project_path)
+ self.tmp_config_path = os.path.join(
+ self.tmp_project_path, "test-config"
+ )
+ Path(self.tmp_config_path).mkdir(parents=True, exist_ok=True)
self.addCleanup(os.chdir, cwd)
def makeLXDProvider(
@@ -105,6 +110,66 @@ class TestRun(RunBaseTestCase):
@patch("lpcraft.commands.run.get_provider")
@patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
+ def test_path_config_file(
+ self, mock_get_host_architecture, mock_get_provider
+ ):
+
+ mock_get_provider.return_value = self.makeLXDProvider(is_ready=False)
+ config = dedent(
+ """
+ pipeline: []
+ jobs: {}
+ """
+ )
+ Path(".launchpad.yaml").write_text(config)
+
+ result = self.run_command("run")
+
+ # When no config path is passed in ensure we default to
+ # .launchpad.yaml
+ self.assertThat(
+ result,
+ MatchesStructure.byEquality(
+ exit_code=1,
+ errors=[CommandError("LXD is broken")],
+ ),
+ )
+
+ launcher = Mock(spec=launch)
+ provider = self.makeLXDProvider(lxd_launcher=launcher)
+ mock_get_provider.return_value = provider
+ execute_run = launcher.return_value.execute_run
+ execute_run.return_value = subprocess.CompletedProcess([], 0)
+ config = dedent(
+ """
+ pipeline:
+ - build-wheel
+
+ jobs:
+ build-wheel:
+ series: focal
+ architectures: amd64
+ run: pyproject-build
+ """
+ )
+
+ # When a custom location / config file ensure we
+ # pick it up instead of defaulting to .launchpad.yaml.
+ path = "%s/default-lpcraft-configuration.yaml" % self.tmp_config_path
+ Path(path).write_text(config)
+
+ result = self.run_command("run", "-c", path)
+
+ execute_run.assert_called_once_with(
+ ["bash", "--noprofile", "--norc", "-ec", "pyproject-build"],
+ cwd=Path("/root/project"),
+ env={},
+ stdout=ANY,
+ stderr=ANY,
+ )
+
+ @patch("lpcraft.commands.run.get_provider")
+ @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
def test_lxd_not_ready(
self, mock_get_host_architecture, mock_get_provider
):
diff --git a/lpcraft/main.py b/lpcraft/main.py
index 94ea82e..ed1df92 100644
--- a/lpcraft/main.py
+++ b/lpcraft/main.py
@@ -66,6 +66,11 @@ def main(argv: Optional[List[str]] = None) -> int:
parser_run.add_argument(
"--output", type=Path, help="Write output files to this directory."
)
+ parser_run.add_argument(
+ "-c" "--config",
+ type=Path,
+ help="Read the configuration file from this path.",
+ )
parser_run.set_defaults(func=run)
parser_run_one = subparsers.add_parser("run-one", help=run_one.__doc__)