Skip to content

Commit 395f3bc

Browse files
Merge pull request #1014 from IntelPython/dpctl_module_lsplatform
Added support for python -m dpctl -l to list platforms
2 parents a3f8141 + 4952963 commit 395f3bc

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

dpctl/__main__.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os.path
2020
import platform
2121
import sys
22+
import warnings
2223

2324
import dpctl
2425

@@ -50,6 +51,24 @@ def print_library() -> None:
5051
print(ld_flags + " -lSyclInterface")
5152

5253

54+
def _warn_if_any_set(args, li) -> None:
55+
opts_set = [it for it in li if getattr(args, it, True)]
56+
if opts_set:
57+
if len(opts_set) == 1:
58+
warnings.warn(
59+
"The option " + str(opts_set[0]) + " is being ignored.",
60+
stacklevel=3,
61+
)
62+
else:
63+
warnings.warn(
64+
"Options " + str(opts_set) + " are being ignored.", stacklevel=3
65+
)
66+
67+
68+
def print_lsplatform(verbosity: int) -> None:
69+
dpctl.lsplatform(verbosity=verbosity)
70+
71+
5372
def main() -> None:
5473
"""Main entry-point."""
5574
parser = argparse.ArgumentParser()
@@ -68,9 +87,45 @@ def main() -> None:
6887
action="store_true",
6988
help="Linker flags for SyclInterface library.",
7089
)
90+
parser.add_argument(
91+
"-f",
92+
"--full-list",
93+
action="store_true",
94+
help="Enumerate system platforms, using dpctl.lsplatform(verbosity=2)",
95+
)
96+
parser.add_argument(
97+
"-l",
98+
"--long-list",
99+
action="store_true",
100+
help="Enumerate system platforms, using dpctl.lsplatform(verbosity=1)",
101+
)
102+
parser.add_argument(
103+
"-s",
104+
"--summary",
105+
action="store_true",
106+
help="Enumerate system platforms, using dpctl.lsplatform()",
107+
)
71108
args = parser.parse_args()
72109
if not sys.argv[1:]:
73110
parser.print_help()
111+
if args.full_list:
112+
_warn_if_any_set(
113+
args, ["long_list", "summary", "includes", "cmakedir", "library"]
114+
)
115+
print_lsplatform(2)
116+
return
117+
if args.long_list:
118+
_warn_if_any_set(
119+
args, ["full_list", "summary", "includes", "cmakedir", "library"]
120+
)
121+
print_lsplatform(1)
122+
return
123+
if args.summary:
124+
_warn_if_any_set(
125+
args, ["long_list", "full_list", "includes", "cmakedir", "library"]
126+
)
127+
print_lsplatform(0)
128+
return
74129
if args.includes:
75130
print_includes()
76131
if args.cmakedir:

dpctl/tests/test_service.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,49 @@ def test_cmakedir():
182182
assert res.stdout
183183
cmake_dir = res.stdout.decode("utf-8").strip()
184184
assert os.path.exists(os.path.join(cmake_dir, "FindDpctl.cmake"))
185+
186+
187+
def test_main_full_list():
188+
res = subprocess.run(
189+
[sys.executable, "-m", "dpctl", "-f"], capture_output=True
190+
)
191+
assert res.returncode == 0
192+
assert res.stdout
193+
assert res.stdout.decode("utf-8")
194+
195+
196+
def test_main_long_list():
197+
res = subprocess.run(
198+
[sys.executable, "-m", "dpctl", "-l"], capture_output=True
199+
)
200+
assert res.returncode == 0
201+
assert res.stdout
202+
assert res.stdout.decode("utf-8")
203+
204+
205+
def test_main_summary():
206+
res = subprocess.run(
207+
[sys.executable, "-m", "dpctl", "-s"], capture_output=True
208+
)
209+
assert res.returncode == 0
210+
assert res.stdout
211+
assert res.stdout.decode("utf-8")
212+
213+
214+
def test_main_warnings():
215+
res = subprocess.run(
216+
[sys.executable, "-m", "dpctl", "-s", "--includes"], capture_output=True
217+
)
218+
assert res.returncode == 0
219+
assert res.stdout
220+
assert "UserWarning" in res.stderr.decode("utf-8")
221+
assert "is being ignored." in res.stderr.decode("utf-8")
222+
223+
res = subprocess.run(
224+
[sys.executable, "-m", "dpctl", "-s", "--includes", "--cmakedir"],
225+
capture_output=True,
226+
)
227+
assert res.returncode == 0
228+
assert res.stdout
229+
assert "UserWarning" in res.stderr.decode("utf-8")
230+
assert "are being ignored." in res.stderr.decode("utf-8")

0 commit comments

Comments
 (0)