Skip to content
Snippets Groups Projects
Commit 4ba06c72 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Start working on ability to recreate environment for xfel_calibrate.repeat

parent 9c562dca
No related branches found
No related tags found
1 merge request!660Recreate environments on demand for xfel-calibrate-repeat
...@@ -5,6 +5,7 @@ from datetime import datetime ...@@ -5,6 +5,7 @@ from datetime import datetime
from pathlib import Path from pathlib import Path
import nbformat import nbformat
from env_cache import EnvsManager, FixedPythonEnvMaker
from nbparameterise import extract_parameters, parameter_values, replace_definitions from nbparameterise import extract_parameters, parameter_values, replace_definitions
from cal_tools.tools import CalibrationMetadata from cal_tools.tools import CalibrationMetadata
...@@ -31,10 +32,28 @@ def new_report_path(old_out_folder, old_report_path, new_out_folder): ...@@ -31,10 +32,28 @@ def new_report_path(old_out_folder, old_report_path, new_out_folder):
else: else:
return str(Path(new_out_folder, report_in_output)) return str(Path(new_out_folder, report_in_output))
def get_python(args, py_version):
if args.env_from_python:
reqs = (args.from_dir / 'requirements.txt').read_text()
env_mgr = EnvsManager(
Path(temp_path, 'envs'), FixedPythonEnvMaker(args.env_from_python)
)
return env_mgr.get_env(py_version, reqs) / 'bin' / 'python'
elif args.python:
return args.python
return sys.executable
def main(argv=None): def main(argv=None):
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
ap.add_argument("from_dir", type=Path, help="A directory containing steps.json") ap.add_argument("from_dir", type=Path, help="A directory containing steps.json")
ap.add_argument("--python", help="Path to Python executable to run notebooks")
env_args = ap.add_mutually_exclusive_group()
env_args.add_argument("--python", help="Path to Python executable to run notebooks")
env_args.add_argument(
"--env-from-python",
help="Make a virtualenv from this Python & install the library versions"
" these notebooks previously used"
)
ap.add_argument("--out-folder", help="Directory to put output data") ap.add_argument("--out-folder", help="Directory to put output data")
ap.add_argument("--slurm-partition", help="Submit jobs in this Slurm partition") ap.add_argument("--slurm-partition", help="Submit jobs in this Slurm partition")
ap.add_argument('--no-cluster-job', action="store_true", ap.add_argument('--no-cluster-job', action="store_true",
...@@ -70,8 +89,9 @@ def main(argv=None): ...@@ -70,8 +89,9 @@ def main(argv=None):
Path(out_folder).mkdir(parents=True, exist_ok=True) Path(out_folder).mkdir(parents=True, exist_ok=True)
shutil.copy(working_dir / 'calibration_metadata.yml', out_folder) shutil.copy(working_dir / 'calibration_metadata.yml', out_folder)
py_version = cal_metadata.get('python-environment', {}).get('python-version')
job_chain = JobChain.from_dir( job_chain = JobChain.from_dir(
working_dir, python=(args.python or sys.executable) working_dir, python=get_python(args, py_version)
) )
if args.no_cluster_job: if args.no_cluster_job:
job_chain.run_direct() job_chain.run_direct()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment