Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add share/lib/python and share/bin to PYTHONPATH & PATH #5525

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/bin/python`.
wxtim marked this conversation as resolved.
Show resolved Hide resolved

### Fixes
[#5328](https://github.com/cylc/cylc-flow/pull/5328) -
Efficiency improvements to reduce task management overheads on the Scheduler.
Expand Down
5 changes: 4 additions & 1 deletion cylc/flow/etc/job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ 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:-}"
wxtim marked this conversation as resolved.
Show resolved Hide resolved
# Create share and work directories
mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}" || true
mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}/lib/python" || true
mkdir -p "${CYLC_WORKFLOW_SHARE_DIR}/bin" || true
mkdir -p "$(dirname "${CYLC_TASK_WORK_DIR}")" || true
mkdir -p "${CYLC_TASK_WORK_DIR}"
cd "${CYLC_TASK_WORK_DIR}"
Expand Down
5 changes: 4 additions & 1 deletion tests/functional/cylc-clean/01-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${CYLC_TEST_REG_BASE}
| |-- 01
| \`-- NN -> 01
|-- share
| \`-- cycle -> ${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${WORKFLOW_NAME}/share/cycle
| |-- bin
| |-- cycle -> ${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${WORKFLOW_NAME}/share/cycle
| \`-- lib
| \`-- python
\`-- work
\`-- 1
${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE}
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}"
wxtim marked this conversation as resolved.
Show resolved Hide resolved

purge
33 changes: 33 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,33 @@
#!jinja2
[scheduler]
[[events]]
stall timeout = PT0M

[scheduling]
initial cycle point = 1266
[[graph]]
R1 = install_cold => run_mypythonscript & run_myscript

[runtime]
[[install_cold]]
script = """
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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it?

_88932705_20302

Copy link
Member Author

@wxtim wxtim May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that one large wave might cure seasickness (and all other illnesses) in a rather permanent way for sailors on that.

(P.S. It's a Spike Milligan quote - I'm running through all the SFW (It's a smallish list) SM quotes I can find for tests today)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjoliver that is an insanely niche reference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__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()'