Browse Source

__package_pip: updating real detection of extras

As the previous detection took the wrong values, this explorer now
checks if packages for an extra are installed or not. If not, the extra
is not installed.

Based on the information of the explorer, it will install the package
again with the absent extras.
feature/type-relationship-graph
matze 1 year ago
parent
commit
2db0ef7c98
  1. 37
      cdist/conf/type/__package_pip/explorer/extras
  2. 21
      cdist/conf/type/__package_pip/gencode-remote

37
cdist/conf/type/__package_pip/explorer/extras vendored

@ -17,10 +17,41 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Checks if the given extras are really installed or not. It will be
# done by querring all dependencies for that extra and return it as
# "to be installed" if no dependency was found.
#
distinfo_dir="$("$__type_explorer/distinfo-dir")"
if [ "$distinfo_dir" ]; then
# output all extras that are installed
awk -F': ' '$1 == "Provides-Extra"{print $2}' "$distinfo_dir/METADATA"
# check if we have something to check
if [ "$distinfo_dir" ] && [ -s "$__object/parameter/extra" ]
then
# save cause freezing is slow
mkdir "$__object/files"
pip_freeze="$__object/files/pip-freeze.tmp"
pip3 freeze > "$pip_freeze"
for extra in $(cat "$__object/parameter/extra" | tr ',' '\n')
do
# create a grep BRE pattern to search all packages
grep_pattern="$(
awk -F'(: | ; )' -v check="$extra" '
$1 == "Requires-Dist" {
split($2, r, " ");
sub("extra == ", "", $3); gsub("'"'"'", "", $3);
if($3 == check) print r[1]
}' "$distinfo_dir/METADATA" \
| sed ':a; $!N; s/\n/\\|/; ta'
)"
# echo the extra if no packages where found for it
# if there is no pattern, we don't need to search ;-)
if [ "$grep_pattern" ] && ! grep -q "$grep_pattern" "$pip_freeze"
then
echo "$extra"
fi
done
fi

21
cdist/conf/type/__package_pip/gencode-remote vendored

@ -26,7 +26,10 @@
state_is=$(cat "$__object/explorer/state")
state_should="$(cat "$__object/parameter/state")"
[ "$state_is" = "$state_should" ] && exit 0
# short circuit if state is the same and no extras to install
[ "$state_is" = "$state_should" ] && ! [ -s "$__object/explorer/extras" ] \
&& exit 0
nameparam="$__object/parameter/name"
if [ -f "$nameparam" ]; then
@ -57,19 +60,11 @@ fi
case "$state_should" in
present)
if [ -f "$__object/parameter/extra" ]
if [ -s "$__object/explorer/extras" ]
then
mkdir "$__object/files"
# sort and generalize all extras
sed 's/,/\n/g' "$__object/parameter/extra" | sort > "$__object/files/extras-params"
sort "$__object/explorer/extras" > "$__object/files/extras-explorer"
# assemble extras
# all extras are passed to pip in a comma-separated list
extras="$(comm -23 \
"$__object/files/extras-params" "$__object/files/extras-explorer" \
| sed ':a; $!N; s/\n/,/; ta' # loops through all input lines and add commas between them
)"
# all extras are passed to pip in a comma-separated list in the name
# sed loops through all input lines and add commas between them
extras="$(sed ':a; $!N; s/\n/,/; ta' "$__object/explorer/extras")"
name="${name}[${extras}]"
fi

Loading…
Cancel
Save