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.
This commit is contained in:
Avi Kivity
2020-06-04 10:12:07 +03:00
committed by Pekka Enberg
parent a2bb48f44b
commit 5b92a6d9e4

View File

@@ -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))