Skip to content

Commit

Permalink
Added SLURM and Conda support
Browse files Browse the repository at this point in the history
- Modified exe function in base_script.sh.template to support
  aliases
- Added `conda install` support in base_script.sh.template
- Added SLURM support with slurm-script.sh.template
- SLURM support wraps given commands with SLURM commands using bash
  aliases
- Added usage instructions for slurm-script.sh.template and
  remote.sh.template
- Updated secret.tar.enc to use abrghost instead of abrgl
  • Loading branch information
xchoo committed Jun 23, 2021
1 parent 15d3b4b commit 5f39391
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 5 deletions.
Binary file modified .ci/secret.tar.enc
Binary file not shown.
22 changes: 20 additions & 2 deletions .nengobones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ travis_yml:
test_args: --test-arg --test-arg
- script: remote
- script: remote-test
- script: remote-slurm-test
- script: test-coverage
env:
TEST_LOCAL_VAR: test local var val
Expand Down Expand Up @@ -98,7 +99,7 @@ ci_scripts:
pre_commands:
- cat .ci/remote.sh
travis_var_key: 2895d60e3414
host: gl
host: abrghost
- template: test
pre_commands:
- cat .ci/test-for-remote.sh
Expand All @@ -110,7 +111,24 @@ ci_scripts:
remote_script: test-for-remote
output_name: remote-test
travis_var_key: 2895d60e3414
host: gl
host: abrghost
coverage: true
- template: remote-script
pre_commands:
- cat .ci/remote-slurm-test.sh
remote_script: test-for-slurm
output_name: remote-slurm-test
travis_var_key: 2895d60e3414
host: abrghost
coverage: true
- template: slurm-script
pre_commands:
- cat .ci/test-for-slurm.sh
slurm_command: "srun -pCI"
wrapped_commands:
- pytest
slurm_script: test-for-remote
output_name: test-for-slurm
coverage: true
- template: docs
pre_commands:
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
-
env:
SCRIPT="remote-test"
-
env:
SCRIPT="remote-slurm-test"
-
env:
TEST_LOCAL_VAR="test local var val"
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Release History
- Added support for changing the main branch name with the ``main_branch``
config option. (`#145`_)
- Added template for ``version.py``. (`#151`_)
- Added support for ``conda install`` in CI scripts (`#152`)
- Added template for running CI scripts through SLURM on remote machines (`#152`)

**Changed**

Expand Down Expand Up @@ -92,6 +94,7 @@ Release History
.. _#144: https://github.com/nengo/nengo-bones/pull/144
.. _#145: https://github.com/nengo/nengo-bones/pull/145
.. _#151: https://github.com/nengo/nengo-bones/pull/151
.. _#152: https://github.com/nengo/nengo-bones/pull/152

0.11.1 (April 13, 2020)
=======================
Expand Down
2 changes: 2 additions & 0 deletions nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def validate_ci_config(ci_config):
"pre_commands",
"post_commands",
"codespell_ignore_words",
"conda_install",
"wrapped_commands",
)
for opt in list_opts:
check_list(ci_config, opt)
Expand Down
10 changes: 7 additions & 3 deletions nengo_bones/templates/base_script.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exe() {
for i in "${!args[@]}"; do
[ -n "${args[$i]}" ] || unset "args[$i]"
done
"${args[@]}" || { echo -e "\033[1;31mCOMMAND '${args[0]}' FAILED\033[0m"; STATUS=1; }
eval '"${args[@]}"' || { echo -e "\033[1;31mCOMMAND '${args[0]}' FAILED\033[0m"; STATUS=1; }
}

if [[ ! -e {{ pkg_name }} ]]; then
Expand All @@ -25,12 +25,16 @@ fi

if [[ "$COMMAND" == "install" ]]; then
{% block install %}
{% if conda_install %}
exe conda install {%- for pkg in conda_install %} "{{ pkg }}" {%- endfor %}

{% endif %}
{% if pip_install %}
exe pip install {%- for pkg in pip_install %} "{{ pkg }}" {%- endfor %}

{% else %}
{% endif %}
{% if not conda_install and not pip_install %}
:

