Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
eepm
Commits
8f2f68a3
Commit
8f2f68a3
authored
Oct 31, 2020
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
epm-restore: rewrite to more full support of python arrays, add python_dependencies.py support
parent
2f9e6808
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
62 deletions
+84
-62
epm-restore
bin/epm-restore
+84
-62
No files found.
bin/epm-restore
View file @
8f2f68a3
...
@@ -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|P
IL
|"
\
-e
"s|pillow|P
illow
|"
\
-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
"
"
\]
,"
;
the
n
# start of sectio
n
fr
=
''
if
__eresection
"
$l
"
"REQUIREMENTS"
;
then
fd
=
''
reqmacro
=
"%py3_use"
continue
section
=
"
$l
"
fi
fi
if
[
-n
"
$fr$fd
"
]
;
then
if
__eresection
"
$l
"
"install_requires"
;
then
local
ll
=
"
$(
echo
"
$l
"
|
sed
-e
"s|[[:space:]]*'||"
-e
"s|'.*||"
)
"
reqmacro
=
"%py3_use"
local
t
=
"
$(
echo
"
$ll
"
|
sed
-e
"s| *[<>!]*=.*||"
| __epm_filter_pip_to_rpm
)
"
section
=
"
$l
"
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
fi
continue
if
__eresection
"
$l
"
"setup_requires"
;
then
reqmacro
=
"%py3_buildrequires"
section
=
"
$l
"
fi
fi
if
rhas
"
$l
"
"install_requires=
\[
"
;
then
if
__eresection
"
$l
"
"tests_require"
;
then
reqmacro
=
"%py3_use"
reqmacro
=
"%py3_buildrequires"
if
[
-n
"
$dryrun
"
]
;
then
section
=
"
$l
"
echo
echo
"# generated by epm --restore --dry-run from
$(
basename
$(
dirname
$(
realpath
$req_file
)))
/
$req_file
$l
"
fi
fi
fr
=
1
if
[
-n
"
$section
"
]
;
then
ar
=
"
$ar
$l
"
fi
# not end of section
if
[
-z
"
$section
"
]
||
!
rhas
"
$l
"
"
\]
,*"
;
then
continue
continue
fi
fi
if
rhas
"
$l
"
"tests_require=
\[
"
;
then
reqmacro
=
"%py3_buildrequires"
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
$l
"
echo
"# generated by epm --restore --dry-run from
$(
basename
$(
dirname
$(
realpath
$req_file
)))
/
$req_file
$(
__epm_get_array_name
"
$section
"
)
"
fi
__epm_lineprint_python_array
"
$ar
"
| __epm_restore_convert_to_rpm_notation
">="
|
sed
-e
"s|^|
$reqmacro
|"
fd
=
1
else
continue
ilist
=
"
$ilist
$(
__epm_lineprint_python_array
"
$ar
"
| __epm_restore_convert_to_rpm_notation
">="
|
cut
-d
' '
-f
1 |
sed
-e
"s|^|python3-module-|"
)
"
fi
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment