diff --git a/CHANGES.md b/CHANGES.md index 565498ced12..22e0cb82e97 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,9 @@ Add the `-n` short option for `--workflow-name` to `cylc vip`; rename the `-n` short option for `--no-detach` to `-N`; add `-r` as a short option for `--run-name`. +[#5525](https://github.com/cylc/cylc-flow/pull/5525) - Jobs can use scripts +in `share/bin` and Python modules in `share/lib/python`. + ### Fixes [#5328](https://github.com/cylc/cylc-flow/pull/5328) - diff --git a/cylc/flow/etc/job.sh b/cylc/flow/etc/job.sh index 3337fa6435d..1a20a88071f 100644 --- a/cylc/flow/etc/job.sh +++ b/cylc/flow/etc/job.sh @@ -131,8 +131,8 @@ cylc__job__main() { CYLC_TASK_MESSAGE_STARTED_PID=$! # System paths: # * workflow directory (installed run-dir first). - export PATH="${CYLC_WORKFLOW_RUN_DIR}/bin:${PATH}" - export PYTHONPATH="${CYLC_WORKFLOW_RUN_DIR}/lib/python:${PYTHONPATH:-}" + export PATH="${CYLC_WORKFLOW_RUN_DIR}/share/bin:${CYLC_WORKFLOW_RUN_DIR}/bin:${PATH}" + export PYTHONPATH="${CYLC_WORKFLOW_RUN_DIR}/share/lib/python:${CYLC_WORKFLOW_RUN_DIR}/lib/python:${PYTHONPATH:-}" # Create share and work directories mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}" || true mkdir -p "$(dirname "${CYLC_TASK_WORK_DIR}")" || true diff --git a/tests/functional/jobscript/01-share-lib-bin.t b/tests/functional/jobscript/01-share-lib-bin.t new file mode 100644 index 00000000000..0c7b500da58 --- /dev/null +++ b/tests/functional/jobscript/01-share-lib-bin.t @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. +# Copyright (C) NIWA & British Crown (Met Office) & Contributors. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- +# CYLC_WORKFLOW_SHARE_DIR/bin is added to the PATH +# CYLC_WORKFLOW_SHARE_DIR/lib/python is added to PYTHONPATH +# +# Workflow creates scripts in CYLC_WORKFLOW_SHARE_DIR in `install_cold` task +# Which are then used in subsequent tasks. We check for the output of those +# tasks. +. "$(dirname "$0")/test_header" +set_test_number 2 + +# Setup: +install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" +run_ok "${TEST_NAME_BASE}.validate" cylc validate "${WORKFLOW_NAME}" +workflow_run_ok "${TEST_NAME_BASE}.play" cylc play --no-detach "${WORKFLOW_NAME}" + +purge diff --git a/tests/functional/jobscript/01-share-lib-bin/flow.cylc b/tests/functional/jobscript/01-share-lib-bin/flow.cylc new file mode 100644 index 00000000000..7c8d7db8186 --- /dev/null +++ b/tests/functional/jobscript/01-share-lib-bin/flow.cylc @@ -0,0 +1,35 @@ +#!jinja2 +[scheduler] + [[events]] + stall timeout = PT0M + +[scheduling] + initial cycle point = 1266 + [[graph]] + R1 = install_cold => run_mypythonscript & run_myscript + +[runtime] + [[install_cold]] + script = """ + mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}/lib/python" + mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}/bin" + + cat > "${CYLC_WORKFLOW_SHARE_DIR}/lib/python/mypythonscript.py" <<__HERE__ + def my_function(): + print("I can speak Esperanto like a native.") + __HERE__ + + cat > "${CYLC_WORKFLOW_SHARE_DIR}/bin/myscript.sh" <<__HERE__ + #!/usr/bin/bash + echo "A sure cure for seasickness is to sit under a tree." + __HERE__ + + chmod +x "${CYLC_WORKFLOW_SHARE_DIR}/lib/python/mypythonscript.py" + chmod +x "${CYLC_WORKFLOW_SHARE_DIR}/bin/myscript.sh" + """ + + [[run_myscript]] + script = myscript.sh + + [[run_mypythonscript]] + script = python -c 'from mypythonscript import my_function; my_function()'