Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a conda_load_cmd, to be used for loading environments (#1) #10

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading