Skip to content

Commit 2bfc9c2

Browse files
committed
move CLI logic into __main__
1 parent d46b990 commit 2bfc9c2

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

threadpoolctl/__init__.py

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