mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 04:17:36 -02:30
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
This commit is contained in:
9
setup.py
9
setup.py
@@ -79,8 +79,9 @@ class sdist_awx(_sdist, object):
|
|||||||
new_sources = file(new_sources_path, 'w')
|
new_sources = file(new_sources_path, 'w')
|
||||||
for line in file(sources_txt_path, 'r'):
|
for line in file(sources_txt_path, 'r'):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
# Include both .py and .pyc files to SOURCES.txt
|
||||||
if line in self.pyc_only_files:
|
if line in self.pyc_only_files:
|
||||||
line = line + 'c'
|
line = line + '\n' + line + 'c'
|
||||||
new_sources.write(line + '\n')
|
new_sources.write(line + '\n')
|
||||||
|
|
||||||
def make_distribution(self):
|
def make_distribution(self):
|
||||||
@@ -99,9 +100,13 @@ class sdist_awx(_sdist, object):
|
|||||||
continue
|
continue
|
||||||
if f.endswith('.py'):
|
if f.endswith('.py'):
|
||||||
log.info('using pyc for: %s', f)
|
log.info('using pyc for: %s', f)
|
||||||
|
# Byte compile to create .pyc file
|
||||||
py_compile.compile(f, doraise=True)
|
py_compile.compile(f, doraise=True)
|
||||||
|
# Replace .py with .pyc file
|
||||||
self.filelist.files[n] = f + 'c'
|
self.filelist.files[n] = f + 'c'
|
||||||
self.pyc_only_files.append(f)
|
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()
|
super(sdist_awx, self).make_distribution()
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
@@ -206,7 +211,7 @@ setup(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
cmdclass = {
|
cmdclass = {
|
||||||
'sdist_awx': _sdist,
|
'sdist_awx': sdist_awx,
|
||||||
'install_lib': install_lib,
|
'install_lib': install_lib,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user