Skip to content

Commit

Permalink
new option --[no]-slurm-export-env. Useful if --export-file is not su…
Browse files Browse the repository at this point in the history
…pported
  • Loading branch information
BerengerBerthoul committed May 24, 2024
1 parent a382e08 commit df8a1d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions pytest_parallel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile
import pytest
from pathlib import Path
import argparse


# --------------------------------------------------------------------------
Expand All @@ -23,8 +24,15 @@ def pytest_addoption(parser):

parser.addoption('--slurm-options', dest='slurm_options', type=str, help='list of SLURM options e.g. "--time=00:30:00 --qos=my_queue --n_tasks=4"')
parser.addoption('--slurm-additional-cmds', dest='slurm_additional_cmds', type=str, help='list of commands to pass to SLURM job e.g. "source my_env.sh"')
parser.addoption('--slurm-file', dest='slurm_file', type=str, help='Path to file containing header of SLURM job')
parser.addoption('--slurm-sub-command', dest='slurm_sub_command', type=str, help='SLURM submission command (defaults to `sbatch`)')
parser.addoption('--slurm-file', dest='slurm_file', type=str, help='Path to file containing header of SLURM job') # TODO DEL
parser.addoption('--slurm-sub-command', dest='slurm_sub_command', type=str, help='SLURM submission command (defaults to `sbatch`)') # TODO DEL

if sys.version_info >= (3,9):
parser.addoption('--slurm-export-env', dest='slurm_export_env', action=argparse.BooleanOptionalAction, default=True)
else:
parser.addoption('--slurm-export-env', dest='slurm_export_env', action='store_true')
parser.addoption('--no-slurm-export-env', dest='slurm_export_env', action='store_false')
parser.set_defaults(slurm_export_env=True)

parser.addoption('--detach', dest='detach', action='store_true', help='Detach SLURM jobs: do not send reports to the scheduling process (useful to launch slurm job.sh separately)')

Expand Down Expand Up @@ -59,13 +67,15 @@ def pytest_configure(config):
slurm_additional_cmds = config.getoption('slurm_additional_cmds')
slurm_worker = config.getoption('_worker')
slurm_file = config.getoption('slurm_file')
slurm_export_env = config.getoption('slurm_export_env')
slurm_sub_command = config.getoption('slurm_sub_command')
detach = config.getoption('detach')
if scheduler != 'slurm':
assert not slurm_worker, 'Option `--slurm-worker` only available when `--scheduler=slurm`'
assert not slurm_options, 'Option `--slurm-options` only available when `--scheduler=slurm`'
assert not slurm_additional_cmds, 'Option `--slurm-additional-cmds` only available when `--scheduler=slurm`'
assert not slurm_file, 'Option `--slurm-file` only available when `--scheduler=slurm`'
assert not slurm_export_env, 'Option `--slurm-export-env` only available when `--scheduler=slurm`'

if scheduler == 'slurm' and not slurm_worker:
assert slurm_options or slurm_file, 'You need to specify either `--slurm-options` or `--slurm-file` when `--scheduler=slurm`'
Expand Down Expand Up @@ -97,6 +107,7 @@ def pytest_configure(config):
'options' : slurm_option_list,
'additional_cmds': slurm_additional_cmds,
'file' : slurm_file,
'export_env' : slurm_export_env,
'sub_command' : slurm_sub_command,
}
plugin = ProcessScheduler(main_invoke_params, n_workers, slurm_conf, detach)
Expand Down
5 changes: 4 additions & 1 deletion pytest_parallel/process_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def submit_items(items_to_run, socket, main_invoke_params, slurm_ntasks, slurm_c
f.write(pytest._pytest_parallel_env_vars)

if slurm_conf['sub_command'] is None:
sbatch_cmd = 'sbatch --parsable --export-file=pytest_slurm/env_vars.sh pytest_slurm/job.sh'
if slurm_conf['export_env']:
sbatch_cmd = 'sbatch --parsable --export-file=pytest_slurm/env_vars.sh pytest_slurm/job.sh'
else:
sbatch_cmd = 'sbatch --parsable pytest_slurm/job.sh'
else:
sbatch_cmd = slurm_conf['sub_command'] + ' pytest_slurm/job.sh'

Expand Down

0 comments on commit df8a1d8

Please sign in to comment.