From 50be479376154c70a8d5b2bae5b977bd291be16e Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 19 Oct 2024 14:19:08 +0200 Subject: [PATCH] don't use default module name --- README.md | 11 ++++++----- app.cfg.example | 2 +- tasks/build.py | 18 +++++++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5ed2696..503c6e2 100644 --- a/README.md +++ b/README.md @@ -429,15 +429,16 @@ the account trying to trigger build jobs has no permission to do so. ``` allow_update_submit_opts = false ``` -`allow_update_submit_opts` determines whether or not to allow updating the submit -options via custom python module provided by the pull request -being processed. +`allow_update_submit_opts` determines whether or not to allow updating the +submit options via custom python module provided by the pull request being +processed. Enabling this also requires `update_submit_opts_modname` to be set. ``` update_submit_opts_modname = MODULE_NAME ``` -Replace `MODULE_NAME` with the name of custom python module used to determine -updated submit options (default is `det_submit_opts`) +Replace `MODULE_NAME` with the name of a python module, located in the root dir +of the target repo, and containing function `det_submit_options()`, which will +be used to determine updated submit options. #### `[bot_control]` section diff --git a/app.cfg.example b/app.cfg.example index ed80ecc..ead8ca5 100644 --- a/app.cfg.example +++ b/app.cfg.example @@ -132,7 +132,7 @@ no_build_permission_comment = Label `bot:build` has been set by user `{build_lab # whether or not to allow updating the submit options via custom python module det_submit_opts allow_update_submit_opts = false -# name of custom python module used to determine updated submit options (default: det_submit_opts) +# name of custom python module used to determine updated submit options det_submit_opts_modname = det_submit_opts [deploycfg] diff --git a/tasks/build.py b/tasks/build.py index 83d91ae..36c02a8 100644 --- a/tasks/build.py +++ b/tasks/build.py @@ -692,21 +692,25 @@ def submit_job(job, cfg): else: time_limit = f"--time={DEFAULT_JOB_TIME_LIMIT}" - # update job.slurm_opts with det_submit_opts(job) in det_submit_opts.py if allowed and available + # update job.slurm_opts with det_submit_opts(job) in custom python module if allowed and available do_update_slurm_opts = False allow_update_slurm_opts = cfg[config.SECTION_BUILDENV].getboolean(config.BUILDENV_SETTING_ALLOW_UPDATE_SUBMIT_OPTS) if allow_update_slurm_opts: sys.path.append(job.working_dir) det_submit_opts_modname = cfg[config.SECTION_BUILDENV].get(config.BUILDENV_SETTING_DET_SUBMIT_OPTS_MODNAME) - det_submit_opts = importlib.import_module(det_submit_opts_modname) - try: - from det_submit_opts import det_submit_opts # pylint:disable=import-outside-toplevel - do_update_slurm_opts = True - except ImportError: + if not det_submit_opts_modname: log(f"{fn}(): not updating job.slurm_opts: " - "cannot import function det_submit_opts from module det_submit_opts") + "config setting {config.BUILDENV_SETTING_DET_SUBMIT_OPTS_MODNAME} not set") + else: + try: + det_submit_opts = importlib.import_module(det_submit_opts_modname) + from det_submit_opts import det_submit_opts # pylint:disable=import-outside-toplevel + do_update_slurm_opts = True + except ImportError: + log(f"{fn}(): not updating job.slurm_opts: " + "cannot import function det_submit_opts from module {det_submit_opts_modname}") if do_update_slurm_opts: job = job._replace(slurm_opts=det_submit_opts(job))