{% endif %}
{% endblock %}
elif [[ "$COMMAND" == "before_script" ]]; then
Expand Down
18 changes: 18 additions & 0 deletions nengo_bones/templates/remote.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ and logged in with `travis login --com`

See https://docs.travis-ci.com/user/encrypting-files/ for more details.


Usage Instructions
==================

This script executes a NengoBones generated CI script on a remote machine.

.nengobones.yml parameters:

`host`: The <hostname> of the remote machine defined in the `config` file above.

`travis_var_key`: The TravisCI variable key as defined in Step 6 of the setup
instructions above.

`remote_script`: The name of the script to be executed on the remote machine. This
script must be defined as a separate entry in the `ci_scripts` section of yml file.

`output_name`: Desired output name of the generated CI script.

#}

{% set pkg = pkg_name | replace("_", "-") %}
Expand Down
76 changes: 76 additions & 0 deletions nengo_bones/templates/slurm-script.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends "templates/base_script.sh.template" %}

{#

Usage Instructions
==================

This script is intended to be used to apply a SLURM wrapper around other NengoBones
generated CI scripts.

.nengobones.yml parameters:

`slurm_command`: The SLURM command used to create the SLURM job. Use quotations to avoid
problems with the space character. Examples:
- "srun"
- "srun -pCI -G1"
- "sbatch"

`wrapped_commands`: A list of commands to be wrapped with `slurm_command`. The command
will be executed as: <slurm_command> <command>
Example, if <slurm_command> is "srun -pCI", and <command> is "pytest", then the command
will be executed as "srun -pCI pytest"

`slurm_script`: The CI script to be executed, but using the SLURM-wrapped commands
instead of the typical non-SLURM invocation.

`output_name`: Desired output name of the generated CI script.

#}

{% block install %}
bash .ci/{{ slurm_script }}.sh install || STATUS=1
{% endblock %}

{% block before_script %}
bash .ci/{{ slurm_script }}.sh before_script || STATUS=1
{% endblock %}

{% block script %}
# Enable `expand_aliases` option for bash interpreter
shopt -s expand_aliases

# Create aliases for commands to include SLURM command prefix
{% for command in wrapped_commands %}
alias {{ command }}="{{ slurm_command }} {{ command }}"
echo "Created alias for {{ command }}: "
type -a {{ command }}

{% endfor %}
# Run script. Use existing shell instead of subshell to ensure alias applies.
. .ci/{{ slurm_script }}.sh script || STATUS=1
{% endblock %}

{% block before_cache %}
bash .ci/{{ slurm_script }}.sh before_cache || STATUS=1
{% endblock %}

{% block after_success %}
bash .ci/{{ slurm_script }}.sh after_success || STATUS=1
{% endblock %}

{% block after_failure %}
bash .ci/{{ slurm_script }}.sh after_failure || STATUS=1
{% endblock %}

{% block before_deploy %}
bash .ci/{{ slurm_script }}.sh before_deploy || STATUS=1
{% endblock %}

{% block after_deploy %}
bash .ci/{{ slurm_script }}.sh after_deploy || STATUS=1
{% endblock %}

{% block after_script %}
bash .ci/{{ slurm_script }}.sh after_script || STATUS=1
{% endblock %}
12 changes: 12 additions & 0 deletions nengo_bones/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ def test_validate_config():
config.validate_config(init_cfg)
test_cfg["pre_commands"] = ["command"]

# error when conda_install is a string instead of list
test_cfg["conda_install"] = "conda_req"
with pytest.raises(TypeError, match="conda_install should be a list"):
config.validate_config(init_cfg)
test_cfg["conda_install"] = ["conda_req"]

# error when wrapped_commands is a string instead of list
test_cfg["wrapped_commands"] = "command"
with pytest.raises(TypeError, match="wrapped_commands should be a list"):
config.validate_config(init_cfg)
test_cfg["wrapped_commands"] = ["command"]

# error when only one of pre_commit_config_yaml or pyproject_toml exists
init_cfg["pyproject_toml"] = {}
with pytest.raises(KeyError, match="must define both"):
Expand Down

0 comments on commit 5f39391

Please sign in to comment.