From ff867df640314e52d1ee0e17233ad5e947c971be Mon Sep 17 00:00:00 2001 From: James Laska Date: Wed, 14 May 2014 12:20:23 -0400 Subject: [PATCH] Include byte-compiled pyc files in sdist tarball Debian doesn't byte-compile .py files during the build process. Packagers are expected to byte-compile in the postinst [1]. The following change adds byte-compiled .pyc files into the sdist tarball. During RPM packaging, the rpm macros will regenerate/replace these files against the appropriate python version. [1] https://wiki.debian.org/Python/Packaging --- setup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 2ddfa23b14..85d9c0ccc2 100755 --- a/setup.py +++ b/setup.py @@ -79,8 +79,9 @@ class sdist_awx(_sdist, object): new_sources = file(new_sources_path, 'w') for line in file(sources_txt_path, 'r'): line = line.strip() + # Include both .py and .pyc files to SOURCES.txt if line in self.pyc_only_files: - line = line + 'c' + line = line + '\n' + line + 'c' new_sources.write(line + '\n') def make_distribution(self): @@ -99,9 +100,13 @@ class sdist_awx(_sdist, object): continue if f.endswith('.py'): log.info('using pyc for: %s', f) + # Byte compile to create .pyc file py_compile.compile(f, doraise=True) + # Replace .py with .pyc file self.filelist.files[n] = f + 'c' self.pyc_only_files.append(f) + # Add .py files back to the filelist + self.filelist.files.extend(self.pyc_only_files) super(sdist_awx, self).make_distribution() ##################################################################### @@ -206,7 +211,7 @@ setup( }, }, cmdclass = { - 'sdist_awx': _sdist, + 'sdist_awx': sdist_awx, 'install_lib': install_lib, }, )