Skip to content

Commit bfc2ca1

Browse files
authored
ci: add DD_CYTHONIZE option to setup.py (#15255)
## Description This new option will allow us to skip cythonizing .pyx files during source distribution building (wasted step that pollutes source tree with extra `.c`/`.cpp` files which we won't use for source distributions). ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> ## Additional Notes <!-- Any other information that would be helpful for reviewers -->
1 parent 4059d22 commit bfc2ca1

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

.github/workflows/build_deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ jobs:
9393
- name: Build sdist
9494
run: |
9595
pip install "setuptools_scm[toml]>=4" "cython" "cmake>=3.24.2,<3.28" "setuptools-rust"
96-
python setup.py sdist
96+
# Disable cython extensions to avoid compiling .pyx files
97+
DD_CYTHONIZE=0 python setup.py sdist
9798
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
9899
with:
99100
name: source-dist

docs/build_system.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ These environment variables modify aspects of the build process.
183183
version_added:
184184
v3.3.0:
185185

186+
DD_CYTHONIZE:
187+
type: Boolean
188+
default: True
189+
description: |
190+
If enabled, then Cython extensions are included in the build. Disabling will exclude them.
191+
This is mostly useful for source distribution builds so we can skip calling ``cythonize`` on source files.
192+
186193
DD_FAST_BUILD:
187194
type: Boolean
188195
default: False

setup.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,33 +1157,10 @@ def get_exts_for(name):
11571157
else:
11581158
ext_modules = []
11591159

1160-
interpose_sccache()
1161-
setup(
1162-
name="ddtrace",
1163-
packages=find_packages(exclude=["tests*", "benchmarks*", "scripts*"]),
1164-
package_data={
1165-
"ddtrace": ["py.typed"],
1166-
"ddtrace.appsec": ["rules.json"],
1167-
"ddtrace.appsec._ddwaf": ["libddwaf/*/lib/libddwaf.*"],
1168-
"ddtrace.appsec._iast._taint_tracking": ["CMakeLists.txt"],
1169-
"ddtrace.internal.datadog.profiling": (
1170-
["libdd_wrapper*.*"]
1171-
+ (["ddtrace/internal/datadog/profiling/test/*"] if BUILD_PROFILING_NATIVE_TESTS else [])
1172-
),
1173-
},
1174-
zip_safe=False,
1175-
# enum34 is an enum backport for earlier versions of python
1176-
# funcsigs backport required for vendored debtcollector
1177-
cmdclass={
1178-
"build_ext": CustomBuildExt,
1179-
"build_py": LibraryDownloader,
1180-
"build_rust": CustomBuildRust,
1181-
"clean": CleanLibraries,
1182-
"ext_hashes": ExtensionHashes,
1183-
},
1184-
setup_requires=["setuptools_scm[toml]>=4", "cython", "cmake>=3.24.2,<3.28", "setuptools-rust"],
1185-
ext_modules=ext_modules
1186-
+ cythonize(
1160+
1161+
cython_exts = []
1162+
if os.getenv("DD_CYTHONIZE", "1").lower() in ("1", "yes", "on", "true"):
1163+
cython_exts = cythonize(
11871164
[
11881165
Cython.Distutils.Extension(
11891166
"ddtrace.internal._rand",
@@ -1244,6 +1221,32 @@ def get_exts_for(name):
12441221
compiler_directives={"language_level": "3"},
12451222
cache=True,
12461223
)
1247-
+ get_exts_for("psutil"),
1224+
1225+
interpose_sccache()
1226+
setup(
1227+
name="ddtrace",
1228+
packages=find_packages(exclude=["tests*", "benchmarks*", "scripts*"]),
1229+
package_data={
1230+
"ddtrace": ["py.typed"],
1231+
"ddtrace.appsec": ["rules.json"],
1232+
"ddtrace.appsec._ddwaf": ["libddwaf/*/lib/libddwaf.*"],
1233+
"ddtrace.appsec._iast._taint_tracking": ["CMakeLists.txt"],
1234+
"ddtrace.internal.datadog.profiling": (
1235+
["libdd_wrapper*.*"]
1236+
+ (["ddtrace/internal/datadog/profiling/test/*"] if BUILD_PROFILING_NATIVE_TESTS else [])
1237+
),
1238+
},
1239+
zip_safe=False,
1240+
# enum34 is an enum backport for earlier versions of python
1241+
# funcsigs backport required for vendored debtcollector
1242+
cmdclass={
1243+
"build_ext": CustomBuildExt,
1244+
"build_py": LibraryDownloader,
1245+
"build_rust": CustomBuildRust,
1246+
"clean": CleanLibraries,
1247+
"ext_hashes": ExtensionHashes,
1248+
},
1249+
setup_requires=["setuptools_scm[toml]>=4", "cython", "cmake>=3.24.2,<3.28", "setuptools-rust"],
1250+
ext_modules=ext_modules + cython_exts + get_exts_for("psutil"),
12481251
distclass=PatchedDistribution,
12491252
)

0 commit comments

Comments
 (0)