Skip to content

Commit a23dac2

Browse files
committed
Converted CLIs to lazy loading logic
1 parent f8d6590 commit a23dac2

File tree

16 files changed

+1024
-961
lines changed

16 files changed

+1024
-961
lines changed

src/instrumentman/__main__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from typing import Any
2+
3+
from click_extra import extra_command
4+
5+
from ..utils import (
6+
com_baud_option,
7+
com_timeout_option,
8+
com_port_argument
9+
)
10+
11+
12+
@extra_command(
13+
"test",
14+
params=None,
15+
context_settings={"auto_envvar_prefix": None}
16+
) # type: ignore[misc]
17+
@com_port_argument()
18+
@com_baud_option()
19+
@com_timeout_option()
20+
def cli(**kwargs: Any) -> None:
21+
from .app import main
22+
23+
main(**kwargs)

src/instrumentman/geocomtest.py renamed to src/instrumentman/geocomtest/app.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from click_extra import (
2-
extra_command,
32
echo,
43
prompt
54
)
@@ -9,13 +8,10 @@
98
from geocompy.geo.gctypes import GeoComCode
109
from geocompy.communication import open_serial
1110

12-
from .utils import (
11+
from ..utils import (
1312
echo_red,
1413
echo_green,
15-
echo_yellow,
16-
com_baud_option,
17-
com_timeout_option,
18-
com_port_argument
14+
echo_yellow
1915
)
2016

2117

@@ -59,23 +55,11 @@ def tests(tps: GeoCom) -> None:
5955
echo_yellow(f"Mororization unavailable ({resp_changeface.response})")
6056

6157

62-
@extra_command(
63-
"test",
64-
params=None,
65-
context_settings={"auto_envvar_prefix": None}
66-
) # type: ignore[misc]
67-
@com_port_argument()
68-
@com_baud_option()
69-
@com_timeout_option()
70-
def cli(
58+
def main(
7159
port: str,
7260
baud: int = 9600,
7361
timeout: int = 15
7462
) -> None:
75-
"""Rudimentary tests for determining what GeoCom functions are
76-
available on an instrument.
77-
"""
78-
7963
try:
8064
with open_serial(
8165
port,
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from typing import Any
2+
3+
from click_extra import (
4+
extra_command,
5+
option,
6+
option_group,
7+
argument,
8+
Choice,
9+
IntRange
10+
)
11+
12+
from ..utils import (
13+
com_baud_option,
14+
com_timeout_option,
15+
com_port_argument
16+
)
17+
18+
19+
@extra_command(
20+
"morse",
21+
params=None,
22+
context_settings={"auto_envvar_prefix": None}
23+
) # type: ignore[misc]
24+
@com_port_argument()
25+
@argument(
26+
"message",
27+
help="message to relay as a string of ASCII characters",
28+
type=str
29+
)
30+
@option(
31+
"-i",
32+
"--intensity",
33+
help="beeping intensity",
34+
type=IntRange(0, 100),
35+
default=100
36+
)
37+
@option(
38+
"-u",
39+
"--unittime",
40+
help="beep unit time in milliseconds [ms]",
41+
type=IntRange(min=50),
42+
default=50
43+
)
44+
@option(
45+
"-c",
46+
"--compatibility",
47+
help="instrument compatibility",
48+
type=Choice(["none", "TPS1000"], case_sensitive=False),
49+
default="none"
50+
)
51+
@option(
52+
"--ignore-non-ascii",
53+
help="suppress encoding errors and skip non-ASCII characters",
54+
is_flag=True
55+
)
56+
@option_group(
57+
"Connection options",
58+
"Options related to the serial connection",
59+
com_baud_option(),
60+
com_timeout_option()
61+
)
62+
def cli(**kwargs: Any) -> None:
63+
"""Play a Morse encoded ASCII message through the beep signals
64+
of a GeoCom capable total station.
65+
"""
66+
67+
from .app import main
68+
69+
main(**kwargs)

src/instrumentman/morse.py renamed to src/instrumentman/morse/app.py

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
from time import sleep
22
from typing import Callable, Any
33

4-
from click_extra import (
5-
extra_command,
6-
option,
7-
option_group,
8-
argument,
9-
Choice,
10-
IntRange,
11-
progressbar
12-
)
4+
from click_extra import progressbar
135

146
from geocompy.geo import GeoCom
157
from geocompy.communication import open_serial
168

17-
from .utils import (
9+
from ..utils import (
1810
echo_red,
19-
echo_green,
20-
com_baud_option,
21-
com_timeout_option,
22-
com_port_argument
11+
echo_green
2312
)
2413

2514

@@ -128,50 +117,7 @@ def relay_message(
128117
)
129118

130119

131-
@extra_command(
132-
"morse",
133-
params=None,
134-
context_settings={"auto_envvar_prefix": None}
135-
) # type: ignore[misc]
136-
@com_port_argument()
137-
@argument(
138-
"message",
139-
help="message to relay as a string of ASCII characters",
140-
type=str
141-
)
142-
@option(
143-
"-i",
144-
"--intensity",
145-
help="beeping intensity",
146-
type=IntRange(0, 100),
147-
default=100
148-
)
149-
@option(
150-
"-u",
151-
"--unittime",
152-
help="beep unit time in milliseconds [ms]",
153-
type=IntRange(min=50),
154-
default=50
155-
)
156-
@option(
157-
"-c",
158-
"--compatibility",
159-
help="instrument compatibility",
160-
type=Choice(["none", "TPS1000"], case_sensitive=False),
161-
default="none"
162-
)
163-
@option(
164-
"--ignore-non-ascii",
165-
help="suppress encoding errors and skip non-ASCII characters",
166-
is_flag=True
167-
)
168-
@option_group(
169-
"Connection options",
170-
"Options related to the serial connection",
171-
com_baud_option(),
172-
com_timeout_option()
173-
)
174-
def cli(
120+
def main(
175121
port: str,
176122
message: str,
177123
intensity: int = 100,
@@ -181,9 +127,6 @@ def cli(
181127
unittime: int = 50,
182128
compatibility: str = "none",
183129
) -> None:
184-
"""Play a Morse encoded ASCII message through the beep signals
185-
of a GeoCom capable total station.
186-
"""
187130
if not ignore_non_ascii:
188131
try:
189132
message.casefold().encode("ascii")
@@ -209,7 +152,3 @@ def cli(
209152
unittime * 1e-3
210153
)
211154
echo_green("Message complete.")
212-
213-
214-
if __name__ == "__main__":
215-
cli()

0 commit comments

Comments
 (0)