Skip to content

Commit

Permalink
add share/lib/python and share/bin to PYTHONPATH & PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed May 9, 2023
1 parent 66004c7 commit bbae847
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cylc/flow/etc/job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ cylc__job__main() {
# System paths:
# * workflow directory (installed run-dir first).
export PATH="${CYLC_WORKFLOW_RUN_DIR}/bin:${PATH}"
export PATH="${CYLC_WORKFLOW_RUN_DIR}/share/bin:${PATH}"
export PYTHONPATH="${CYLC_WORKFLOW_RUN_DIR}/lib/python:${PYTHONPATH:-}"
export PYTHONPATH="${CYLC_WORKFLOW_RUN_DIR}/share/lib/python:${PYTHONPATH:-}"
# Create share and work directories
mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}" || true
mkdir -p "$(dirname "${CYLC_TASK_WORK_DIR}")" || true
Expand Down
32 changes: 32 additions & 0 deletions tests/functional/jobscript/01-share-lib-bin.t
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# 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}"
run_ok "${TEST_NAME_BASE}.play" cylc play --no-detach "${WORKFLOW_NAME}"

purge
36 changes: 36 additions & 0 deletions tests/functional/jobscript/01-share-lib-bin/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!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 Esparanto 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()'

0 comments on commit bbae847

Please sign in to comment.