Skip to content

Commit e4cc75c

Browse files
committed
Load only requested command module in shub.tool and shub.image
1 parent f2eea1b commit e4cc75c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

shub/image/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import click
21
import importlib
2+
import sys
3+
4+
import click
35

46

57
@click.group(help="Manage project based on custom Docker image")
@@ -18,6 +20,9 @@ def cli():
1820
"check",
1921
]
2022

23+
if len(sys.argv) > 2 and sys.argv[2] in module_deps:
24+
module_deps = [sys.argv[2]]
25+
2126
for command in module_deps:
2227
module_path = "shub.image." + command
2328
command_module = importlib.import_module(module_path)

shub/tool.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22
import importlib
3+
import sys
34

45
import click
56

@@ -51,6 +52,12 @@ def cli():
5152
"image",
5253
]
5354

55+
# Some imports, particularly requests and pip, are very slow. To avoid
56+
# importing these modules when running a command that doesn't need them, we
57+
# import that command module only.
58+
if len(sys.argv) > 1 and sys.argv[1] in commands:
59+
commands = [sys.argv[1]]
60+
5461
for command in commands:
5562
module_path = "shub." + command
5663
command_module = importlib.import_module(module_path)

0 commit comments

Comments
 (0)