Skip to content

Commit dfbad17

Browse files
authored
Import modules when required (#107)
1 parent fc8055e commit dfbad17

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/vstarstack/tool/clean.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import os
1616

1717
import vstarstack.tool.common
18-
import vstarstack.library.common
1918
import vstarstack.tool.cfg
2019

2120
def run(project: vstarstack.tool.cfg.Project, _argv: list):

src/vstarstack/tool/debayer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ def _process(project: vstarstack.tool.cfg.Project, argv: list):
7474
project.config.paths.npy_orig,
7575
project.config.paths.npy_fixed)
7676

77-
def run(project: vstarstack.tool.cfg.Project, argv: list):
78-
_process(project, argv)
77+
commands = {
78+
"*": (_process, "debayer image", "input/ output/"),
79+
}

src/vstarstack/tool/process.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,38 @@
1717
import vstarstack.tool.usage
1818
import vstarstack.tool.manage_project
1919

20-
import vstarstack.tool.config
21-
import vstarstack.tool.image
2220
import vstarstack.tool.clean
23-
import vstarstack.tool.readimage
24-
import vstarstack.tool.merge
25-
import vstarstack.tool.debayer
26-
import vstarstack.tool.stars.stars
27-
import vstarstack.tool.cluster
28-
import vstarstack.tool.shift
29-
import vstarstack.tool.image_processing.fixes
30-
import vstarstack.tool.fine_shift.fine_shift
31-
import vstarstack.tool.objects.objects
32-
import vstarstack.tool.calibration
33-
import vstarstack.tool.analyzers.analyzers
3421

3522
commands = {
36-
"readimage": (vstarstack.tool.readimage.commands,
23+
"readimage": ("vstarstack.tool.readimage",
3724
"read source images to npz"),
38-
"debayer": (vstarstack.tool.debayer.run,
25+
"debayer": ("vstarstack.tool.debayer",
3926
"debayer RAW images"),
40-
"image-process": (vstarstack.tool.image_processing.fixes.commands,
27+
"image-process": ("vstarstack.tool.image_processing.fixes",
4128
"image-process - make optical fixes and other image fixes"),
42-
"calibration": (vstarstack.tool.calibration.commands,
29+
"calibration": ("vstarstack.tool.calibration",
4330
"calibration - flats, darks"),
44-
"objects": (vstarstack.tool.objects.objects.commands,
31+
"objects": ("vstarstack.tool.objects.objects",
4532
"commands for processing images with compact objects " +
4633
"(planets, diffractions, etc)"),
47-
"stars": (vstarstack.tool.stars.stars.commands,
34+
"stars": ("vstarstack.tool.stars.stars",
4835
"commands for processing stars images"),
49-
"cluster": (vstarstack.tool.cluster.commands,
36+
"cluster": ("vstarstack.tool.cluster",
5037
"command for cluster processing"),
51-
"shift": (vstarstack.tool.shift.commands,
38+
"shift": ("vstarstack.tool.shift",
5239
"move and rotate images to match them"),
53-
"merge": (vstarstack.tool.merge.commands,
40+
"merge": ("vstarstack.tool.merge",
5441
"merge images", "input_dir/ output.npz"),
5542
"project": (vstarstack.tool.manage_project.run,
5643
"configurate project"),
5744
# "planets": (vstarstack.targets.planets.planets.run,
5845
# "commands for processing planets"),
59-
"image": (vstarstack.tool.image.commands,
46+
"image": ("vstarstack.tool.image",
6047
"image processing (show, convert, etc)"),
6148
"clean": (vstarstack.tool.clean.run,
6249
"remove temporary files"),
63-
"fine-shift": (vstarstack.tool.fine_shift.fine_shift.commands,
50+
"fine-shift": ("vstarstack.tool.fine_shift.fine_shift",
6451
"fine shift images"),
65-
"analyzers": (vstarstack.tool.analyzers.analyzers.commands,
52+
"analyzers": ("vstarstack.tool.analyzers.analyzers",
6653
"analyze images"),
6754
}

src/vstarstack/tool/usage.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2022 Vladislav Tsendrovskii
2+
# Copyright (c) 2022-2024 Vladislav Tsendrovskii
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -13,6 +13,8 @@
1313
#
1414

1515
import os
16+
import importlib
17+
1618
_PRGNAME = "vstarstack"
1719

1820
def complete_path_in_dir(dirname : str | None, prefix : str):
@@ -80,6 +82,10 @@ def autocompletion(commands : dict, argv : list):
8082
if isinstance(command, dict):
8183
"""Go to subcommand completion"""
8284
return autocompletion(command, argv[1:])
85+
elif isinstance(command, str):
86+
"""Go to subcommand completion"""
87+
loaded_submodule = importlib.import_module(command)
88+
return autocompletion(loaded_submodule.commands, argv[1:])
8389
else:
8490
return autocomplete_files(argv[1:])
8591

@@ -135,5 +141,12 @@ def run(project, argv, base, commands, message=None):
135141
else:
136142
new_base = cmd
137143
run(project, argv[1:], new_base, submodule, message)
144+
elif isinstance(submodule, str):
145+
if len(base) > 0:
146+
new_base = base + " " + cmd
147+
else:
148+
new_base = cmd
149+
loaded_submodule = importlib.import_module(submodule)
150+
run(project, argv[1:], new_base, loaded_submodule.commands, message)
138151
else:
139152
submodule(project, argv[1:])

0 commit comments

Comments
 (0)