Commit ab204fc3 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm restore: add requirements/ dir support

parent 9c497ea9
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2020 Etersoft # Copyright (C) 2021 Etersoft
# Copyright (C) 2020 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2021 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
load_helper epm-sh-altlinux load_helper epm-sh-altlinux
load_helper epm-assure load_helper epm-assure
# file prefix suffix
__epm_restore_print_comment()
{
echo "#$2 generated by 'epm restore --dry-run' from $(basename $(dirname $(realpath "$1")))/$(basename "$1")$3"
}
# FIXME: python modules are packaged into python packages, but we have only module names and rpm package names instead of python packages # FIXME: python modules are packaged into python packages, but we have only module names and rpm package names instead of python packages
# enable python3dest(PEP-503 normalized name) provides # enable python3dest(PEP-503 normalized name) provides
# https://bugzilla.altlinux.org/show_bug.cgi?id=39003 # https://bugzilla.altlinux.org/show_bug.cgi?id=39003
...@@ -60,10 +66,11 @@ __epm_pi_sign_to_rpm() ...@@ -60,10 +66,11 @@ __epm_pi_sign_to_rpm()
local pi='' local pi=''
local sign ll local sign ll
for sign in "<=" "<" ">=" ">" "==" "!="; do for sign in "<=" "<" ">=" ">" "==" "!=" "~="; do
ll=$(fill_sign "$sign" "$l") ll=$(fill_sign "$sign" "$l")
[ -n "$ll" ] || continue [ -n "$ll" ] || continue
[ "$sign" = "==" ] && sign="$equal" [ "$sign" = "==" ] && sign="$equal"
[ "$sign" = "~=" ] && sign="$equal"
[ "$sign" = "!=" ] && sign=">=" [ "$sign" = "!=" ] && sign=">="
[ -n "$pi" ] && pi="$pi [ -n "$pi" ] && pi="$pi
" "
...@@ -102,7 +109,7 @@ __epm_restore_convert_to_rpm_notation() ...@@ -102,7 +109,7 @@ __epm_restore_convert_to_rpm_notation()
if echo "$l" | grep -qE "^ *#" || [ -z "$l" ] ; then if echo "$l" | grep -qE "^ *#" || [ -z "$l" ] ; then
continue continue
fi fi
local t="$(echo "$l" | sed -E -e "s|[[:space:]]*[<>!=]+.*||" -e "s| *#.*||" | __epm_filter_pip_to_rpm)" local t="$(echo "$l" | sed -E -e "s|[[:space:]]*[<>!=~]+.*||" -e "s| *#.*||" | __epm_filter_pip_to_rpm)"
[ -n "$t" ] || continue [ -n "$t" ] || continue
# until new section # until new section
if echo "$l" | grep -qE "^\[" ; then if echo "$l" | grep -qE "^\[" ; then
...@@ -132,7 +139,7 @@ __epm_restore_pip() ...@@ -132,7 +139,7 @@ __epm_restore_pip()
reqmacro="%py3_use" reqmacro="%py3_use"
basename "$req_file" | egrep -q "(dev|test)" && reqmacro="%py3_buildrequires" basename "$req_file" | egrep -q "(dev|test)" && reqmacro="%py3_buildrequires"
echo echo
echo "# generated by epm restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file" __epm_restore_print_comment "$req_file"
cat $req_file | __epm_restore_convert_to_rpm_notation | sed -e "s|^|$reqmacro |" cat $req_file | __epm_restore_convert_to_rpm_notation | sed -e "s|^|$reqmacro |"
return return
else else
...@@ -193,7 +200,7 @@ $l" ...@@ -193,7 +200,7 @@ $l"
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
echo echo
echo "# generated by epm restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file $(__epm_get_array_name "$section")" __epm_restore_print_comment "$req_file" "" " $(__epm_get_array_name "$section")"
__epm_lineprint_python_array "$ar" | __epm_restore_convert_to_rpm_notation ">=" | sed -e "s|^|$reqmacro |" __epm_lineprint_python_array "$ar" | __epm_restore_convert_to_rpm_notation ">=" | sed -e "s|^|$reqmacro |"
else else
ilist="$ilist $(__epm_lineprint_python_array "$ar" | __epm_restore_convert_to_rpm_notation ">=" | cut -d' ' -f 1 | sed -e "s|^|python3-module-|")" ilist="$ilist $(__epm_lineprint_python_array "$ar" | __epm_restore_convert_to_rpm_notation ">=" | cut -d' ' -f 1 | sed -e "s|^|python3-module-|")"
...@@ -259,11 +266,11 @@ __epm_restore_npm() ...@@ -259,11 +266,11 @@ __epm_restore_npm()
local lt=$(mktemp) local lt=$(mktemp)
a= jq .dependencies <$req_file >$lt a= jq .dependencies <$req_file >$lt
echo echo
echo "# generated by epm restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file" __epm_restore_print_comment "$req_file"
__epm_print_npm_list "Requires:" $lt __epm_print_npm_list "Requires:" $lt
echo echo
echo "# devDependencies generated by epm restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file" __epm_restore_print_comment "$req_file" " devDependencies"
a= jq .devDependencies <$req_file >$lt a= jq .devDependencies <$req_file >$lt
__epm_print_npm_list "BuildRequires:" $lt __epm_print_npm_list "BuildRequires:" $lt
rm -f $lt rm -f $lt
...@@ -298,6 +305,12 @@ __epm_restore_by() ...@@ -298,6 +305,12 @@ __epm_restore_by()
return return
fi fi
case $req_file in
requirements/default.txt|requirements/dev.txt|requirements/test.txt)
[ -s "$req_file" ] && __epm_restore_pip "$req_file" && return
;;
esac
case $(basename $req_file) in case $(basename $req_file) in
requirements.txt|dev-requirements.txt|requirements-dev.txt|requirements_dev.txt|requirements_test.txt|requirements-test.txt|test-requirements.txt|requires.txt) requirements.txt|dev-requirements.txt|requirements-dev.txt|requirements_dev.txt|requirements_test.txt|requirements-test.txt|test-requirements.txt|requires.txt)
[ -s "$req_file" ] && __epm_restore_pip "$req_file" [ -s "$req_file" ] && __epm_restore_pip "$req_file"
...@@ -334,7 +347,7 @@ epm_restore() ...@@ -334,7 +347,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 requirements-dev.txt dev-requirements.txt requirements-test.txt requirements_test.txt test-requirements.txt Gemfile requires.txt package.json setup.py python_dependencies.py; do for i in requirements.txt requirements/default.txt requirements_dev.txt requirements-dev.txt requirements/dev.txt dev-requirements.txt requirements-test.txt requirements_test.txt requirements/test.txt test-requirements.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