Based on my earlier work, it brings me much pleasure to contribute the attached patch (which requires the earlier, lexicographical-order patch to be applied first). The following attached file makes distutils automatically add dependencies to the Requires: field in the RPM spec file, if the egg metadata specifies any primary dependency.
With this patch, it is no longer needed to manually specify your dependencies in both setup.cfg and requires.txt. DRY FTW! regards, -- Manuel Amador (Rudd-O) <rud...@rudd-o.com> Rudd-O.com - http://rudd-o.com/ GPG key ID 0xC8D28B92 at http://wwwkeys.pgp.net/ Some people have a way about them that seems to say: "If I have only one life to live, let me live it as a jerk."
--- 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 <version> <release> +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())
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig