Skip to content

Commit

Permalink
Merge pull request #10 from kelbling/develop
Browse files Browse the repository at this point in the history
added a conda_load_cmd, to be used for loading environments (#1)
  • Loading branch information
corentincarton authored Jul 12, 2024
2 parents f76d68c + be84ebd commit 04d5529
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions wellies/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

conda_load = """
set +ux
conda activate {{ TARGET }}
{{ CONDA_ACTIVATE_CMD }} activate {{ TARGET }}
set -ux
"""

Expand Down Expand Up @@ -404,6 +404,7 @@ def __init__(
environment: str,
setup: str = None,
depends: List[str] = [],
conda_activate_cmd: str = "conda",
options: Dict[str, str] = {},
):
"""
Expand All @@ -419,11 +420,19 @@ def __init__(
The setup script, by default None.
depends : List[str], optional
A list of dependencies for the tool, by default [].
conda_activate_cmd : str, optional
The conda command to use to load the environment,
some login-nodes reuquire "source" instead of "conda"
by default "conda".
options : Dict[str, str], optional
A dictionary of options for the tool, by default {}.
"""
load = pf.TemplateScript(conda_load, TARGET=environment)
unload = "conda deactivate"
load = pf.TemplateScript(
conda_load,
TARGET=environment,
CONDA_ACTIVATE_CMD=conda_activate_cmd,
)
unload = f"{conda_activate_cmd} deactivate"
super().__init__(name, depends, load, unload, setup, options=options)


Expand All @@ -435,6 +444,7 @@ def __init__(
env_file: str,
depends: List[str] = [],
conda_cmd: str = "conda",
conda_activate_cmd: str = "conda",
options: Dict[str, any] = {},
):
"""
Expand Down Expand Up @@ -486,7 +496,12 @@ def __init__(
)
setup_script = [file_setup.script, setup]
super().__init__(
name, env_root, setup_script, depends, options=options
name,
env_root,
setup_script,
depends,
conda_activate_cmd,
options=options,
)


Expand All @@ -498,6 +513,7 @@ def __init__(
packages: Union[str, List[str]],
depends: List[str] = [],
conda_cmd: str = "conda",
conda_activate_cmd: str = "conda",
options: Dict[str, any] = {},
):
"""
Expand Down Expand Up @@ -528,7 +544,9 @@ def __init__(
PACKAGES=packages_str,
CONDA_CMD=conda_cmd,
)
super().__init__(name, env_root, setup, depends, options=options)
super().__init__(
name, env_root, setup, depends, conda_activate_cmd, options=options
)


def parse_environment(
Expand Down Expand Up @@ -576,7 +594,12 @@ def parse_environment(
"environment, file and extra_packages options cannot be used at the same time for conda" # noqa: E501
)
environment = options["environment"]
env = CondaEnvTool(name, environment, depends=depends)
env = CondaEnvTool(
name,
environment,
depends=depends,
conda_activate_cmd=options.get("conda_activate_cmd", "conda"),
)
elif type == "conda" and "env_file" in options:
if "environment" in options:
raise Exception(
Expand All @@ -588,6 +611,7 @@ def parse_environment(
options["env_file"],
depends,
conda_cmd=options.get("conda_cmd", "conda"),
conda_activate_cmd=options.get("conda_activate_cmd", "conda"),
)
elif type == "conda" and "extra_packages" in options:
if "environment" in options:
Expand All @@ -601,6 +625,7 @@ def parse_environment(
conda_packages,
depends,
conda_cmd=options.get("conda_cmd", "conda"),
conda_activate_cmd=options.get("conda_activate_cmd", "conda"),
)
elif type == "venv":
raise NotImplementedError("Pure virtual environment not implemented")
Expand Down

0 comments on commit 04d5529

Please sign in to comment.