diff --git a/shub/image/__init__.py b/shub/image/__init__.py index d4ec3897..f1f0b4b7 100644 --- a/shub/image/__init__.py +++ b/shub/image/__init__.py @@ -1,5 +1,7 @@ -import click import importlib +import sys + +import click @click.group(help="Manage project based on custom Docker image") @@ -18,6 +20,9 @@ def cli(): "check", ] +if len(sys.argv) > 2 and sys.argv[2] in module_deps: + module_deps = [sys.argv[2]] + for command in module_deps: module_path = "shub.image." + command command_module = importlib.import_module(module_path) diff --git a/shub/tool.py b/shub/tool.py index 423824f3..ce09f55e 100644 --- a/shub/tool.py +++ b/shub/tool.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import importlib +import sys import click @@ -51,6 +52,12 @@ def cli(): "image", ] +# Some imports, particularly requests and pip, are very slow. To avoid +# importing these modules when running a command that doesn't need them, we +# import that command module only. +if len(sys.argv) > 1 and sys.argv[1] in commands: + commands = [sys.argv[1]] + for command in commands: module_path = "shub." + command command_module = importlib.import_module(module_path)