Commit 8f2f68a3 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm-restore: rewrite to more full support of python arrays, add python_dependencies.py support

parent 2f9e6808
...@@ -27,11 +27,14 @@ __epm_filter_pip_to_rpm() ...@@ -27,11 +27,14 @@ __epm_filter_pip_to_rpm()
{ {
tr "A-Z" "a-z" | sed -e "s|-|_|g" -e "s|^python_||" \ tr "A-Z" "a-z" | sed -e "s|-|_|g" -e "s|^python_||" \
-e "s|beautifulsoup4|bs4|" \ -e "s|beautifulsoup4|bs4|" \
-e "s|pillow|PIL|" \ -e "s|pillow|Pillow|" \
-e "s|redis|redis-py|" \ -e "s|redis|redis-py|" \
-e "s|pyjwt|jwt|" \ -e "s|pyjwt|jwt|" \
-e "s|pymonetdb|monetdb|" \
-e "s|pyyaml|yaml|" \ -e "s|pyyaml|yaml|" \
-e "s|attrs|attr|" \ -e "s|twisted|twisted-core|" \
-e "s|pymacaroons|pymacaroons-pynacl|" \
-e "s|pyasn1_modules|pyasn1-modules|" \
-e "s|pygments|Pygments|" \ -e "s|pygments|Pygments|" \
-e "s|patch_ng|patch-ng|" \ -e "s|patch_ng|patch-ng|" \
-e "s|memcached|memcache|" \ -e "s|memcached|memcache|" \
...@@ -49,11 +52,10 @@ fill_sign() ...@@ -49,11 +52,10 @@ fill_sign()
# macro pkg caseline # macro pkg caseline
__epm_pi_sign_to_rpm() __epm_pi_sign_to_rpm()
{ {
local reqmacro="$1" local t="$1"
local t="$2" local l="$2"
local l="$3" local equal="$3"
local equal="$4" [ -n "$equal" ] || equal=">="
[ -n "$equal" ] || equal="="
local pi='' local pi=''
local sign ll local sign ll
...@@ -64,28 +66,37 @@ __epm_pi_sign_to_rpm() ...@@ -64,28 +66,37 @@ __epm_pi_sign_to_rpm()
[ "$sign" = "!=" ] && sign=">=" [ "$sign" = "!=" ] && sign=">="
[ -n "$pi" ] && pi="$pi [ -n "$pi" ] && pi="$pi
" "
pi="$pi$reqmacro $t $sign $ll" pi="$pi$t $sign $ll"
done done
[ -n "$pi" ] || pi="$reqmacro $t" [ -n "$pi" ] || pi="$t"
echo "$pi" echo "$pi"
} }
__epm_restore_pip() __epm_get_array_name()
{ {
local req_file="$1" echo "$*" | grep "=" | head -n1 | sed -e 's| *=.*||'
if [ -n "$dryrun" ] ; then }
echo
echo "# generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file"
else
info "Install requirements from $req_file ..."
fi
local ilist='' __epm_lineprint_python_array()
{
local a="$*"
[ -n "$a" ] || return
local name="$(__epm_get_array_name "$a")"
(echo "$a" | sed -e 's|\].*|]|' ; echo "print('\n'.join($name))" ) | ( a= python - || a= python3 )
}
# translate pip requirement lines to rpm notation
# (compare signs and package names)
__epm_restore_convert_to_rpm_notation()
{
local equal="$1"
local l
while read l ; do while read l ; do
local t="$(echo "$l" | sed -e "s| *[<>!]*=.*||" -e "s| *#.*||" | __epm_filter_pip_to_rpm)" local t="$(echo "$l" | sed -e "s| *[<>!]*=.*||" -e "s| *#.*||" | __epm_filter_pip_to_rpm)"
if echo "$l" | grep -qE "^ *#" || [ -z "$l" ] ; then if echo "$l" | grep -qE "^ *#" || [ -z "$l" ] ; then
continue continue
fi fi
[ -n "$t" ] || continue
# until new section # until new section
if echo "$l" | grep -qE "^\[" ; then if echo "$l" | grep -qE "^\[" ; then
break break
...@@ -103,28 +114,37 @@ __epm_restore_pip() ...@@ -103,28 +114,37 @@ __epm_restore_pip()
warning " $t is python2 only requirement, skipped" warning " $t is python2 only requirement, skipped"
continue continue
fi fi
[ -n "$t" ] || continue __epm_pi_sign_to_rpm "$t" "$l" "$equal"
if [ -n "$dryrun" ] ; then done
local reqmacro="%py3_use" }
[ "$(basename "$req_file")" = "requirements_dev.txt" ] && reqmacro="%py3_buildrequires"
__epm_pi_sign_to_rpm $reqmacro $t $l __epm_restore_pip()
continue {
else local req_file="$1"
# TODO: python3-egg-info($t) local reqmacro
local pi="python3($t)" local ilist
echo " $l -> $t -> $pi"
fi
ilist="$ilist $pi"
done < $req_file
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
echo "$ilist" reqmacro="%py3_use"
[ "$(basename "$req_file")" = "requirements_dev.txt" ] && reqmacro="%py3_buildrequires"
echo
echo "# generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file"
cat $req_file | __epm_restore_convert_to_rpm_notation | sed -e "s|^|$reqmacro |"
return return
else
info "Install requirements from $req_file ..."
ilist="$(cat $req_file | __epm_restore_convert_to_rpm_notation | cut -d' ' -f 1 | sed -e "s|^|python3-module-|")"
fi fi
ilist="$(estrlist list $ilist)"
docmd epm install $ilist docmd epm install $ilist
} }
__eresection()
{
rhas "$1" "[[:space:]]*$2[[:space:]]*=[[:space:]]*\["
}
__epm_restore_setup_py() __epm_restore_setup_py()
{ {
local req_file="$1" local req_file="$1"
...@@ -132,55 +152,57 @@ __epm_restore_setup_py() ...@@ -132,55 +152,57 @@ __epm_restore_setup_py()
info "Install requirements from $req_file ..." info "Install requirements from $req_file ..."
fi fi
local ar=''
local ilist='' local ilist=''
local fr fd
local reqmacro local reqmacro
local section=''
while read l ; do while read l ; do
if rhas "$l" "^ *#" ; then if rhas "$l" "^ *#" ; then
continue continue
fi fi
if rhas "$l" "\]," ; then # start of section
fr='' if __eresection "$l" "REQUIREMENTS" ; then
fd='' reqmacro="%py3_use"
continue section="$l"
fi
if [ -n "$fr$fd" ] ; then
local ll="$(echo "$l" | sed -e "s|[[:space:]]*'||" -e "s|'.*||")"
local t="$(echo "$ll" | sed -e "s| *[<>!]*=.*||" | __epm_filter_pip_to_rpm)"
if [ -n "$dryrun" ] ; then
__epm_pi_sign_to_rpm $reqmacro $t $ll ">="
else
local pi="python3-module-$t"
ilist="$ilist $pi"
echo " $l -> $t -> $pi"
fi
continue
fi fi
if rhas "$l" "install_requires=\[" ; then if __eresection "$l" "install_requires" ; then
reqmacro="%py3_use" reqmacro="%py3_use"
if [ -n "$dryrun" ] ; then section="$l"
echo
echo "# generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file $l"
fi
fr=1
continue
fi fi
if rhas "$l" "tests_require=\[" ; then if __eresection "$l" "setup_requires" ; then
reqmacro="%py3_buildrequires" reqmacro="%py3_buildrequires"
if [ -n "$dryrun" ] ; then section="$l"
echo fi
echo "# generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file $l" if __eresection "$l" "tests_require" ; then
fi reqmacro="%py3_buildrequires"
fd=1 section="$l"
fi
if [ -n "$section" ] ; then
ar="$ar
$l"
fi
# not end of section
if [ -z "$section" ] || ! rhas "$l" "\],*" ; then
continue continue
fi fi
if [ -n "$dryrun" ] ; then
echo
echo "# generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file $(__epm_get_array_name "$section")"
__epm_lineprint_python_array "$ar" | __epm_restore_convert_to_rpm_notation ">=" | sed -e "s|^|$reqmacro |"
else
ilist="$ilist $(__epm_lineprint_python_array "$ar" | __epm_restore_convert_to_rpm_notation ">=" | cut -d' ' -f 1 | sed -e "s|^|python3-module-|")"
fi
section=''
ar=''
done < $req_file done < $req_file
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
echo "$ilist"
return return
fi fi
ilist="$(estrlist list $ilist)"
docmd epm install $ilist docmd epm install $ilist
} }
...@@ -276,7 +298,7 @@ __epm_restore_by() ...@@ -276,7 +298,7 @@ __epm_restore_by()
requirements.txt|requirements_dev.txt|requires.txt) requirements.txt|requirements_dev.txt|requires.txt)
[ -s "$req_file" ] && __epm_restore_pip "$req_file" [ -s "$req_file" ] && __epm_restore_pip "$req_file"
;; ;;
setup.py) setup.py|python_dependencies.py)
[ -s "$req_file" ] && __epm_restore_setup_py "$req_file" [ -s "$req_file" ] && __epm_restore_setup_py "$req_file"
;; ;;
package.json) package.json)
...@@ -308,7 +330,7 @@ epm_restore() ...@@ -308,7 +330,7 @@ epm_restore()
# TODO: nowhere works: python3 setup.py --requires # TODO: nowhere works: python3 setup.py --requires
# if run with empty args # if run with empty args
for i in requirements.txt requirements_dev.txt Gemfile requires.txt package.json setup.py; do for i in requirements.txt requirements_dev.txt Gemfile requires.txt package.json setup.py python_dependencies.py; do
__epm_restore_by $i __epm_restore_by $i
done done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment