Skip to content

Commit dcee1e0

Browse files
committed
move CLI logic into __main__
1 parent 8d1cbbc commit dcee1e0

2 files changed

Lines changed: 46 additions & 42 deletions

File tree

threadpoolctl/__init__.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,45 +1253,3 @@ def _get_windll(cls, dll_name):
12531253
dll = ctypes.WinDLL(f"{dll_name}.dll")
12541254
cls._system_libraries[dll_name] = dll
12551255
return dll
1256-
1257-
1258-
def _main():
1259-
"""Commandline interface to display thread-pool information and exit."""
1260-
import argparse
1261-
import importlib
1262-
import json
1263-
import sys
1264-
1265-
parser = argparse.ArgumentParser(
1266-
usage="python -m threadpoolctl -i numpy scipy.linalg xgboost",
1267-
description="Display thread-pool information and exit.",
1268-
)
1269-
parser.add_argument(
1270-
"-i",
1271-
"--import",
1272-
dest="modules",
1273-
nargs="*",
1274-
default=(),
1275-
help="Python modules to import before introspecting thread-pools.",
1276-
)
1277-
parser.add_argument(
1278-
"-c",
1279-
"--command",
1280-
help="a Python statement to execute before introspecting thread-pools.",
1281-
)
1282-
1283-
options = parser.parse_args(sys.argv[1:])
1284-
for module in options.modules:
1285-
try:
1286-
importlib.import_module(module, package=None)
1287-
except ImportError:
1288-
print("WARNING: could not import", module, file=sys.stderr)
1289-
1290-
if options.command:
1291-
exec(options.command)
1292-
1293-
print(json.dumps(threadpool_info(), indent=2))
1294-
1295-
1296-
if __name__ == "__main__":
1297-
_main()

threadpoolctl/__main__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Commandline interface to display thread-pool information and exit."""
2+
3+
__all__ = ()
4+
5+
6+
def _main() -> None:
7+
import argparse
8+
import importlib
9+
import json
10+
import sys
11+
12+
from threadpoolctl import threadpool_info
13+
14+
parser = argparse.ArgumentParser(
15+
usage="python -m threadpoolctl -i numpy scipy.linalg xgboost",
16+
description="Display thread-pool information and exit.",
17+
)
18+
parser.add_argument(
19+
"-i",
20+
"--import",
21+
dest="modules",
22+
nargs="*",
23+
default=(),
24+
help="Python modules to import before introspecting thread-pools.",
25+
)
26+
parser.add_argument(
27+
"-c",
28+
"--command",
29+
help="a Python statement to execute before introspecting thread-pools.",
30+
)
31+
options = parser.parse_args(sys.argv[1:])
32+
33+
for module in options.modules:
34+
try:
35+
importlib.import_module(module, package=None)
36+
except ImportError:
37+
print("WARNING: could not import", module, file=sys.stderr)
38+
39+
if options.command:
40+
exec(options.command)
41+
42+
print(json.dumps(threadpool_info(), indent=2))
43+
44+
45+
if __name__ == "__main__":
46+
_main()

0 commit comments

Comments
 (0)