diff --git a/tests/test_tools.py b/tests/test_tools.py index 6240143..d61e33b 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -133,7 +133,15 @@ def test_system_venv(self, tools_config): extra_pkgs = tools_config["environments"][test_target][ "extra_packages" ] - extra_pkgs = " ".join(extra_pkgs) + pkgs_str = "" + ws = "" + for pkg in extra_pkgs: + pkgs_str += ( + f"{ws}'{pkg}'" + if set(pkg).intersection(set("><")) + else f"{ws}{pkg}" + ) + ws = " " expected = { "load": [f"source {self.lib_dir}/{test_target}/bin/activate"], @@ -141,7 +149,7 @@ def test_system_venv(self, tools_config): "setup": [ f"rm -rf {self.lib_dir}/{test_target}", f"python3 -m venv {self.lib_dir}/{test_target} --system-site-packages", - f"pip install {extra_pkgs}", + f"pip install {pkgs_str}", ], } @@ -272,7 +280,15 @@ def test_conda_pkgs(self, tools_config): extra_pkgs = tools_config["environments"][test_target][ "extra_packages" ] - extra_pkgs = " ".join(extra_pkgs) + pkgs_str = "" + ws = "" + for pkg in extra_pkgs: + pkgs_str += ( + f"{ws}'{pkg}'" + if set(pkg).intersection(set("><")) + else f"{ws}{pkg}" + ) + ws = " " conda_cmd = tools_config["environments"][test_target]["conda_cmd"] expected = { @@ -284,7 +300,7 @@ def test_conda_pkgs(self, tools_config): "unload": ["conda deactivate"], "setup": [ f"rm -rf {self.lib_dir}/{test_target}", - f"{conda_cmd} create -p {self.lib_dir}/{test_target} {extra_pkgs}", + f"{conda_cmd} create -p {self.lib_dir}/{test_target} {pkgs_str}", ], } diff --git a/wellies/tools.py b/wellies/tools.py index 768371a..9fe65dd 100644 --- a/wellies/tools.py +++ b/wellies/tools.py @@ -1,4 +1,5 @@ import os +import shlex from os import path from typing import Dict from typing import List @@ -354,7 +355,7 @@ def __init__( ] if extra_packages: setup.extend(load) - pkgs = " ".join(extra_packages) + pkgs = " ".join([shlex.quote(pkg) for pkg in extra_packages]) setup.append(f"pip install {pkgs}") super().__init__(name, depends, load, unload, setup, options=options) @@ -544,7 +545,7 @@ def __init__( A dictionary of options for the tool, by default {}. """ env_root = path.join(lib_dir, name) - packages_str = " ".join(packages) + packages_str = " ".join([shlex.quote(pkg) for pkg in packages]) setup = pf.TemplateScript( conda_create, ENV_DIR=env_root,