--- Lib/distutils/command/bdist_rpm.py 2009-03-12 22:12:28.000000000 -0500 +++ Lib/distutils/command/bdist_rpm.py 2009-03-12 22:14:08.000000000 -0500 @@ -55,6 +55,65 @@ print "%s-%s %s-%s"%(sys.argv[2],sys.argv[3],v,r) +def auto_requires(): + + try: import pkg_resources # no setuptools? + except ImportError: return "" # no autodeps! + + try: # is there a requires.txt file in this dir? then use the requirements + requirestext = file( + glob.glob( + os.path.join("*.egg-info","requires.txt") + )[0]).read() + requirestext = requirestext.split("[")[0] + except IndexError: # no requires.txt file? go on without it then + requirestext = "" + + # parse the list of requirements + parsed_reqs = list( + pkg_resources.parse_requirements( + "python\n" + requirestext)) + + for req in parsed_reqs: + # 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] + + # now time to munge the version numbers + # to conform to the RPM lexicographical order + if req.specs: + newspecs = [] + for spec in req.specs: + verb,vers = spec + spec = (verb,"%s-%s"%rewrite_lexicographically(vers,"1")) + newspecs.append(spec) + req.specs = newspecs + + # stringify requirements + reqstrs = [] + for req in parsed_reqs: + if req.specs: + for spec in req.specs: + n = req.project_name + o,v = spec + reqstrs.append( "%s %s %s" % (n,o,v) ) + else: reqstrs.append(req.project_name) + + # return the requirements ready to be tacked + # onto the Requires: line in the spec file + return ", ".join(reqstrs) + +# this is so you can test me by running python bdist_rpm.py rewrite +if __name__ == "__main__" and "requires" in sys.argv: + print auto_requires() + + class bdist_rpm (Command): description = "create an RPM distribution" @@ -484,6 +543,8 @@ elif val is not None: spec_file.append('%s: %s' % (field, val)) + auto_reqs = auto_requires() + if auto_reqs: spec_file.append("Requires: %s"%auto_reqs) if self.distribution.get_url() != 'UNKNOWN': spec_file.append('Url: ' + self.distribution.get_url())