__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.
This commit is contained in:
parent
8dc6ab9738
commit
2db0ef7c98
2 changed files with 42 additions and 16 deletions
|
@ -17,10 +17,41 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# 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")"
|
distinfo_dir="$("$__type_explorer/distinfo-dir")"
|
||||||
if [ "$distinfo_dir" ]; then
|
|
||||||
# output all extras that are installed
|
# check if we have something to check
|
||||||
awk -F': ' '$1 == "Provides-Extra"{print $2}' "$distinfo_dir/METADATA"
|
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
|
fi
|
||||||
|
|
|
@ -26,7 +26,10 @@
|
||||||
state_is=$(cat "$__object/explorer/state")
|
state_is=$(cat "$__object/explorer/state")
|
||||||
state_should="$(cat "$__object/parameter/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"
|
nameparam="$__object/parameter/name"
|
||||||
if [ -f "$nameparam" ]; then
|
if [ -f "$nameparam" ]; then
|
||||||
|
@ -57,19 +60,11 @@ fi
|
||||||
|
|
||||||
case "$state_should" in
|
case "$state_should" in
|
||||||
present)
|
present)
|
||||||
if [ -f "$__object/parameter/extra" ]
|
if [ -s "$__object/explorer/extras" ]
|
||||||
then
|
then
|
||||||
mkdir "$__object/files"
|
# all extras are passed to pip in a comma-separated list in the name
|
||||||
# sort and generalize all extras
|
# sed loops through all input lines and add commas between them
|
||||||
sed 's/,/\n/g' "$__object/parameter/extra" | sort > "$__object/files/extras-params"
|
extras="$(sed ':a; $!N; s/\n/,/; ta' "$__object/explorer/extras")"
|
||||||
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
|
|
||||||
)"
|
|
||||||
name="${name}[${extras}]"
|
name="${name}[${extras}]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue