From 07b5dd38230ba1d8f9a9730a85a36f570e1b758b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Wed, 21 Sep 2016 20:27:30 +0200 Subject: [PATCH] Added option to install dependencies in CLI --- Dockerfile.template | 2 ++ Makefile | 10 +++++++--- senpy/VERSION | 2 +- senpy/__main__.py | 8 ++++++++ senpy/extensions.py | 23 ++++++++++++++++------- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Dockerfile.template b/Dockerfile.template index 64d68bc..a75a9cb 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -1,3 +1,5 @@ from python:{{PYVERSION}}-onbuild +RUN pip install . + ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"] diff --git a/Makefile b/Makefile index 87d9e91..c2f265f 100644 --- a/Makefile +++ b/Makefile @@ -34,9 +34,13 @@ upload-%: test-% upload: testall $(addprefix upload-,$(PYVERSIONS)) docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' '$(REPO)/$(NAME):$(VERSION)' - docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYVERSIONS)' '$(REPO)/$(NAME)' - docker push '$(REPO)/$(NAME):$(VERSION)' docker push '$(REPO)/$(NAME)' - python setup.py sdist upload + docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' '$(REPO)/$(NAME)' + docker push '$(REPO)/$(NAME):$(VERSION)' + +clean: + @docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1;}}' | xargs docker rm 2>/dev/null|| true + @docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true + pip_upload: python setup.py sdist upload ; diff --git a/senpy/VERSION b/senpy/VERSION index 09a3acf..ee6cdce 100644 --- a/senpy/VERSION +++ b/senpy/VERSION @@ -1 +1 @@ -0.6.0 \ No newline at end of file +0.6.1 diff --git a/senpy/__main__.py b/senpy/__main__.py index c5d7087..a0e6c36 100644 --- a/senpy/__main__.py +++ b/senpy/__main__.py @@ -65,6 +65,11 @@ def main(): type=str, default='plugins', help='Where to look for plugins.') + parser.add_argument('--only-install', + '-i', + action='store_true', + default=False, + help='Do not run a server, only install the dependencies of the plugins.') args = parser.parse_args() logging.basicConfig() rl = logging.getLogger() @@ -72,6 +77,9 @@ def main(): app = Flask(__name__) app.debug = args.debug sp = Senpy(app, args.plugins_folder, default_plugins=args.default_plugins) + if args.only_install: + sp.install_deps() + return sp.activate_all() http_server = WSGIServer((args.host, args.port), app) try: diff --git a/senpy/extensions.py b/senpy/extensions.py index 6e297bc..a9228e5 100644 --- a/senpy/extensions.py +++ b/senpy/extensions.py @@ -204,6 +204,21 @@ class Senpy(object): def validate_info(cls, info): return all(x in info for x in ('name', 'module', 'version')) + def install_deps(self): + for i in self.plugins.values(): + self._install_deps(i._info) + + @classmethod + def _install_deps(cls, info=None): + requirements = info.get('requirements', []) + if requirements: + pip_args = [] + pip_args.append('install') + for req in requirements: + pip_args.append( req ) + logger.info('Installing requirements: ' + str(requirements)) + pip.main(pip_args) + @classmethod def _load_plugin_from_info(cls, info, root): if not cls.validate_info(info): @@ -215,13 +230,7 @@ class Senpy(object): sys.path.append(root) (fp, pathname, desc) = imp.find_module(module, [root, ]) try: - if requirements: - pip_args = [] - pip_args.append('install') - for req in requirements: - pip_args.append( req ) - logger.info('Installing requirements: ' + str(requirements)) - pip.main(pip_args) + cls._install_deps(info) tmp = imp.load_module(module, fp, pathname, desc) sys.path.remove(root) candidate = None