diff --git a/xfel_calibrate/finalize.py b/xfel_calibrate/finalize.py index df620c5136eb31582541fbfa7162cc2d7e686151..6bdc1117cc5eba7ce18e08300044e41ad7cd2cee 100644 --- a/xfel_calibrate/finalize.py +++ b/xfel_calibrate/finalize.py @@ -186,8 +186,8 @@ def make_timing_summary(run_path, joblist, request_time, submission_time): time_table=time_table.split('\n')))) -def make_report(run_path, tmp_path, out_path, project, author, version, - report_to): +def make_report(run_path: str, tmp_path: str, out_path: str, project: str, + author: str, version: str, report_to: str): """ Create calibration report (pdf file) @@ -201,12 +201,13 @@ def make_report(run_path, tmp_path, out_path, project, author, version, :param project: Project title :param author: Author of the notebook :param version: Version of the notebook - :param report_to: Name or path of the report file + :param report_to: report path tailed with report name """ run_path = path.abspath(run_path) report_path, report_name = path.split(report_to) - if report_path != '': - out_path = report_path + + if not report_path: + report_path = out_path try: check_call([sys.executable, "-m", "sphinx.cmd.quickstart", @@ -299,16 +300,18 @@ def make_report(run_path, tmp_path, out_path, project, author, version, # finally call the make scripts chdir(run_path) try: - check_call(["make", f"SPHINXBUILD={sys.executable} -m sphinx", "latexpdf"]) + check_call(["make", f"SPHINXBUILD={sys.executable} -m sphinx", + "latexpdf"]) except CalledProcessError: print("Failed to make pdf documentation") - print("Temp files will not be deleted and " + - "can be inspected at: {}".format(run_path)) + print("Temp files will not be deleted and " + f"can be inspected at: {run_path}") return - print("Moving report to final location: {}".format(out_path)) - makedirs(out_path, exist_ok=True) - copy('{}/_build/latex/{}.pdf'.format(run_path, report_name), out_path) + + print(f"Moving report to final location: {report_path}") + makedirs(report_path, exist_ok=True) + copy(f'{run_path}/_build/latex/{report_name}.pdf', report_path) temp_dirs = glob(f'{tmp_path}/*/') # Remove folders with figures and sphinx files. @@ -318,15 +321,15 @@ def make_report(run_path, tmp_path, out_path, project, author, version, # Archiving files in slurm_tmp if os.path.isfile(f'{out_path}/retrieved_constants.yml'): - move(f'{out_path}/retrieved_constants.yml', + copy(f'{out_path}/retrieved_constants.yml', f"{tmp_path}") # Moving temporary files to out-folder after successful execution # This helps in keeping elements needed for re-producibility. print(f"Moving temporary files to final location" - f": {out_path}/{os.path.basename(tmp_path)} with name: " + f": {report_path}/{os.path.basename(tmp_path)} with name: " f"slurm_out_{report_name}") - move(tmp_path, f"{out_path}/slurm_out_{report_name}") + move(tmp_path, f"{report_path}/slurm_out_{report_name}") def make_titlepage(sphinx_path, project, data_path, version):