-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_license_check.sh
54 lines (45 loc) · 1.7 KB
/
run_license_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# This script provides a wrapper to easily run the license checker.
# You can either provide a single module using -m, or a file with a list of modules using -mf
# If nothing is provided, the license checker runs on the working directory
# Saner programming env: these switches turn some bugs into errors
set -o errexit -o pipefail -o noclobber -o nounset
# Argument parsing
while [[ "$#" -gt 0 ]]; do case $1 in
-m|--module) module="$2"; shift;;
-mf|--modules-file) modules_file="$2"; shift;;
*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done
# Build the list of modules to check from the input arguments
if [ -n "${module-}" ] && [ -n "${modules_file-}" ]; then
echo "Both a module and modules_file were provided. Please only provide one."
exit 1
elif [ -n "${module-}" ]; then
MODULES=("${module}")
elif [ -n "${modules_file-}" ]; then
# List all modules in pylint-modules
MODULES=()
dir_name="$(dirname "${modules_file}")"
while IFS= read -r line || [[ "$line" ]]; do
MODULES+=("${dir_name}/${line}");
done < "${modules_file}"
else
MODULES=(".")
fi
echo "Running license check for modules ${MODULES[@]}"
echo
# Install pip-tools for pip-compile but suppress stdout
pip install pip-tools > /dev/null
for module in "${MODULES[@]}"; do
echo "Checking ${module}"
# Try setup.py if it exists, otherwise requirements.txt
if [ -e "${module%/}"/setup.py ]
then
file="${module%/}"/setup.py
else
file="${module%/}"/requirements.txt
fi
echo "Using ${file}"
pip-compile "${file}" -q -o /tmp/requirements.txt
license_check -r /tmp/requirements.txt
done