Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
senpy
senpy
Commits
7e5b55ff
Commit
7e5b55ff
authored
Mar 30, 2017
by
J. Fernando Sánchez
Browse files
Run pip with Popen
Closes
#22
parent
0c8f98d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
senpy/extensions.py
View file @
7e5b55ff
...
...
@@ -22,11 +22,18 @@ import importlib
import
logging
import
traceback
import
yaml
import
pip
import
subprocess
logger
=
logging
.
getLogger
(
__name__
)
def
log_subprocess_output
(
process
):
for
line
in
iter
(
process
.
stdout
.
readline
,
b
''
):
logger
.
info
(
'%r'
,
line
)
for
line
in
iter
(
process
.
stderr
.
readline
,
b
''
):
logger
.
error
(
'%r'
,
line
)
class
Senpy
(
object
):
""" Default Senpy extension for Flask """
...
...
@@ -333,13 +340,19 @@ class Senpy(object):
def
_install_deps
(
cls
,
info
=
None
):
requirements
=
info
.
get
(
'requirements'
,
[])
if
requirements
:
pip_args
=
[]
pip_args
=
[
'pip'
]
pip_args
.
append
(
'install'
)
pip_args
.
append
(
'--use-wheel'
)
for
req
in
requirements
:
pip_args
.
append
(
req
)
logger
.
info
(
'Installing requirements: '
+
str
(
requirements
))
pip
.
main
(
pip_args
)
process
=
subprocess
.
Popen
(
pip_args
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
log_subprocess_output
(
process
)
exitcode
=
process
.
wait
()
if
exitcode
!=
0
:
raise
Error
(
"Dependencies not properly installed"
)
@
classmethod
def
_load_module
(
cls
,
name
,
root
):
...
...
senpy/models.py
View file @
7e5b55ff
...
...
@@ -357,5 +357,8 @@ class Error(SenpyMixin, Exception):
def
__delattr__
(
self
,
key
):
delattr
(
self
.
_error
,
key
)
def
__str__
(
self
):
return
str
(
self
.
to_JSON
(
with_context
=
False
))
register
(
Error
,
'error'
)
tests/test_extensions.py
View file @
7e5b55ff
...
...
@@ -61,6 +61,19 @@ class ExtensionsTest(TestCase):
assert
len
(
self
.
senpy
.
plugins
)
>=
3
assert
self
.
senpy
.
plugins
[
"Sleep"
].
is_activated
def
test_installing_nonexistent
(
self
):
""" Fail if the dependencies cannot be met """
info
=
{
'name'
:
'TestPipFail'
,
'module'
:
'dummy'
,
'description'
:
None
,
'requirements'
:
[
'IAmMakingThisPackageNameUpToFail'
],
'version'
:
0
}
root
=
os
.
path
.
join
(
self
.
dir
,
'plugins'
,
'dummy_plugin'
)
with
self
.
assertRaises
(
Error
):
name
,
module
=
self
.
senpy
.
_load_plugin_from_info
(
info
,
root
=
root
)
def
test_disabling
(
self
):
""" Disabling a plugin """
self
.
senpy
.
deactivate_all
(
sync
=
True
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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