Skip to content

Commit

Permalink
Load only requested command module in shub.tool and shub.image
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemaeyer committed Jun 6, 2017
1 parent f2eea1b commit e4cc75c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion shub/image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import click
import importlib
import sys

import click


@click.group(help="Manage project based on custom Docker image")
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions shub/tool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import
import importlib
import sys

import click

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e4cc75c

Please sign in to comment.