[ENH]: Allow for using venv in queue kind #249

Merged
synchon merged 6 commits from feat/run-venv into main 2024-02-29 08:29:37 +00:00
6 changed files with 48 additions and 7 deletions

View file

@ -0,0 +1 @@
Support ``venv`` as environment kind for queueing jobs by `Synchon Mandal`_
LeSasse commented 2024-02-28 07:53:19 +00:00 (Migrated from github.com)

nice!

nice!

View file

@ -52,11 +52,13 @@ The following parameters are available for HTCondor:
* ``kind``: This is the kind of virtual environment to use: * ``kind``: This is the kind of virtual environment to use:
LeSasse commented 2024-02-28 07:53:00 +00:00 (Migrated from github.com)

no support for a relative path? What is the main rationale behind this?

no support for a relative path? What is the main rationale behind this?
fraimondo commented 2024-02-28 08:29:38 +00:00 (Migrated from github.com)

The main question is: relative to what? The YAML? the CWD? We had this issue in #224, #127, #191.

If we can answer this, then we can also use a relative path.

The main question is: relative to what? The YAML? the CWD? We had this issue in #224, #127, #191. If we can answer this, then we can also use a relative path.
LeSasse commented 2024-02-28 08:30:44 +00:00 (Migrated from github.com)

i agree. Absolute will keep it simple.

i agree. Absolute will keep it simple.
fraimondo commented 2024-02-28 09:02:58 +00:00 (Migrated from github.com)

I think relative paths are simpler, problem is always the same: determining the "relative to" to compute an absolute path and fix it in the yaml.

I think relative paths are simpler, problem is always the same: determining the "relative to" to compute an absolute path and fix it in the yaml.
synchon commented 2024-02-28 10:56:22 +00:00 (Migrated from github.com)

We have been following the "relative to YAML" idea and I updated it to reflect that.

We have been following the "relative to YAML" idea and I updated it to reflect that.
* ``conda`` * ``conda``
* ``virtualenv`` (not yet supported) * ``venv``
* ``local`` (no virtual environment) * ``local`` (no virtual environment)
* ``name``: This is the name of the environment to use in case a virtual * ``name``: This is the name of the environment to use in case a virtual
environment is used. environment is used. It should be the name when ``conda`` is used and
the absolute or relative path to the virtualenv when ``venv`` is used.
If relative path is used then it should be relative to the YAML.
* ``mem``: Memory to be used by the job. It must be provided as a string with * ``mem``: Memory to be used by the job. It must be provided as a string with
the units (e.g. ``2GB``). the units (e.g. ``2GB``).

View file

@ -418,7 +418,10 @@ def _queue_condor(
env_name = env["name"] env_name = env["name"]
executable = "run_venv.sh" executable = "run_venv.sh"
arguments = f"{env_name} junifer" arguments = f"{env_name} junifer"
# TODO: Copy run_venv.sh to jobdir exec_path = jobdir / executable
logger.info(f"Copying {executable} to {exec_path.absolute()!s}")
shutil.copy(Path(__file__).parent / "res" / executable, exec_path)
make_executable(exec_path)
elif env["kind"] == "local": elif env["kind"] == "local":
executable = "junifer" executable = "junifer"
arguments = "" arguments = ""

View file

@ -99,4 +99,17 @@ def parse_yaml(filepath: Union[str, Path]) -> Dict:
contents["storage"]["uri"] = str( contents["storage"]["uri"] = str(
(filepath.parent / uri_path).resolve() (filepath.parent / uri_path).resolve()
) )
# Allow relative path if queue env kind is venv; same motivation as above
if "queue" in contents:
if "env" in contents["queue"]:
if "venv" == contents["queue"]["env"]["kind"]:
# Check if the env name is relative
venv_path = Path(contents["queue"]["env"]["name"])
if not venv_path.is_absolute():
# Compute the absolute path
contents["queue"]["env"]["name"] = str(
(filepath.parent / venv_path).resolve()
)
return contents return contents

View file

@ -1,17 +1,17 @@
#!/bin/bash #!/bin/bash
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
echo "This script is meant to run a command within a python environment" echo "This script is meant to run a command within a conda environment."
echo "It needs at least 2 parameters." echo "It needs at least 2 parameters."
echo "The first one must be the environment name." echo "The first one must be the environment name."
echo "The rest will be the command" echo "The rest will be the command."
exit 255 exit 255
fi fi
eval "$(conda shell.bash hook)" eval "$(conda shell.bash hook)"
env_name=$1 env_name=$1
echo "Activating ${env_name}" echo "Activating ${env_name}"
conda activate "$1" conda activate "${env_name}"
shift 1 shift 1
if [ -f "pre_run.sh" ]; then if [ -f "pre_run.sh" ]; then
@ -19,5 +19,5 @@ if [ -f "pre_run.sh" ]; then
. ./pre_run.sh . ./pre_run.sh
fi fi
echo "Running ${*} in virtual environment" echo "Running ${*} in conda environment"
"$@" "$@"

View file

@ -0,0 +1,22 @@
#!/bin/bash
LeSasse commented 2024-02-28 07:54:02 +00:00 (Migrated from github.com)

hard coded shell? I suppose this will change in a separate PR?

hard coded shell? I suppose this will change in a separate PR?
LeSasse commented 2024-02-28 07:54:38 +00:00 (Migrated from github.com)

the environment path in this case i suppose, might be worth mentioning here specifically

the environment path in this case i suppose, might be worth mentioning here specifically
fraimondo commented 2024-02-28 08:30:31 +00:00 (Migrated from github.com)

I think this is the case. We need to provide run_venv.zsh, run_conda.zsh, etc.

I think this is the case. We need to provide `run_venv.zsh`, `run_conda.zsh`, etc.
fraimondo commented 2024-02-28 08:30:44 +00:00 (Migrated from github.com)

+1

+1
synchon commented 2024-02-28 10:24:23 +00:00 (Migrated from github.com)

Yes this will change in #273 which will require a new option in the YAML.

Yes this will change in #273 which will require a new option in the YAML.
synchon commented 2024-02-28 10:56:59 +00:00 (Migrated from github.com)

Updated it to make it clear.

Updated it to make it clear.
if [ $# -lt 2 ]; then
echo "This script is meant to run a command within a Python virtual environment."
echo "It needs at least 2 parameters."
echo "The first one must be the virtualenv path."
echo "The rest will be the command."
exit 255
fi
env_path=$1
echo "Activating ${env_path}"
source "${env_path}"/bin/activate
shift 1
if [ -f "pre_run.sh" ]; then
echo "Sourcing pre_run.sh"
. ./pre_run.sh
fi
echo "Running ${*} in Python virtual environment"
"$@"