--- Lib/distutils/command/bdist_rpm.py 2009-03-18 07:46:07.000000000 -0500 +++ Lib/distutils/command/bdist_rpm.py 2009-03-18 09:44:57.000000000 -0500 @@ -55,6 +55,12 @@ print "%s-%s %s-%s"%(sys.argv[2],sys.argv[3],v,r) +def rpm_package_name(name): + if name == "python": return name + if name.lower().startswith("py"): return "%s-py%s.%s"%(name,sys.version_info[0],sys.version_info[1]) + return "python-%s-py%s.%s"%(name,sys.version_info[0],sys.version_info[1]) + + def auto_requires(): try: import pkg_resources # no setuptools? @@ -78,12 +84,7 @@ # these requirements are not in the Cheese Shop # but they are commonly packaged in distros with this name # so we make the RPM depend on them if they were required - renamemap = { - "setuptools" : "python-setuptools", - "elementtree" : "python-elementtree" - } - if req.project_name in renamemap.keys(): - req.project_name = renamemap[req.project_name] + req.project_name = rpm_package_name(req.project_name) # now time to munge the version numbers # to conform to the RPM lexicographical order @@ -305,6 +306,7 @@ "cannot supply both '--source-only' and '--binary-only'" # don't pass CFLAGS to pure python distributions + if not self.distribution.has_ext_modules(): self.use_rpm_opt_flags = 0 @@ -491,9 +493,15 @@ version = self.distribution.get_version() release = self.release + # we now mangle the version and release so that pre-release RPMs do not upgrade final release ones version, release = rewrite_lexicographically(version,release) spec_file.insert(3,"%define version " + version) spec_file.insert(4,"%define release " + release) + # and we also mangle the package name to conform to the python package name guidelines in RPM + spec_file.insert(5,'%define name ' + rpm_package_name(self.distribution.get_name())) + spec_file.insert(6,'%define originalname ' + self.distribution.get_name()) + spec_file.insert(7,'%define originalversion ' + self.distribution.get_version()) + # put locale summaries into spec file # XXX not supported for now (hard to put a dictionary @@ -511,9 +519,9 @@ # but only after it has run: and we create the spec file before # running "sdist", in case of --spec-only. if self.use_bzip2: - spec_file.append('Source0: %{name}-%{version}.tar.bz2') + spec_file.append('Source0: %{originalname}-%{originalversion}.tar.bz2') else: - spec_file.append('Source0: %{name}-%{version}.tar.gz') + spec_file.append('Source0: %{originalname}-%{originalversion}.tar.gz') license = self.distribution.get_license() if len(license.splitlines()) > 1: license = "Other" @@ -591,13 +599,38 @@ # that we open and interpolate into the spec file, but the defaults # are just text that we drop in as-is. Hmmm. + # this snippet has one responsibility: remove from the manifest + # any listed files that were not successfully compiled. + # this is necessary because, under some circumstances, .py files + # are uncompileable (Plone skin packages come to mind). + prune_uncompiled_files = """ +%s -c ' +import os +root = os.getenv("RPM_BUILD_ROOT") +newmanifest = [] +for line in file("INSTALLED_FILES").readlines(): + line = line.strip() + if line.endswith(".pyc") or line.endswith(".pyo"): + if not os.path.exists(root + line): continue + newmanifest.append(line.replace(" ","?")) +file("INSTALLED_FILES","w").write("\\n".join(newmanifest)) +' +"""%self.python + + # optimize by default on RPM installation, otherwise SELinux barks real bad + if "install" in self.distribution.command_options and "optimize" in self.distribution.command_options["install"]: + optimize = "-O%s"%str(self.distribution.command_options["install"]["optimize"][1]) + else: + optimize = "-O1" script_options = [ - ('prep', 'prep_script', "%setup"), + ('prep', 'prep_script', "%setup -n %{originalname}-%{originalversion}"), ('build', 'build_script', def_build), ('install', 'install_script', ("%s install " "--root=$RPM_BUILD_ROOT " - "--record=INSTALLED_FILES") % def_setup_call), + "--record=INSTALLED_FILES " + "%s " + "%s") % (def_setup_call,optimize,prune_uncompiled_files)), ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"), ('verifyscript', 'verify_script', None), ('pre', 'pre_install', None),