Skip to content

Commit 1f6c907

Browse files
committed
cli: Add prepare command
This can be used to prepare an environment with a build before running the exec, shell, or activate commands.
1 parent 8f9731c commit 1f6c907

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

cli/cloe_launch/__main__.py

+41-10
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ def cli_exec(
198198
options.deny_profile_and_path(profile, profile_path)
199199
conf = Configuration(profile)
200200
engine = Engine(conf, conanfile=profile_path)
201-
engine.conan_args = conan_arg
202-
engine.conan_options = conan_option
203-
engine.conan_settings = conan_setting
201+
engine.conan_args = list(conan_arg)
202+
engine.conan_options = list(conan_option)
203+
engine.conan_settings = list(conan_setting)
204204

205205
engine.preserve_env = preserve_env
206206

@@ -248,9 +248,9 @@ def cli_shell(
248248
conf = Configuration(profile)
249249
engine = Engine(conf, conanfile=profile_path)
250250
engine.preserve_env = preserve_env
251-
engine.conan_args = conan_arg
252-
engine.conan_options = conan_option
253-
engine.conan_settings = conan_setting
251+
engine.conan_args = list(conan_arg)
252+
engine.conan_options = list(conan_option)
253+
engine.conan_settings = list(conan_setting)
254254

255255
# Replace process with shell.
256256
engine.shell(shell_args, use_cache=cache)
@@ -305,14 +305,45 @@ def cli_activate(
305305
options.deny_profile_and_path(profile, profile_path)
306306
conf = Configuration(profile)
307307
engine = Engine(conf, conanfile=profile_path)
308-
engine.conan_args = conan_arg
309-
engine.conan_options = conan_option
310-
engine.conan_settings = conan_setting
308+
engine.conan_args = list(conan_arg)
309+
engine.conan_options = list(conan_option)
310+
engine.conan_settings = list(conan_setting)
311311

312-
# Replace process with shell.
313312
engine.activate(use_cache=cache)
314313

315314

315+
# _________________________________________________________________________
316+
# Command: prepare [--cache] [--profile=PROFILE | --profile-path=CONANFILE]
317+
@main.command("prepare")
318+
@options.profile()
319+
@options.profile_path()
320+
@options.conan_arg()
321+
@options.conan_option()
322+
@options.conan_setting()
323+
@click.pass_obj
324+
def cli_prepare(
325+
opt,
326+
profile: str,
327+
profile_path: str,
328+
conan_arg: List[str],
329+
conan_option: List[str],
330+
conan_setting: List[str],
331+
) -> None:
332+
"""Prepare environment for selected profile.
333+
334+
This involves downloading missing and available packages and building
335+
outdated packages.
336+
"""
337+
options.deny_profile_and_path(profile, profile_path)
338+
conf = Configuration(profile)
339+
engine = Engine(conf, conanfile=profile_path)
340+
engine.conan_args = list(conan_arg)
341+
engine.conan_options = list(conan_option)
342+
engine.conan_settings = list(conan_setting)
343+
344+
engine.prepare()
345+
346+
316347
# _________________________________________________________________________
317348
# Command: clean [--profile PROFILE | --profile-path=CONANFILE]
318349
@main.command("clean")

cli/cloe_launch/exec.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ def __init__(self, conf, conanfile=None):
353353
self.engine_pre_args = conf._conf["engine"]["pre_arguments"]
354354
self.engine_post_args = conf._conf["engine"]["post_arguments"]
355355
self.preserve_env = False
356-
self.conan_args = []
357-
self.conan_options = []
358-
self.conan_settings = []
356+
self.conan_args = list()
357+
self.conan_options = list()
358+
self.conan_settings = list()
359+
self.capture_output = True
359360

360361
logging.info(f"Profile name: {self.profile}")
361362
logging.info("Configuration:")
@@ -591,6 +592,15 @@ def activate(
591592
print(f'export {var}="{env[var]}"')
592593
print(f'export CLOE_SHELL="{self.runtime_env_path()}"')
593594

595+
def prepare(self, build_policy: str = "outdated") -> None:
596+
"""Prepare (by downloading or building) dependencies for the profile."""
597+
self.capture_output = False
598+
if build_policy == "":
599+
self.conan_args.append("--build")
600+
else:
601+
self.conan_args.append(f"--build={build_policy}")
602+
self._prepare_runtime_env(use_cache=False)
603+
594604
def exec(
595605
self,
596606
args: List[str],
@@ -636,4 +646,4 @@ def exec(
636646
return result
637647

638648
def _run_cmd(self, cmd, must_succeed=True) -> subprocess.CompletedProcess:
639-
return run_cmd(cmd, must_succeed=must_succeed)
649+
return run_cmd(cmd, must_succeed=must_succeed, capture_output=self.capture_output)

cli/cloe_launch/utility.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ def run_cmd(
1010
cmd: List[str],
1111
env: Optional[Dict[str, str]] = None,
1212
must_succeed: bool = True,
13+
capture_output: bool = True,
1314
) -> subprocess.CompletedProcess:
1415
"""Run a command quietly, only printing stderr if the command fails."""
1516

1617
logging.info(f"Exec: {' '.join(cmd)}")
1718
result = subprocess.run(
1819
cmd,
1920
check=False,
20-
stdout=subprocess.PIPE,
21-
stderr=subprocess.STDOUT,
21+
stdout=subprocess.PIPE if capture_output else None,
22+
stderr=subprocess.STDOUT if capture_output else None,
2223
universal_newlines=True,
2324
env=env,
2425
)

cli/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cloe-launch"
3-
version = "0.18.0"
3+
version = "0.19.0"
44
description = "Launch cloe-engine with Conan profiles."
55
license = "Apache-2.0"
66
authors = [

cli/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
setup(
1313
long_description=readme,
1414
name="cloe-launch",
15-
version="0.18.0",
15+
version="0.19.0",
1616
description="Launch cloe-engine with Conan profiles.",
1717
python_requires="==3.*,>=3.6.0",
1818
author="Robert Bosch GmbH",

0 commit comments

Comments
 (0)