From 5b92a6d9e4208317e61fd9081c60dd041e30c093 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 4 Jun 2020 10:12:07 +0300 Subject: [PATCH] build: drop __pycache__ directories from python3 relocatable package Recently ./reloc/build_deb.sh started failing with dpkg-source: info: using source format '1.0' dpkg-source: info: building scylla-python3 using existing scylla-python3_3.8.3-0.20200604.77dfa4f15.orig.tar.gz dpkg-source: info: building scylla-python3 in scylla-python3_3.8.3-0.20200604.77dfa4f15-1.diff.gz dpkg-source: error: cannot represent change to scylla-python3/lib64/python3.8/site-packages/urllib3/packages/backports/__pycache__/__init__.cpython-38.pyc: dpkg-source: error: new version is plain file dpkg-source: error: old version is symlink to /usr/lib/python3.8/site-packages/__pycache__/six.cpython-38.pyc dpkg-source: error: unrepresentable changes to source dpkg-buildpackage: error: dpkg-source -b . subprocess returned exit status 1 debuild: fatal error at line 1182: Those files are not in fact symlinks, so it's clear that dpkg is confused about something. Rather than debug dpkg, however, it's easier to just drop __pycache__ directories. These hold the result of bytecode compilation and are therefore optional, as Python will compile the sources if the cache is not populated. Fixes #6584. --- scripts/create-relocatable-package-python3.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/create-relocatable-package-python3.py b/scripts/create-relocatable-package-python3.py index 6bd6faf46d..eaa0095ac3 100755 --- a/scripts/create-relocatable-package-python3.py +++ b/scripts/create-relocatable-package-python3.py @@ -60,13 +60,24 @@ def should_copy(f): if f == "": # package with no files return False + # Filtering out files, below, won't work if we copy the directories + # they are in. So filter them out. Tar files are perfectly happy + # to carry a file without the directory it is in. + if os.path.isdir(f): + return False + + parts = list(pathlib.PurePath(f).parts) + + # files in __pycache__ are optimizations, and confuse build_deb + if "__pycache__" in parts: + return False + if f.startswith("/usr/bin/python3."): return f[-1] != "m" # python ships with two binaries, one of them with a specialized malloc (python 3.xm). No need. if f.startswith("/lib64/ld-linux"): # the interpreter is copied by the binary fixup process return False - parts = list(pathlib.PurePath(f).parts) el = parts.pop(0) if el != "/": raise RuntimeError("unexpected path: not absolute! {}".format(f))