horizon/tools/requirements_style_check.sh
ChenZheng 4d6238ceb4 Sort requirement files in alphabetical order
This makes code more readable, and can check whether specific library
in the requirement files easily. We enforce the check in pep8, We also
add the tools for checking requirements.txt and test_requirements.txt.

Change-Id: Ia0a24553b7a5204faf6413c17dae6ba6aae2b5e8
Closes-Bug: #1285478
2014-03-03 10:00:37 +08:00

33 lines
744 B
Bash
Executable File

#!/bin/bash
#
# Enforce the requirement that dependencies are listed in the input
# files in alphabetical order.
# FIXME(dhellmann): This doesn't deal with URL requirements very
# well. We should probably sort those on the egg-name, rather than the
# full line.
function check_file() {
typeset f=$1
# We don't care about comment lines.
grep -v '^#' $f > ${f}.unsorted
sort -i -f ${f}.unsorted > ${f}.sorted
diff -c ${f}.unsorted ${f}.sorted
rc=$?
rm -f ${f}.sorted ${f}.unsorted
return $rc
}
exit_code=0
for filename in $@
do
check_file $filename
if [ $? -ne 0 ]
then
echo "Please list requirements in $filename in alphabetical order" 1>&2
exit_code=1
fi
done
exit $exit_code