@@ -34,7 +34,21 @@ RUN rm -rf ./python/lib/$runtime/site-packages/botocore*
3434RUN rm -rf ./python/lib/$runtime/site-packages/setuptools
3535RUN rm -rf ./python/lib/$runtime/site-packages/jsonschema/tests
3636RUN rm -rf ./python/lib/$runtime/site-packages/ddtrace/appsec/_iast
37- RUN rm -rf ./python/lib/$runtime/site-packages/ddtrace/internal/test_visibility
37+ # CI Visibility paths/integrations
38+ RUN rm -rf \
39+ ./python/lib/$runtime/site-packages/ddtrace/contrib/coverage/ \
40+ ./python/lib/$runtime/site-packages/ddtrace/contrib/pytest/ \
41+ ./python/lib/$runtime/site-packages/ddtrace/contrib/pytest_bdd/ \
42+ ./python/lib/$runtime/site-packages/ddtrace/contrib/pytest_benchmark/ \
43+ ./python/lib/$runtime/site-packages/ddtrace/contrib/selenium/ \
44+ ./python/lib/$runtime/site-packages/ddtrace/contrib/unittest/ \
45+ ./python/lib/$runtime/site-packages/ddtrace/ext/ci_visibility \
46+ ./python/lib/$runtime/site-packages/ddtrace/ext/test_visibility \
47+ ./python/lib/$runtime/site-packages/ddtrace/internal/ci_visibility \
48+ ./python/lib/$runtime/site-packages/ddtrace/internal/coverage \
49+ ./python/lib/$runtime/site-packages/ddtrace/internal/test_visibility \
50+ ./python/lib/$runtime/site-packages/ddtrace/testing/
51+
3852# Dogshell
3953RUN rm -rf ./python/lib/$runtime/site-packages/datadog/dogshell
4054RUN rm -rf ./python/lib/$runtime/site-packages/bin/dog*
@@ -62,10 +76,18 @@ RUN rm -rf \
6276# https://docs.python.org/3.11/using/cmdline.html#cmdoption-O
6377# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNODEBUGRANGES
6478RUN PYTHONNODEBUGRANGES=1 python -OO -m compileall -b ./python/lib/$runtime/site-packages
65- # remove all .py files except ddtrace/contrib/*/patch.py which are necessary
66- # for ddtrace.patch to discover instrumationation packages.
67- RUN find ./python/lib/$runtime/site-packages -name \* .py | grep -v ddtrace/contrib | xargs rm -rf
68- RUN find ./python/lib/$runtime/site-packages/ddtrace/contrib -name \* .py | grep -v patch.py | xargs rm -rf
79+ # remove all .py files
80+ # DEV: ddtrace>=4.7.0rc3 checks for .pyc files in addition to .py files for instrumentation
81+ # discovery (DataDog/dd-trace-py#17196), so we can safely remove all .py files.
82+ # For older versions, we need to keep patch.py files for instrumentation discovery.
83+ RUN pip install --quiet packaging && \
84+ DDTRACE_VERSION=$(grep "^Version:" ./python/lib/$runtime/site-packages/ddtrace-*.dist-info/METADATA | awk '{print $2}' ) && \
85+ if python -c "from packaging.version import Version; exit(0 if Version('$DDTRACE_VERSION') >= Version('4.7.0rc3') else 1)" ; then \
86+ find ./python/lib/$runtime/site-packages -name \* .py | xargs rm -rf; \
87+ else \
88+ find ./python/lib/$runtime/site-packages -name \* .py | grep -v ddtrace/contrib | xargs rm -rf && \
89+ find ./python/lib/$runtime/site-packages/ddtrace/contrib -name \* .py | grep -v patch.py | xargs rm -rf; \
90+ fi
6991RUN find ./python/lib/$runtime/site-packages -name __pycache__ -type d -exec rm -r {} \+
7092
7193# When building ddtrace from branch, remove extra source files. These are
0 commit comments