=== modified file 'setup.py' --- setup.py 2008-08-21 21:54:16 +0000 +++ setup.py 2009-02-19 20:43:56 +0000 @@ -72,7 +72,8 @@ ], "setuptools.file_finders": ["svn_cvs = setuptools.command.sdist:_default_revctrl"], - + "setuptools.revision_taggers": + ['svn = setuptools.command.egg_info:get_svn_revision'], "setuptools.installation": ['eggsecutable = setuptools.command.easy_install:bootstrap'], === modified file 'setuptools.egg-info/entry_points.txt' --- setuptools.egg-info/entry_points.txt 2008-08-21 21:54:16 +0000 +++ setuptools.egg-info/entry_points.txt 2009-02-20 10:47:08 +0000 @@ -1,3 +1,6 @@ +[setuptools.revision_taggers] +svn = setuptools.command.egg_info:get_svn_revision + [distutils.commands] bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm rotate = setuptools.command.rotate:rotate === modified file 'setuptools.txt' --- setuptools.txt 2008-09-24 17:05:35 +0000 +++ setuptools.txt 2009-02-20 10:51:11 +0000 @@ -1395,8 +1395,11 @@ (``--tag-build=STRING, -bSTRING``) * A "last-modified revision number" string generated automatically from - Subversion's metadata (assuming your project is being built from a Subversion - "working copy") (``--tag-svn-revision, -r``) + your version control system's metadata. To do this, pass the name of the + version control system to the ``--revision-tagger`` (``-t``) option. + Subversion support is built in, other systems may be available as plugins. + For backwards compatibility, ``--tag-svn-revision, -r`` is also + supported. * An 8-character representation of the build date (``--tag-date, -d``), as a postrelease tag @@ -1552,7 +1555,7 @@ [egg_info] tag_build = .dev - tag_svn_revision = 1 + revision_tagger = svn This will tell ``setuptools`` to generate package version numbers like ``1.0a1.dev-r1263``, which will be considered to be an *older* release than @@ -1981,27 +1984,46 @@ it on the command line using ``-b ""`` or ``--tag-build=""`` as an argument to the ``egg_info`` command. +``--revision-tagger, t`` + If the current directory is version-controlled, and this option is set to + the name of the version control system (VCS), append a string describing the + current revision to the version string. + + If set to 'none', revision tagging is disabled. + + The VCS name may be followed by a colon and more options for the tagger. + + Subversion is supported out of the box (``--revision-tagger=svn``). For + details on how the Subversion version string is generated, see + ``--tag-svn-revision``, below. Plugins can add support for other systems. + + If the current directory is not version-controlled (or a plugin for the + specified VCS is not found), the command will look for a ``PKG-INFO`` + file instead, and try to find the revision number from that, by looking for + a "-rNNNN" string at the end of the version number. (This is so that + building a package from a source distribution of a Subversion snapshot will + produce a binary with the correct version number.) + + If there is no ``PKG-INFO`` file, or the version number contained therein + does not end with ``-r`` and a number, then ``-r0`` is used. + ``--tag-svn-revision, -r`` + Set ``--revision-tagger=svn``. Only works when ``--revision-tagger`` is not + set explicitly. + If the current directory is a Subversion checkout (i.e. has a ``.svn`` subdirectory, this appends a string of the form "-rNNNN" to the project's version string, where NNNN is the revision number of the most recent modification to the current directory, as obtained from the ``svn info`` command. - If the current directory is not a Subversion checkout, the command will - look for a ``PKG-INFO`` file instead, and try to find the revision number - from that, by looking for a "-rNNNN" string at the end of the version - number. (This is so that building a package from a source distribution of - a Subversion snapshot will produce a binary with the correct version - number.) - - If there is no ``PKG-INFO`` file, or the version number contained therein - does not end with ``-r`` and a number, then ``-r0`` is used. - ``--no-svn-revision, -R`` Don't include the Subversion revision in the version number. This option is included so you can override a default setting put in ``setup.cfg``. + It is safer to set ``--revision-tagger=none`` than to use this option, + as ``-R`` won't revert an explicit ``--revision-tagger=svn``. + ``--tag-date, -d`` Add a date stamp of the form "-YYYYMMDD" (e.g. "-20050528") to the project's version number. === modified file 'setuptools/command/egg_info.py' --- setuptools/command/egg_info.py 2008-08-21 19:19:24 +0000 +++ setuptools/command/egg_info.py 2009-02-20 10:46:18 +0000 @@ -20,13 +20,17 @@ user_options = [ ('egg-base=', 'e', "directory containing .egg-info directories" " (default: top of the source tree)"), + ('tag-build=', 'b', "Specify explicit tag to add to version number"), + ('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"), + ('no-date', 'D', "Don't include date stamp [default]"), + ('revision-tagger=', 't', + "Use the supplied revision tagger to tag revisions. Default is " + "'none'."), ('tag-svn-revision', 'r', - "Add subversion revision ID to version number"), - ('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"), - ('tag-build=', 'b', "Specify explicit tag to add to version number"), + "Add subversion revision ID to version number. Same as " + "--revision-tagger=svn"), ('no-svn-revision', 'R', "Don't add subversion revision ID [default]"), - ('no-date', 'D', "Don't include date stamp [default]"), ] boolean_options = ['tag-date', 'tag-svn-revision'] @@ -46,6 +50,7 @@ self.egg_info = None self.tag_build = None self.tag_svn_revision = 0 + self.revision_tagger = None self.tag_date = 0 self.broken_egg_info = False self.vtags = None @@ -55,7 +60,8 @@ edit_config( filename, {'egg_info': - {'tag_svn_revision':0, 'tag_date': 0, 'tag_build': self.tags()} + {'tag_svn_revision':0, 'tag_date': 0, 'tag_build': self.tags(), + 'revision_tagger': None}, } ) @@ -81,6 +87,14 @@ def finalize_options (self): + # Get the revision tagger + # if revision_tagger is not set, look at tag_svn_revision + if self.revision_tagger is None: + if self.tag_svn_revision: + self.revision_tagger = 'svn' + else: + self.revision_tagger = '' + self.egg_name = safe_name(self.distribution.get_name()) self.vtags = self.tags() self.egg_version = self.tagged_version() @@ -180,9 +194,19 @@ version = '' if self.tag_build: version+=self.tag_build - if self.tag_svn_revision and ( - os.path.exists('.svn') or os.path.exists('PKG-INFO') - ): version += '-r%s' % self.get_svn_revision() + if self.revision_tagger: + # Get tagger name by removing first colon and anything after it + tagger_name, dummy, dummy = self.revision_tagger.partition(':') + if tagger_name != 'none': + revision = '' + for entrypoint in iter_entry_points( + "setuptools.revision_taggers", + tagger_name): + tagger = entrypoint.load() + revision = tagger(self.revision_tagger) + if revision: + break + version += revision or '-r' + str(get_pkg_info_revision()) if self.tag_date: import time; version += time.strftime("-%Y%m%d") return version @@ -203,40 +227,6 @@ - def get_svn_revision(self): - revision = 0 - urlre = re.compile('url="([^"]+)"') - revre = re.compile('committed-rev="(\d+)"') - - for base,dirs,files in os.walk(os.curdir): - if '.svn' not in dirs: - dirs[:] = [] - continue # no sense walking uncontrolled subdirs - dirs.remove('.svn') - f = open(os.path.join(base,'.svn','entries')) - data = f.read() - f.close() - - if data.startswith('9') or data.startswith('8'): - data = map(str.splitlines,data.split('\n\x0c\n')) - del data[0][0] # get rid of the '8' or '9' - dirurl = data[0][3] - localrev = max([int(d[9]) for d in data if len(d)>9 and d[9]]+[0]) - elif data.startswith('9 and d[9]]+[0]) + elif data.startswith('