diff options
Diffstat (limited to 'share')
-rw-r--r-- | share/spack/csh/spack.csh | 8 | ||||
-rwxr-xr-x | share/spack/qa/check_dependencies | 96 | ||||
-rwxr-xr-x | share/spack/qa/run-doc-tests | 41 | ||||
-rwxr-xr-x | share/spack/qa/run-flake8 | 55 | ||||
-rwxr-xr-x | share/spack/qa/run-flake8-tests | 29 | ||||
-rwxr-xr-x | share/spack/qa/run-unit-tests | 51 | ||||
-rwxr-xr-x | share/spack/setup-env.sh | 34 |
7 files changed, 245 insertions, 69 deletions
diff --git a/share/spack/csh/spack.csh b/share/spack/csh/spack.csh index d64ce8935b..5acd190449 100644 --- a/share/spack/csh/spack.csh +++ b/share/spack/csh/spack.csh @@ -74,25 +74,25 @@ case unload: # tool's commands to add/remove the result from the environment. switch ($_sp_subcommand) case "use": - set _sp_full_spec = ( "`\spack $_sp_flags module find dotkit $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type dotkit $_sp_spec`" ) if ( $? == 0 ) then use $_sp_module_args $_sp_full_spec endif breaksw case "unuse": - set _sp_full_spec = ( "`\spack $_sp_flags module find dotkit $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type dotkit $_sp_spec`" ) if ( $? == 0 ) then unuse $_sp_module_args $_sp_full_spec endif breaksw case "load": - set _sp_full_spec = ( "`\spack $_sp_flags module find tcl $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type tcl $_sp_spec`" ) if ( $? == 0 ) then module load $_sp_module_args $_sp_full_spec endif breaksw case "unload": - set _sp_full_spec = ( "`\spack $_sp_flags module find tcl $_sp_spec`" ) + set _sp_full_spec = ( "`\spack $_sp_flags module find --module-type tcl $_sp_spec`" ) if ( $? == 0 ) then module unload $_sp_module_args $_sp_full_spec endif diff --git a/share/spack/qa/check_dependencies b/share/spack/qa/check_dependencies new file mode 100755 index 0000000000..e999463b03 --- /dev/null +++ b/share/spack/qa/check_dependencies @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +# +# Description: +# Check to see if dependencies are installed. +# If not, warn the user and tell them how to +# install these dependencies. +# +# Usage: +# check-deps <dep> ... +# +# Options: +# One or more dependencies. Must use name of binary. + +for dep in "$@"; do + if ! which $dep &> /dev/null; then + # Map binary name to package name + case $dep in + sphinx-apidoc|sphinx-build) + spack_package=py-sphinx + pip_package=sphinx + ;; + coverage) + spack_package=py-coverage + pip_package=coverage + ;; + flake8) + spack_package=py-flake8 + pip_package=flake8 + ;; + dot) + spack_package=graphviz + ;; + git) + spack_package=git + ;; + hg) + spack_package=mercurial + pip_package=mercurial + ;; + svn) + spack_package=subversion + ;; + *) + spack_package=$dep + pip_package=$dep + ;; + esac + + echo "ERROR: $dep is required to run this script." + echo + + if [[ $spack_package ]]; then + echo "To install with Spack, run:" + echo " $ spack install $spack_package" + fi + + if [[ $pip_package ]]; then + echo "To install with pip, run:" + echo " $ pip install $pip_package" + fi + + if [[ $spack_package || $pip_package ]]; then + echo "Then add the bin directory to your PATH." + fi + + exit 1 + fi + + # Flake8 and Sphinx require setuptools in order to run. + # Otherwise, they print out this error message: + # + # Traceback (most recent call last): + # File: "/usr/bin/flake8", line 5, in <module> + # from pkg_resources import load_entry_point + # ImportError: No module named pkg_resources + # + # Print a more useful error message if setuptools not found. + if [[ $dep == flake8 || $dep == sphinx* ]]; then + # Find which Python is being run + # Spack-installed packages have a hard-coded shebang + python_cmd=$(head -n 1 $(which $dep) | cut -c 3-) + # May not have a shebang + if [[ $python_cmd != *python* ]]; then + python_cmd=python + fi + # Check if setuptools is in the PYTHONPATH + if ! $python_cmd -c "import setuptools" 2> /dev/null; then + echo "ERROR: setuptools is required to run $dep." + echo "Please add it to your PYTHONPATH." + + exit 1 + fi + fi +done + +echo "Dependencies found." diff --git a/share/spack/qa/run-doc-tests b/share/spack/qa/run-doc-tests new file mode 100755 index 0000000000..ca892d7eb4 --- /dev/null +++ b/share/spack/qa/run-doc-tests @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# Description: +# Builds Spack documentation and checks for +# possible syntax errors. Treats warnings as +# fatal errors. +# +# Usage: +# run-doc-tests +# +# Notes: +# Requires sphinx, graphviz, git, mercurial, and subversion. +# + +QA_DIR="$(dirname "$0")" +SPACK_ROOT="$QA_DIR/../../.." +DOC_DIR="$SPACK_ROOT/lib/spack/docs" + +# Array of dependencies +deps=( + sphinx-apidoc + sphinx-build + dot + git + hg + svn +) + +# Check for dependencies +"$QA_DIR/check_dependencies" "${deps[@]}" || exit 1 + +# Add Spack to the PATH. +export PATH="$SPACK_ROOT/bin:$PATH" + +# Move to documentation directory +# Allows script to be run from anywhere +cd "$DOC_DIR" + +# Treat warnings as fatal errors +make clean --silent +make SPHINXOPTS=-W JOBS=1 diff --git a/share/spack/qa/run-flake8 b/share/spack/qa/run-flake8 deleted file mode 100755 index 722c7fcba6..0000000000 --- a/share/spack/qa/run-flake8 +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# -# This script runs source code style checks on Spack. -# -# It should be executed from the top-level directory of the repo, -# e.g.: -# -# share/spack/qa/run-flake8 -# -# To run it, you'll need to have the Python flake8 installed locally. -# -PYTHONPATH=./lib/spack:$PYTHONPATH - -flake8="$(which flake8)" -if [[ ! $flake8 ]]; then - echo "ERROR: flake8 is required to run this script." - exit 1 -fi - -# Check if changed files are flake8 conformant [framework] -changed=$(git diff --name-only develop... | grep '.py$') - -# Exempt url lines in changed packages from overlong line errors. -for file in $changed; do - if [[ $file = *package.py ]]; then - perl -i~ -pe 's/^(\s*url\s*=.*)$/\1 # NOQA: ignore=E501/' $file; - fi -done - -return_code=0 -if [[ $changed ]]; then - echo ======================================================= - echo flake8: running flake8 code checks on spack. - echo - echo Modified files: - echo $changed | perl -pe 's/^/ /;s/ +/\n /g' - echo ======================================================= - if flake8 --format pylint $changed; then - echo "Flake8 checks were clean." - else - echo "Flake8 found errors." - return_code=1 - fi -else - echo No core framework files modified. -fi - -# Restore original package files after modifying them. -for file in $changed; do - if [[ $file = *package.py ]]; then - mv "${file}~" "${file}" - fi -done - -exit $return_code diff --git a/share/spack/qa/run-flake8-tests b/share/spack/qa/run-flake8-tests new file mode 100755 index 0000000000..83469eeb9d --- /dev/null +++ b/share/spack/qa/run-flake8-tests @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# Description: +# Runs source code style checks on Spack. +# See $SPACK_ROOT/.flake8 for a list of +# approved exceptions. +# +# Usage: +# run-flake8-tests +# +# Notes: +# Requires flake8. +# + +QA_DIR="$(dirname "$0")" +SPACK_ROOT="$QA_DIR/../../.." + +# Array of dependencies +deps=( + flake8 +) + +# Check for dependencies +"$QA_DIR/check_dependencies" "${deps[@]}" || exit 1 + +# Add Spack to the PATH. +export PATH="$SPACK_ROOT/bin:$PATH" + +exec spack flake8 diff --git a/share/spack/qa/run-unit-tests b/share/spack/qa/run-unit-tests new file mode 100755 index 0000000000..d2ce9647af --- /dev/null +++ b/share/spack/qa/run-unit-tests @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Description: +# Runs Spack unit tests. +# +# Usage: +# run-unit-tests [test ...] +# +# Options: +# Optionally add one or more unit tests +# to only run these tests. +# +# Notes: +# Requires coverage, git, mercurial, and subversion. +# + +QA_DIR="$(dirname "$0")" +SPACK_ROOT="$QA_DIR/../../.." + +# Array of dependencies +deps=( + coverage + git + hg + svn +) + +# Check for dependencies +"$QA_DIR/check_dependencies" "${deps[@]}" || exit 1 + +# Add Spack to the PATH. +export PATH="$SPACK_ROOT/bin:$PATH" + +# Move to root directory of Spack +# Allows script to be run from anywhere +cd "$SPACK_ROOT" + +# Run integration tests +# TODO: should these be separated into a different test suite? +source "$SPACK_ROOT/share/spack/setup-env.sh" +spack compilers +spack config get compilers + +# Run unit tests with code coverage +if [[ "$TRAVIS_PYTHON_VERSION" == 2.7 ]]; then + coverage run bin/spack install -v libdwarf + coverage run bin/spack test "$@" && coverage combine +else + spack install -v libdwarf + spack test "$@" +fi diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index 8aa259cf15..943db72612 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -57,6 +57,11 @@ ######################################################################## function spack { + # Zsh does not do word splitting by default, this enables it for this function only + if [ -n "${ZSH_VERSION:-}" ]; then + emulate -L sh + fi + # save raw arguments into an array before butchering them args=( "$@" ) @@ -93,11 +98,18 @@ function spack { ;; "use"|"unuse"|"load"|"unload") # Shift any other args for use off before parsing spec. + _sp_subcommand_args="" _sp_module_args="" - if [[ "$1" =~ ^- ]]; then - _sp_module_args="$1"; shift - _sp_spec="$@" - fi + while [[ "$1" =~ ^- ]]; do + if [ "$1" = "-r" -o "$1" = "--dependencies" ]; then + _sp_subcommand_args="$_sp_subcommand_args $1" + else + _sp_module_args="$_sp_module_args $1" + fi + shift + done + + _sp_spec="$@" # Here the user has run use or unuse with a spec. Find a matching # spec using 'spack module find', then use the appropriate module @@ -105,19 +117,19 @@ function spack { # If spack module command comes back with an error, do nothing. case $_sp_subcommand in "use") - if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type dotkit $_sp_spec); then use $_sp_module_args $_sp_full_spec fi ;; "unuse") - if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type dotkit $_sp_spec); then unuse $_sp_module_args $_sp_full_spec fi ;; "load") - if _sp_full_spec=$(command spack $_sp_flags module find tcl $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type tcl $_sp_spec); then module load $_sp_module_args $_sp_full_spec fi ;; "unload") - if _sp_full_spec=$(command spack $_sp_flags module find tcl $_sp_spec); then + if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type tcl $_sp_spec); then module unload $_sp_module_args $_sp_full_spec fi ;; esac @@ -177,5 +189,7 @@ _sp_prefix=$(cd "$(dirname $(dirname $_sp_share_dir))" && pwd) _spack_pathadd PATH "${_sp_prefix%/}/bin" _sp_sys_type=$(spack-python -c 'print(spack.architecture.sys_type())') -_spack_pathadd DK_NODE "${_sp_share_dir%/}/dotkit/$_sp_sys_type" -_spack_pathadd MODULEPATH "${_sp_share_dir%/}/modules/$_sp_sys_type" +_sp_dotkit_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('dotkit')))") +_sp_tcl_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('tcl')))") +_spack_pathadd DK_NODE "${_sp_dotkit_root%/}/$_sp_sys_type" +_spack_pathadd MODULEPATH "${_sp_tcl_root%/}/$_sp_sys_type" |