2017-04-28 02:47:56 +08:00
|
|
|
#!/bin/bash -e
|
2018-10-08 04:52:23 +08:00
|
|
|
#
|
2025-01-02 22:40:28 +08:00
|
|
|
# Copyright Spack Project Developers. See COPYRIGHT file for details.
|
2018-10-08 04:52:23 +08:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
2017-04-28 02:47:56 +08:00
|
|
|
#
|
|
|
|
# Description:
|
|
|
|
# Common setup code to be sourced by Spack's test scripts.
|
|
|
|
#
|
|
|
|
|
|
|
|
QA_DIR="$(dirname ${BASH_SOURCE[0]})"
|
2018-12-30 04:26:16 +08:00
|
|
|
export SPACK_ROOT=$(realpath "$QA_DIR/../../..")
|
2017-04-28 02:47:56 +08:00
|
|
|
|
|
|
|
# Source the setup script
|
|
|
|
. "$SPACK_ROOT/share/spack/setup-env.sh"
|
|
|
|
|
2019-05-10 14:52:39 +08:00
|
|
|
# by default coverage is off.
|
|
|
|
coverage=""
|
|
|
|
coverage_run=""
|
|
|
|
|
2017-04-28 02:47:56 +08:00
|
|
|
# Set up some variables for running coverage tests.
|
2019-05-10 14:52:39 +08:00
|
|
|
if [[ "$COVERAGE" == "true" ]]; then
|
2018-12-30 04:26:16 +08:00
|
|
|
# these set up coverage for Python
|
2017-04-28 02:47:56 +08:00
|
|
|
coverage=coverage
|
|
|
|
coverage_run="coverage run"
|
2018-12-30 04:26:16 +08:00
|
|
|
|
2020-07-02 00:58:53 +08:00
|
|
|
# bash coverage depends on some other factors
|
|
|
|
mkdir -p coverage
|
|
|
|
bashcov=$(realpath ${QA_DIR}/bashcov)
|
2020-10-27 15:13:09 +08:00
|
|
|
|
|
|
|
# instrument scripts requiring shell coverage
|
2021-08-20 05:03:10 +08:00
|
|
|
sed -i "s@#\!/bin/bash@#\!${bashcov}@" "$SPACK_ROOT/lib/spack/env/cc"
|
2020-10-27 15:13:09 +08:00
|
|
|
if [ "$(uname -o)" != "Darwin" ]; then
|
|
|
|
# On darwin, #! interpreters must be binaries, so no sbang for bashcov
|
2021-08-20 05:03:10 +08:00
|
|
|
sed -i "s@#\!/bin/sh@#\!${bashcov}@" "$SPACK_ROOT/bin/sbang"
|
2020-10-27 15:13:09 +08:00
|
|
|
fi
|
2017-04-28 02:47:56 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
check_dependencies() {
|
|
|
|
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
|
|
|
|
;;
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
mypy)
|
|
|
|
spack_package=py-mypy
|
|
|
|
pip_package=mypy
|
|
|
|
;;
|
2017-04-28 02:47:56 +08:00
|
|
|
dot)
|
|
|
|
spack_package=graphviz
|
|
|
|
;;
|
|
|
|
git)
|
|
|
|
spack_package=git
|
|
|
|
;;
|
|
|
|
hg)
|
|
|
|
spack_package=mercurial
|
|
|
|
pip_package=mercurial
|
|
|
|
;;
|
2020-07-02 00:58:53 +08:00
|
|
|
kcov)
|
|
|
|
spack_package=kcov
|
|
|
|
;;
|
2017-04-28 02:47:56 +08:00
|
|
|
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."
|
|
|
|
}
|