Skip to content

Commit 63f81be

Browse files
authored
chore: remove ddtrace patch.py files from layer (#763)
chore: remove ddtrace patch.py files from layer version gate the patch.py file removing Apply suggestion from @brettlangdon Co-authored-by: brett.langdon <brett.langdon@datadoghq.com>
1 parent 38cabf2 commit 63f81be

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ RUN rm -rf \
6262
# https://docs.python.org/3.11/using/cmdline.html#cmdoption-O
6363
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNODEBUGRANGES
6464
RUN 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
65+
# remove all .py files
66+
# DEV: ddtrace>=4.7.0rc4 checks for .pyc files in addition to .py files for instrumentation
67+
# discovery (DataDog/dd-trace-py#17196), so we can safely remove all .py files.
68+
# For older versions, we need to keep patch.py files for instrumentation discovery.
69+
RUN if python -c "from packaging.version import Version; import ddtrace; exit(0 if Version(ddtrace.__version__) >= Version('4.7.0rc3') else 1)"; then \
70+
find ./python/lib/$runtime/site-packages -name \*.py | xargs rm -rf; \
71+
else \
72+
find ./python/lib/$runtime/site-packages -name \*.py | grep -v ddtrace/contrib | xargs rm -rf && \
73+
find ./python/lib/$runtime/site-packages/ddtrace/contrib -name \*.py | grep -v patch.py | xargs rm -rf; \
74+
fi
6975
RUN find ./python/lib/$runtime/site-packages -name __pycache__ -type d -exec rm -r {} \+
7076

7177
# When building ddtrace from branch, remove extra source files. These are

0 commit comments

Comments
 (0)