Skip to content

Commit c2d8773

Browse files
authored
Provide setup.py option to profile Cython code (dask#4362)
As it can be useful for development to profile the Cythonized code and this requires an argument be provided to the extensions to enable, go ahead and add some logic to `setup.py` to parse this option if provided. If it is not provided, profiling is turned off, which is preferable as this would impact the performance of the compiled code.
1 parent e098030 commit c2d8773

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

setup.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,27 @@
2121
else:
2222
install_requires.append(r)
2323

24-
try:
25-
sys.argv.remove("--with-cython")
26-
cython = True
27-
except ValueError:
28-
cython = False
24+
cython_arg = None
25+
for i in range(len(sys.argv)):
26+
if sys.argv[i].startswith("--with-cython"):
27+
cython_arg = sys.argv[i]
28+
del sys.argv[i]
29+
break
2930

3031
ext_modules = []
31-
if cython:
32+
if cython_arg:
3233
try:
33-
import cython
34+
import cython # noqa: F401
3435
except ImportError:
3536
setup_requires.append("cython")
3637

38+
profile = False
39+
try:
40+
_, param = cython_arg.split("=")
41+
profile = param == "profile"
42+
except ValueError:
43+
pass
44+
3745
cyext_modules = [
3846
Extension(
3947
"distributed.scheduler",
@@ -46,6 +54,7 @@
4654
"binding": False,
4755
"embedsignature": True,
4856
"language_level": 3,
57+
"profile": profile,
4958
}
5059
ext_modules.extend(cyext_modules)
5160

0 commit comments

Comments
 (0)