Skip to content

Commit 4eac023

Browse files
Merge pull request #563 from IntelPython/coverage-init
Improve coverage of dpctl.__init__ file and other service functions
2 parents 2203dea + 0c499ec commit 4eac023

File tree

3 files changed

+126
-29
lines changed

3 files changed

+126
-29
lines changed

dpctl/tests/test_service.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2020-2021 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
""" Defines unit test cases for miscellaneous functions.
18+
"""
19+
20+
import ctypes
21+
import ctypes.util
22+
import glob
23+
import os
24+
import os.path
25+
import re
26+
27+
import dpctl
28+
29+
30+
def _get_mkl_version_if_present():
31+
class MKLVersion(ctypes.Structure):
32+
_fields_ = [
33+
("MajorVersion", ctypes.c_int),
34+
("MinorVersion", ctypes.c_int),
35+
("UpdateVersion", ctypes.c_int),
36+
("ProductStatus", ctypes.c_char_p),
37+
("Build", ctypes.c_char_p),
38+
("Processor", ctypes.c_char_p),
39+
("Platform", ctypes.c_char_p),
40+
]
41+
42+
lib = ctypes.util.find_library("mkl_rt")
43+
if lib is None:
44+
return None
45+
try:
46+
lib = ctypes.cdll.LoadLibrary(lib)
47+
get_ver_fn = lib.mkl_get_version
48+
except Exception:
49+
return None
50+
get_ver_fn.argtypes = []
51+
get_ver_fn.restype = MKLVersion
52+
mkl_ver = get_ver_fn()
53+
return ".".join(
54+
[
55+
str(mkl_ver.MajorVersion),
56+
str(mkl_ver.UpdateVersion),
57+
str(mkl_ver.MinorVersion),
58+
]
59+
)
60+
61+
62+
def test_get_include():
63+
incl = dpctl.get_include()
64+
assert type(incl) is str
65+
assert incl != ""
66+
assert os.path.isdir(incl)
67+
68+
69+
def test_get_dpcppversion():
70+
incl_dir = dpctl.get_include()
71+
libs = glob.glob(os.path.join(incl_dir, "..", "*DPCTLSyclInterface*"))
72+
libs = sorted(libs)
73+
assert len(libs) > 0
74+
lib = ctypes.cdll.LoadLibrary(libs[0])
75+
fn = lib.DPCTLService_GetDPCPPVersion
76+
fn.restype = ctypes.c_char_p
77+
fn.argtypes = []
78+
dpcpp_ver = fn()
79+
assert len(dpcpp_ver) > 0
80+
dpcpp_ver = dpcpp_ver.decode("utf-8")
81+
mkl_ver = _get_mkl_version_if_present()
82+
assert mkl_ver is None or mkl_ver == dpcpp_ver
83+
84+
85+
def test___version__():
86+
dpctl_ver = getattr(dpctl, "__version__", None)
87+
assert type(dpctl_ver) is str
88+
assert "unknown" not in dpctl_ver
89+
# Reg expr from PEP-440
90+
reg_expr = (
91+
r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))"
92+
r"*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev("
93+
r"0|[1-9][0-9]*))?(\+.*)?$"
94+
)
95+
assert re.match(reg_expr, dpctl_ver) is not None

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VCS = git
33
versionfile_source = dpctl/_version.py
44
versionfile_build = dpctl/_version.py
55
tag_prefix =
6-
parentdir_prefix = DPCTL-
6+
parentdir_prefix = dpctl-
77

88
[bdist_wheel]
99
universal=1

setup.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import numpy as np
2424
import setuptools.command.build_ext as orig_build_ext
25-
import setuptools.command.build_py as orig_build_py
2625
import setuptools.command.develop as orig_develop
2726
import setuptools.command.install as orig_install
2827
from Cython.Build import cythonize
@@ -254,32 +253,35 @@ def run(self):
254253
return super().run()
255254

256255

257-
class build_py(orig_build_py.build_py):
258-
def run(self):
259-
dpctl_src_dir = self.get_package_dir("dpctl")
260-
dpctl_build_dir = os.path.join(self.build_lib, "dpctl")
261-
os.makedirs(dpctl_build_dir, exist_ok=True)
262-
if IS_LIN:
263-
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.so*")):
264-
# Check if the file already exists before copying. The check is
265-
# needed when dealing with symlinks.
266-
if not os.path.exists(
267-
os.path.join(dpctl_build_dir, os.path.basename(fn))
268-
):
269-
shutil.copy(
270-
src=fn,
271-
dst=dpctl_build_dir,
272-
follow_symlinks=False,
273-
)
274-
elif IS_WIN:
275-
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.lib")):
276-
shutil.copy(src=fn, dst=dpctl_build_dir)
277-
278-
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.dll")):
279-
shutil.copy(src=fn, dst=dpctl_build_dir)
280-
else:
281-
raise NotImplementedError("Unsupported platform")
282-
return super().run()
256+
def get_build_py(orig_build_py):
257+
class build_py(orig_build_py):
258+
def run(self):
259+
dpctl_src_dir = self.get_package_dir("dpctl")
260+
dpctl_build_dir = os.path.join(self.build_lib, "dpctl")
261+
os.makedirs(dpctl_build_dir, exist_ok=True)
262+
if IS_LIN:
263+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.so*")):
264+
# Check if the file already exists before copying.
265+
# The check is needed when dealing with symlinks.
266+
if not os.path.exists(
267+
os.path.join(dpctl_build_dir, os.path.basename(fn))
268+
):
269+
shutil.copy(
270+
src=fn,
271+
dst=dpctl_build_dir,
272+
follow_symlinks=False,
273+
)
274+
elif IS_WIN:
275+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.lib")):
276+
shutil.copy(src=fn, dst=dpctl_build_dir)
277+
278+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.dll")):
279+
shutil.copy(src=fn, dst=dpctl_build_dir)
280+
else:
281+
raise NotImplementedError("Unsupported platform")
282+
return super().run()
283+
284+
return build_py
283285

284286

285287
class install(orig_install.install):
@@ -436,10 +438,10 @@ def run(self):
436438

437439
def _get_cmdclass():
438440
cmdclass = versioneer.get_cmdclass()
441+
cmdclass["build_py"] = get_build_py(cmdclass["build_py"])
439442
cmdclass["install"] = install
440443
cmdclass["develop"] = develop
441444
cmdclass["build_ext"] = build_ext
442-
cmdclass["build_py"] = build_py
443445
return cmdclass
444446

445447

0 commit comments

Comments
 (0)