77# - For everything *not* in use by HA-core we still would want dependabot to kick in appropriately
88# - This script will exit with error if it finds 'unversioned' dependencies (as such should be part of our CI)
99
10+ # Default to non-error
11+ exitcode=0
12+
1013# Use local tmp
1114if [ ! -d ./tmp ]; then
1215 mkdir -p ./tmp/urls
@@ -27,12 +30,16 @@ packages=$(grep -hEv "^$|^#|^\-e" ./requirements*.txt | cut -f 1 -d '=' | sort -
2730
2831# Check for local defined packages against upstream
2932pkglist=" ./tmp/pkglist"
33+ pkgredundant=" ./tmp/pkgredundant"
3034true > " ${pkglist} "
35+ true > " ${pkgredundant} "
3136for pkg in ${packages} ; do
3237 # shellcheck disable=SC2046,SC2143
3338 if [ ! $( grep -rhE " ^${pkg} " ./tmp/urls) ]; then
3439# echo "${pkg} not in upstream requirements/constraints"
3540 echo " ${pkg} " >> " ${pkglist} "
41+ else
42+ echo " ${pkg} " >> " ${pkgredundant} "
3643 fi
3744done
3845
@@ -48,13 +55,53 @@ for pkg in $(sort -u ${pkglist}); do
4855 fi
4956done
5057
58+ # Check for versioning in setup.py
59+ pkgpy=$( sed -n ' /install_requires=\[/,/\]/p' setup.py | tr -d ' \n' | sed ' s/^.*\[\(.*\)\].*$/\1/g' | tr -d ' ,"' )
60+ for pkgfull in ${pkgpy} ; do
61+ # Very ugly multi-character split
62+ # shellcheck disable=SC3011
63+ pkg=$( cut -d ' =' -f 1 <<< " ${pkgfull}" | cut -d ' <' -f 1 | cut -d ' >' -f 1)
64+ # shellcheck disable=SC2046,SC2143
65+ if [ ! $( grep -qrhE " ^${pkg} " ./tmp/urls) ]; then
66+ # echo "DEBUG: ${pkg} from setup.py not in upstream requirements/constraints"
67+ if [ ! $( grep -rhE " ^${pkg} ==" ./requirements* .txt) ]; then
68+ # echo "DEBUG: ${pkg} from setup.py not in local requirements"
69+ # shellcheck disable=SC3014
70+ if [ " ${pkg} " == " ${pkgfull} " ]; then
71+ echo " WARNING: ${pkg} not in any requirements and no version specified in setup.py"
72+ # else
73+ # echo "DEBUG: ${pkg} version specified in setup.py"
74+ fi
75+ # else
76+ # echo "DEBUG: ${pkg} found in local requirements"
77+ fi
78+ # else
79+ # echo "DEBUG: ${pkg} found in upstream URLs"
80+ fi
81+ done
82+ echo " "
83+
84+ # Print redundant information (no error value)
85+ # shellcheck disable=SC2046
86+ # if [ $(wc -l "${pkgmiss}" | awk '{print $1}') -gt 0 ]; then
87+ echo " INFO: Packages redundant with upstream:"
88+ # shellcheck disable=SC2013
89+ for pkg in $( sort -u ${pkgredundant} ) ; do
90+ echo " INFO: ${pkg} in ($( grep -hlE " ^${pkg} " ./requirements* .txt) ) already avavilable via $( grep -rhlE " ^${pkg} " ./tmp/urls/) "
91+ done
92+ echo " "
93+ # fi
94+
5195# Print missing information and exit error out
5296# shellcheck disable=SC2046
5397if [ $( wc -l " ${pkgmiss} " | awk ' {print $1}' ) -gt 0 ]; then
54- echo " Packages missing from local requirements_*.txt files:"
98+ echo " ERROR: Packages missing from local requirements_*.txt files:"
5599 # shellcheck disable=SC2013
56100 for pkg in $( sort -u ${pkgmiss} ) ; do
57- echo " ${pkg} in $( grep -hlE " ^${pkg} " ./requirements* .txt) missing version information"
101+ echo " INFO: ${pkg} in $( grep -hlE " ^${pkg} " ./requirements* .txt) missing version information"
58102 done
59- exit 1
103+ echo " "
104+ exitcode=1
60105fi
106+
107+ exit ${exitcode}
0 commit comments