Ticket #1696: make-some-rpms-3-1696.patch

File make-some-rpms-3-1696.patch, 4.1 KB (added by TimAllen, 9 years ago)

A minimal patch based on the current work in #4138

  • new file setup.cfg

    diff --git a/setup.cfg b/setup.cfg
    new file mode 100644
    index 0000000..9dbe235
    - +  
     1# Some RPM-based distributions configure RPM to automatically create .pyo files
     2# when .py files are installed, but don't configure bdist_rpm to add .pyo files
     3# to the list-of-files-to-be-installed. Since RPM will exit with an error if
     4# files are installed that aren't in the list-of-files-to-be-installed, this
     5# prevents bdist_rpm from working. This has been a problem for a very long time
     6# (at least since Fedora 6, if not before), but is due to be fixed in Fedora
     7# 11, with the same workaround we present here. For more details, see the
     8# upstream Fedora bug:
     9#
     10#   https://bugzilla.redhat.com/show_bug.cgi?id=236535
     11#
     12[install]
     13optimize = 1
  • setup.py

    diff --git a/setup.py b/setup.py
    index 529fda5..860e713 100755
    a b def main(args): 
    4444        sys.path.insert(0, '.')
    4545    from twisted import copyright
    4646    from twisted.python.dist import getDataFiles, getScripts, getPackages
    47     from twisted.python.dist import setup, _SDistTwisted
     47    from twisted.python.dist import setup, _SDistTwisted, _BuildPyTwisted
    4848
    4949    # "" is included because core scripts are directly in bin/
    5050    projects = [''] + [x for x in os.listdir('bin')
    on event-based network programming and multiprotocol integration. 
    7474            conditionalExtensions = getExtensions(),
    7575            scripts = scripts,
    7676            data_files=getDataFiles('twisted'),
    77             cmdclass = {'sdist': _SDistTwisted},
     77            cmdclass = {
     78                'sdist': _SDistTwisted,
     79                'build_py': _BuildPyTwisted,
     80                },
    7881            )
    7982
    8083    if 'setuptools' in sys.modules:
  • twisted/python/dist.py

    diff --git a/twisted/python/dist.py b/twisted/python/dist.py
    index 6d91b52..9b89b78 100644
    a b Don't use this outside of Twisted. 
    66Maintainer: Christopher Armstrong
    77"""
    88
     9import sys
    910import os
    10 from distutils.command import (build_scripts, install_data, build_ext,
    11                                sdist)
     11from distutils.command import build_scripts, install_data, build_ext
     12from distutils.command import sdist, build_py
    1213from distutils.errors import CompileError
    1314from distutils import core
    1415from distutils.core import Extension
    class _SDistTwisted(sdist.sdist): 
    377378        builder.buildTwistedFiles(version, basedir)
    378379
    379380        self.distribution.metadata.write_pkg_info(basedir)
     381
     382
     383
     384class _BuildPyTwisted(build_py.build_py):
     385    """
     386    Install Python source files, except the ones we don't want.
     387    """
     388
     389    blacklist = {
     390            (2, 5): [
     391                "twisted/test/generator_failure_tests.py",
     392            ],
     393        }
     394
     395
     396    def _check_file(self, filepath):
     397        incompatible_versions = [v for v in self.blacklist.keys()
     398                if v > sys.version_info]
     399
     400        for version in incompatible_versions:
     401            for victim in self.blacklist[version]:
     402                # Ignore plain Python files
     403                if filepath.endswith(victim):
     404                    print "Rejecting Python script %r" % (victim,)
     405                    return False
     406
     407                # Ignore byte-compiled files
     408                if filepath.endswith(victim + "c"):
     409                    print "Rejecting compiled version of %r" % (victim,)
     410                    return False
     411
     412                # Ignore optimized byte-compiled files
     413                if filepath.endswith(victim + "o"):
     414                    print "Rejecting optimized version of %r" % (victim,)
     415                    return False
     416
     417        return True
     418
     419
     420    def get_outputs(self, *args, **kwargs):
     421        outfiles = build_py.build_py.get_outputs(self, *args, **kwargs)
     422
     423        filtered = [filepath for filepath in outfiles
     424                if self._check_file(filepath)]
     425
     426        assert len(filtered) < len(outfiles)
     427
     428        return filtered
     429
     430
     431    def build_module(self, module, module_file, package):
     432        if self._check_file(module_file):
     433            build_py.build_py.build_module(self, module, module_file, package)