Skip to content

Commit

Permalink
cli: Add --ignore-plugin-setups option
Browse files Browse the repository at this point in the history
This option lets you prevent Python configuration files from
being loaded from CLOE_PLUGIN_PATH.
  • Loading branch information
cassava committed May 6, 2024
1 parent 68bccdc commit 093bd23
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cli/cloe_launch/commands/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ def extract_target_args(xargs) -> List[str]:
should_append = True
return results

def ignore_plugin_setups():
"""Click option --ignore-plugin-setups.
Python files co-located in the CLOE_PLUGIN_PATH are loaded by cloe-launch.
However, CLOE_PLUGIN_PATH is currently approximated through identifying
directories in LD_LIBRARY_PATH that contain a cloe directory.
This approximation doesn't always work out, for example if LD_LIBRARY_PATH
contains relative paths, such as ".".
In this case you may want to disable plugin-setup loading, espcially if
you know that you don't need it.
"""
return click.option(
"--ignore-plugin-setups",
is_flag=True,
help="Ignore python plugin setup configuration files."
)

def preserve_env():
"""Click option --preserve-env."""
Expand Down
3 changes: 3 additions & 0 deletions cli/cloe_launch/commands/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
@cli_command("exec")
@_options.preserve_env()
@_options.override_env()
@_options.ignore_plugin_setups()
@_options.cache()
@click.option(
"-d",
Expand All @@ -49,6 +50,7 @@ def cli_exec(
conf: Configuration,
preserve_env: bool,
override_env: List[str],
ignore_plugin_setups: bool,
cache: bool,
debug: bool,
conanfile: str,
Expand All @@ -71,6 +73,7 @@ def cli_exec(
engine = Engine(conf, conanfile=conanfile)
engine.conan_args = _options.extract_conan_args(args)
engine.preserve_env = preserve_env
engine.load_plugin_setups = not ignore_plugin_setups

# Run cloe-engine and pass on returncode:
# If cloe-engine is killed/aborted, subprocess will return 250.
Expand Down
3 changes: 3 additions & 0 deletions cli/cloe_launch/commands/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
@cli_command("shell")
@_options.preserve_env()
@_options.override_env()
@_options.ignore_plugin_setups()
@_options.cache()
@_options.conanfile()
@_options.args()
Expand All @@ -43,6 +44,7 @@ def cli_shell(
conf: Configuration,
preserve_env: bool,
override_env: List[str],
ignore_plugin_setups: bool,
cache: bool,
conanfile: str,
args: List[str],
Expand All @@ -68,6 +70,7 @@ def cli_shell(
engine = Engine(conf, conanfile=conanfile)
engine.preserve_env = preserve_env
engine.conan_args = _options.extract_conan_args(args)
engine.load_plugin_setups = not ignore_plugin_setups

# Replace process with shell.
engine.shell(_options.extract_target_args(args), use_cache=cache)
9 changes: 7 additions & 2 deletions cli/cloe_launch/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, conf: Configuration, conanfile: Optional[str] = None):
self.preserve_env: bool = False
self.conan_args: List[str] = []
self.capture_output = True
self.load_plugin_setups = True

logging.info(f"Profile name: {self.profile}")
logging.info("Configuration:")
Expand Down Expand Up @@ -523,7 +524,9 @@ def shell(
env = self._prepare_runtime_env(use_cache)
self._write_runtime_env(env)

plugin_setups = self._prepare_plugin_setups(env)
plugin_setups = []
if self.load_plugin_setups:
plugin_setups = self._prepare_plugin_setups(env)
shell = os.getenv("SHELL", "/bin/bash")

# Print the final environment, if desired
Expand Down Expand Up @@ -694,9 +697,11 @@ def exec(
plugin setup and teardown."""
env = self._prepare_runtime_env(use_cache)
self._write_runtime_env(env)
plugin_setups = self._prepare_plugin_setups(env)

# Initialize plugin setups:
plugin_setups = []
if self.load_plugin_setups:
plugin_setups = self._prepare_plugin_setups(env)
for plugin in plugin_setups:
logging.debug(
f"Initializing plugin setup for {plugin.name} at {plugin.plugin}"
Expand Down

0 comments on commit 093bd23

Please sign in to comment.