forked from ungleich-public/cdist
Merge branch 'feature/__package_pip/extras' into 'master'
__package_pip: add optional (extra) dependencies See merge request ungleich-public/cdist!975
This commit is contained in:
commit
6358885d26
6 changed files with 149 additions and 6 deletions
45
cdist/conf/type/__package_pip/explorer/distinfo-dir
Executable file
45
cdist/conf/type/__package_pip/explorer/distinfo-dir
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2021 Matthias Stecher (matthiasstecher at gmx.de)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
nameparam="$__object/parameter/name"
|
||||
if [ -f "$nameparam" ]; then
|
||||
name=$(cat "$nameparam")
|
||||
else
|
||||
name="$__object_id"
|
||||
fi
|
||||
|
||||
pipparam="$__object/parameter/pip"
|
||||
if [ -f "$pipparam" ]; then
|
||||
pip=$(cat "$pipparam")
|
||||
else
|
||||
pip="$( "$__type_explorer/pip" )"
|
||||
fi
|
||||
|
||||
|
||||
if command -v "$pip" >/dev/null 2>&1; then
|
||||
# assemble the path where pip stores all pip package info
|
||||
"$pip" show "$name" \
|
||||
| awk -F': ' '
|
||||
$1 == "Name" {name=$2; gsub(/-/,"_",name); next}
|
||||
$1 == "Version" {version=$2; next}
|
||||
$1 == "Location" {location=$2; next}
|
||||
END {if (version != "") printf "%s/%s-%s.dist-info", location, name, version}'
|
||||
fi
|
66
cdist/conf/type/__package_pip/explorer/extras
Executable file
66
cdist/conf/type/__package_pip/explorer/extras
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2021 Matthias Stecher (matthiasstecher at gmx.de)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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")"
|
||||
|
||||
# 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"
|
||||
|
||||
# If all is set, it searches all available extras to separatly check them.
|
||||
# It would work with just 'all' (cause dependencies are specified for
|
||||
# 'all'), but will not update if one extra is already present. Side effect
|
||||
# is that it will not use [all] but instead name all extras seperatly.
|
||||
for extra in $(if grep -qFx all "$__object/parameter/extra";
|
||||
then awk -F': ' '$1 == "Provides-Extra" && $2 != "all"{print $2}' "$distinfo_dir/METADATA";
|
||||
else tr ',' '\n' < "$__object/parameter/extra";
|
||||
fi)
|
||||
do
|
||||
# create a grep BRE pattern to search all packages
|
||||
# maybe a file full of patterns for -F could be written
|
||||
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 ;-)
|
||||
# pip matches packages case-insensetive, we need to do that, too
|
||||
if [ "$grep_pattern" ] && ! grep -qi "$grep_pattern" "$pip_freeze"
|
||||
then
|
||||
echo "$extra"
|
||||
fi
|
||||
done
|
||||
fi
|
0
cdist/conf/type/__package_pip/explorer/state
Normal file → Executable file
0
cdist/conf/type/__package_pip/explorer/state
Normal file → Executable file
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
# 2016 Darko Poljak (darko.poljak at gmail.com)
|
||||
# 2021 Matthias Stecher (matthiasstecher at gmx.de)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -25,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
|
||||
|
@ -56,6 +60,14 @@ fi
|
|||
|
||||
case "$state_should" in
|
||||
present)
|
||||
if [ -s "$__object/explorer/extras" ]
|
||||
then
|
||||
# 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
|
||||
|
||||
if [ "$runas" ]
|
||||
then
|
||||
echo "su -c '$pip install -q $name' $runas"
|
||||
|
|
|
@ -22,6 +22,16 @@ OPTIONAL PARAMETERS
|
|||
name
|
||||
If supplied, use the name and not the object id as the package name.
|
||||
|
||||
extra
|
||||
Extra optional dependencies which should be installed along the selected
|
||||
package. Can be specified multiple times. Multiple extras can be passed
|
||||
in one `--extra` as a comma-separated list.
|
||||
|
||||
Extra optional dependencies will be installed even when the base package
|
||||
is already installed. Notice that the type will not remove installed extras
|
||||
that are not explicitly named for the type because pip does not offer a
|
||||
management for orphaned packages and they may be used by other packages.
|
||||
|
||||
pip
|
||||
Instead of using pip from PATH, use the specific pip path.
|
||||
|
||||
|
@ -46,6 +56,14 @@ EXAMPLES
|
|||
# Use pip in a virtualenv located at /foo/shinken_virtualenv as user foo
|
||||
__package_pip pyro --state present --pip /foo/shinken_virtualenv/bin/pip --runas foo
|
||||
|
||||
# Install package with optional dependencies
|
||||
__package_pip mautrix-telegram --extra speedups --extra webp_convert --extra hq_thumbnails
|
||||
# the extras can also be specified comma-separated
|
||||
__package_pip mautrix-telegram --extra speedups,webp_convert,hq_thumbnails --extra postgres
|
||||
|
||||
# or take all extras
|
||||
__package_pip mautrix-telegram --extra all
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
|
@ -54,12 +72,13 @@ SEE ALSO
|
|||
|
||||
AUTHORS
|
||||
-------
|
||||
Nico Schottelius <nico-cdist--@--schottelius.org>
|
||||
| Nico Schottelius <nico-cdist--@--schottelius.org>
|
||||
| Matthias Stecher <matthiasstecher--@--gmx.de>
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2012 Nico Schottelius. You can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
Copyright \(C) 2012 Nico Schottelius, 2021 Matthias Stecher. You can
|
||||
redistribute it and/or modify it under the terms of the GNU General
|
||||
Public License as published by the Free Software Foundation, either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
extra
|
Loading…
Reference in a new issue