Skip to content

Commit aadb0ca

Browse files
Removed use of CODE_COVERAGE environment variable
CODE_COVERAGE was used to influence whether the backend SyclInterface library was built in debug mode with coverage over dpctp-capi/ test suite collected or not. It was also influencing how Cython extensions were built. It would pass linetrace=true option to cythonize, and define CYTHON_TRACE preprocessor variable when compiling Cython-generated C++ source files with compiler. This change removes use CODE_COVERAGE all together. Instead: 1. Custom setuptools command 'build_ext' is implemented which auto-adds 'CYTHON_TRACE' to the list of defines received by downstream build_ext command if develop command received --coverage=True cythonize call was removed from extensions() function, allowing ``python setup.py develop --help` execute cleanly without running cythonize. Consequentially, linetrace Cython directive will need to be added to each .pyx file in a separate commit. This is safe to do per https://cython.readthedocs.io/en/latest/src/tutorial/profiling_tutorial.html#enabling-line-tracing since it is a no-op unless CYTHON_TRACE preprocessor variable is also set, which is only done when --coverage=True is used 2. install setuptools command removed support for `--coverage` option, and always builds backend without coverage. This is to avoid inadvertent installation of debug build of library in Python prefix.
1 parent f94f451 commit aadb0ca

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

setup.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import sys
2020

2121
import numpy as np
22+
import setuptools.command.build_ext as orig_build_ext
2223
import setuptools.command.develop as orig_develop
2324
import setuptools.command.install as orig_install
24-
from Cython.Build import cythonize
2525
from setuptools import Extension, find_packages, setup
2626

2727
import versioneer
@@ -39,6 +39,9 @@
3939
else:
4040
assert False, "We currently do not build for " + sys.platform
4141

42+
# global variable used to pass value of --coverage option of develop command
43+
# to build_ext command
44+
_coverage = False
4245
dpctl_sycl_interface_lib = "dpctl"
4346
dpctl_sycl_interface_include = r"dpctl/include"
4447

@@ -123,7 +126,6 @@ def extensions():
123126
ela = get_sdl_ldflags()
124127
libs = []
125128
libraries = []
126-
CODE_COVERAGE = os.environ.get("CODE_COVERAGE")
127129

128130
if IS_LIN:
129131
libs += ["rt", "DPCTLSyclInterface"]
@@ -160,15 +162,6 @@ def extensions():
160162
"define_macros": [],
161163
}
162164

163-
if CODE_COVERAGE:
164-
extension_args.update(
165-
{
166-
"define_macros": [
167-
("CYTHON_TRACE", "1"),
168-
]
169-
}
170-
)
171-
172165
extensions = [
173166
Extension(
174167
"dpctl._sycl_context",
@@ -253,15 +246,25 @@ def extensions():
253246
define_macros=extension_args["define_macros"],
254247
),
255248
]
256-
if CODE_COVERAGE:
257-
exts = cythonize(
258-
extensions,
259-
compiler_directives={"linetrace": True},
260-
language_level=3,
261-
)
262-
else:
263-
exts = cythonize(extensions, language_level=3)
264-
return exts
249+
# ext = cythonize(extensions, language_level=3)
250+
return extensions
251+
252+
253+
class build_ext(orig_build_ext.build_ext):
254+
description = "Build dpctl native extensions"
255+
256+
def finalize_options(self):
257+
global _coverage
258+
if _coverage:
259+
pre_d = getattr(self, "define", None)
260+
if pre_d is None:
261+
self.define = "CYTHON_TRACE"
262+
else:
263+
self.define = ",".join((pre_d, "CYTHON_TRACE"))
264+
super().finalize_options()
265+
266+
def run(self):
267+
return super().run()
265268

266269

267270
class install(orig_install.install):
@@ -279,18 +282,11 @@ class install(orig_install.install):
279282
"Path to SYCL compiler installation. None means "
280283
"read it off ONEAPI_ROOT environment variable or fail.",
281284
),
282-
(
283-
"coverage=",
284-
None,
285-
"Whether to generate coverage report "
286-
"when building the backend library",
287-
),
288285
]
289286

290287
def initialize_options(self):
291288
super().initialize_options()
292289
self.level_zero_support = "True"
293-
self.coverage = os.getenv("CODE_COVERAGE", "False")
294290
self.sycl_compiler_prefix = None
295291

296292
def finalize_options(self):
@@ -302,12 +298,6 @@ def finalize_options(self):
302298
raise ValueError(
303299
"--level-zero-support value is invalid, use True/False"
304300
)
305-
if isinstance(self.coverage, str):
306-
self.coverage = self.coverage.capitalize()
307-
if self.coverage in ["True", "False", "0", "1"]:
308-
self.coverage = bool(eval(self.coverage))
309-
else:
310-
raise ValueError("--coverage value is invalid, use True/False")
311301
if isinstance(self.sycl_compiler_prefix, str):
312302
if not os.path.exists(os.path.join(self.sycl_compiler_prefix)):
313303
raise ValueError(
@@ -326,9 +316,7 @@ def finalize_options(self):
326316
super().finalize_options()
327317

328318
def run(self):
329-
build_backend(
330-
self.level_zero_support, self.coverage, self.sycl_compiler_prefix
331-
)
319+
build_backend(self.level_zero_support, False, self.sycl_compiler_prefix)
332320
return super().run()
333321

334322

@@ -358,7 +346,7 @@ class develop(orig_develop.develop):
358346
def initialize_options(self):
359347
super().initialize_options()
360348
self.level_zero_support = "True"
361-
self.coverage = os.getenv("CODE_COVERAGE", "False")
349+
self.coverage = "False"
362350
self.sycl_compiler_prefix = None
363351

364352
def finalize_options(self):
@@ -374,6 +362,8 @@ def finalize_options(self):
374362
self.coverage = self.coverage.capitalize()
375363
if self.coverage in ["True", "False", "0", "1"]:
376364
self.coverage = bool(eval(self.coverage))
365+
global _coverage
366+
_coverage = self.coverage
377367
else:
378368
raise ValueError("--coverage value is invalid, use True/False")
379369
if isinstance(self.sycl_compiler_prefix, str):
@@ -404,6 +394,7 @@ def _get_cmdclass():
404394
cmdclass = versioneer.get_cmdclass()
405395
cmdclass["install"] = install
406396
cmdclass["develop"] = develop
397+
cmdclass["build_ext"] = build_ext
407398
return cmdclass
408399

409400

0 commit comments

Comments
 (0)