setup: upgrade bundled copy of darcsver to v1.6.3

This commit is contained in:
Zooko O'Whielacronx 2010-09-21 00:30:46 -07:00
parent 76594cb955
commit 548e587d86
15 changed files with 258 additions and 99 deletions

View File

@ -1,32 +0,0 @@
Metadata-Version: 1.0
Name: darcsver
Version: 1.5.1
Summary: generate a version number from darcs history
Home-page: http://allmydata.org/trac/darcsver
Author: Zooko O'Whielacronx
Author-email: zooko@zooko.com
License: BSD
Description: UNKNOWN
Keywords: distutils setuptools plugin setup darcs
Platform: UNKNOWN
Classifier: Framework :: Setuptools Plugin
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: BSD License
Classifier: License :: DFSG approved
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: POSIX
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows :: Windows NT/2000
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.4
Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Topic :: Utilities
Classifier: Topic :: Software Development :: Libraries

View File

@ -1,6 +0,0 @@
[console_scripts]
darcsver = scripts.darcsverscript:main
[distutils.commands]
darcsver = darcsver.setuptools_command:DarcsVer

View File

@ -0,0 +1,121 @@
Metadata-Version: 1.0
Name: darcsver
Version: 1.6.3
Summary: generate a version number from darcs history
Home-page: http://tahoe-lafs.org/trac/darcsver
Author: Zooko O'Whielacronx
Author-email: zooko@zooko.com
License: BSD
Description: darcsver - generate version numbers from darcs revision control history
=======================================================================
What Does It Do
---------------
Create files containing version numbers, based upon the latest darcs
release tag.
If your source tree is coming from darcs (i.e. it is in a darcs
repository), this tool will determine the most recent release tag,
count the patches that have been applied since then, and compute a
version number to be written into _version.py (and optionally other
version files). This version number will be available by doing:
from your_package_name import __version__
Source trees that do not come from darcs (e.g. release tarballs, nightly
tarballs) and are not within a darcs repository should instead, come with a
_version.py that was generated before the tarball was produced. In this case,
this tool will quietly exit without modifying the existing _version.py .
'release tags' are tags in the source repository that match the following
regexp:
^your_package_name-(\d+)(\.(\d+)(\.(\d+))?)?((a|b|c|rc)(\d+))?
Installation
------------
With easy_install:
easy_install darcsver
Alternative manual installation:
tar -zxvf darcsver-X.Y.Z.tar.gz
cd darcsver-X.Y.Z
python setup.py install
Where X.Y.Z is a version number.
Alternative to make a specific package use darcsver without installing
darcsver into the system:
Put "setup_requires=['darcsver']" in the call to setup() in the
package's setup.py file.
Usage
-----
There are two ways to use this: the command-line tool and the
setuptools plugin.
To use the command-line tool, execute it as:
darcsver $PACKAGE_NAME $PATH_TO_VERSION_PY
To use the setuptools plugin (which enables you to write "./setup.py
darcsver" and which cleverly figures out where the _version.py file
ought to go), you must first package your python module with
`setup.py` and use setuptools.
The former is well documented in the distutils manual:
http://docs.python.org/dist/dist.html
To use setuptools instead of distutils, just edit `setup.py` and
change
from distutils.core import setup
to
from setuptools import setup
References
----------
How to distribute Python modules with Distutils:
http://docs.python.org/dist/dist.html
Setuptools complete manual:
http://peak.telecommunity.com/DevCenter/setuptools
Thanks to Yannick Gingras for providing the prototype for this
README.txt.
Keywords: distutils setuptools plugin setup darcs
Platform: UNKNOWN
Classifier: Framework :: Setuptools Plugin
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: BSD License
Classifier: License :: DFSG approved
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.4
Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Topic :: Utilities
Classifier: Topic :: Software Development :: Libraries

View File

@ -1,6 +1,5 @@
README.txt
TODO
setup.cfg
setup.py
darcsver/__init__.py
darcsver/_version.py
@ -12,5 +11,7 @@ darcsver.egg-info/dependency_links.txt
darcsver.egg-info/entry_points.txt
darcsver.egg-info/not-zip-safe
darcsver.egg-info/top_level.txt
darcsver/test/__init__.py
darcsver/test/test_darcsver.py
scripts/__init__.py
scripts/darcsverscript.py

View File

@ -0,0 +1,10 @@
[distutils.setup_keywords]
versionbodies = darcsver.setuptools_command:validate_versionbodies
versionfiles = darcsver.setuptools_command:validate_versionfiles
[console_scripts]
darcsver = scripts.darcsverscript:main
[distutils.commands]
darcsver = darcsver.setuptools_command:DarcsVer

View File

@ -1,11 +1,12 @@
# This is the version of this tree, as created by setup.py darcsver from the Darcs patch
# This is the version of this tree, as created by setup.py darcsver from the darcs patch
# information: the main version number is taken from the most recent release
# tag. If some patches have been added since the last release, this will have a
# -NN "build number" suffix, or else a -rNN "revision number" suffix. Please see
# pyutil.version_class for a description of what the different fields mean.
verstr = "1.5.1"
__pkgname__ = "darcsver"
verstr = "1.6.3"
try:
from pyutil.version_class import Version as pyutil_Version
__version__ = pyutil_Version(verstr)

View File

@ -1,18 +1,25 @@
import os, string, sys, re
import xml.dom.minidom
import xml.parsers.expat
from subprocess import Popen, PIPE
import subprocess
PIPE=subprocess.PIPE
from distutils import log
def all(iterable):
for thing in iterable:
if not thing:
return False
return True
OUR_VERSION_BASE_RE_STR="(\d+)(\.(\d+)(\.(\d+))?)?((a|b|c)(\d+))?(\.dev(\d+))?"
try:
# If we can import pyutil.version_class then use its regex.
from pyutil import version_class
VERSION_BASE_RE_STR = version_class.VERSION_BASE_RE_STR
except ImportError:
except (ImportError, AttributeError):
# Else (perhaps a bootstrapping problem),then we'll use this
# regex, which was copied from the pyutil source code on
# 2007-10-30.
VERSION_BASE_RE_STR="(\d+)(\.(\d+)(\.(\d+))?)?((a|b|c)(\d+))?"
# 2010-09-02.
VERSION_BASE_RE_STR=OUR_VERSION_BASE_RE_STR
def get_text(nodelist):
rc = ""
@ -22,26 +29,30 @@ def get_text(nodelist):
return rc
VERSION_BODY = '''
# This is the version of this tree, as created by %s from the Darcs patch
# This is the version of this tree, as created by %(versiontool)s from the darcs patch
# information: the main version number is taken from the most recent release
# tag. If some patches have been added since the last release, this will have a
# -NN "build number" suffix, or else a -rNN "revision number" suffix. Please see
# pyutil.version_class for a description of what the different fields mean.
verstr = "%s"
__pkgname__ = "%(pkgname)s"
verstr = "%(pkgversion)s"
try:
from pyutil.version_class import Version as pyutil_Version
__version__ = pyutil_Version(verstr)
except (ImportError, ValueError):
# Maybe there is no pyutil installed, or this may be an older version of
# pyutil.version_class which does not support SVN-alike revision numbers.
# Maybe there is no pyutil installed.
from distutils.version import LooseVersion as distutils_Version
__version__ = distutils_Version(verstr)
'''
def write_version_py(verstr, outfname, EXE_NAME):
def write_version_py(verstr, outfname, EXE_NAME, version_body, pkgname):
f = open(outfname, "wt+")
f.write(VERSION_BODY % (EXE_NAME, verstr,))
f.write(version_body % {
'versiontool': EXE_NAME,
'pkgversion': verstr,
'pkgname': pkgname,
})
f.close()
def read_version_py(infname):
@ -55,7 +66,7 @@ def read_version_py(infname):
if mo:
return mo.group(1)
def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_snapshot=False, EXE_NAME="darcsver"):
def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_snapshot=False, EXE_NAME="darcsver", version_body=VERSION_BODY):
"""
@param revision_number If true, count the total number of patches in all
history. If false, count the total number of patches since the most recent
@ -63,14 +74,21 @@ def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_sna
Returns a tuple of (exit code, new version string).
"""
if isinstance(verfilename, basestring):
verfilenames = [verfilename]
else:
verfilenames = verfilename
if isinstance(version_body, basestring):
verbodies = [version_body]
else:
verbodies = version_body
rc = -1
cmd = ["changes", "--xml-output"]
if not revision_number:
cmd.append("--from-tag=^%s" % (pkgname,))
errput = None
# First we try "darcs query repo" because if that fails then we
# won't try "darcs changes" at all, because "darcs changes" emits
# an ugly error message when run in not-a-repo.
try:
p = Popen(["darcs"] + cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
p = subprocess.Popen(["darcs", 'query', 'repo'], stdout=PIPE, stderr=PIPE, universal_newlines=True)
except OSError, ose:
if ose.errno == 2 and '~' in os.environ['PATH']:
expanded_path = os.environ['PATH'].replace('~', os.path.expanduser('~'))
@ -82,29 +100,28 @@ def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_sna
else:
(output, errput) = p.communicate()
rc = p.returncode
if rc != 0:
if rc == 0:
cmd = ["changes", "--xml-output"]
if not revision_number:
cmd.append("--from-tag=^%s" % (pkgname,))
errput = None
try:
p = Popen(["realdarcs.exe"] + cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
except OSError, ose:
if ose.errno == 2 and '~' in os.environ['PATH']:
expanded_path = os.environ['PATH'].replace('~', os.path.expanduser('~'))
msg = ("WARNING: 'realdarcs.exe' was not found. However '~' was found in your PATH. \n"
"Please note that bugs in python cause it to fail to traverse '~' in \n"
"the user's PATH. Please fix your path, e.g. \nPATH=%s" )
log.warn(msg % (expanded_path,))
p = subprocess.Popen(["darcs"] + cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
except OSError:
pass
else:
(output, errput) = p.communicate()
rc = p.returncode
if rc != 0:
if errput:
if rc != 0 and errput:
log.info("%s: darcs wrote to stderr: '%s'" % (EXE_NAME, errput,))
if os.path.exists(verfilename):
log.info("%s: Failure from attempt to find version tags with 'darcs changes', and %s already exists, so leaving it alone." % (EXE_NAME, verfilename,))
return (0, read_version_py(verfilename))
else:
log.warn("%s: Failure from attempt to find version tags with 'darcs changes', and %s doesn't exist." % (EXE_NAME, verfilename))
return (rc, None)
else:
if all([os.path.exists(vfn) for vfn in verfilenames]):
log.info("%s: using extant version file %s" % (EXE_NAME, verfilenames))
return (0, read_version_py(verfilenames[0]))
else:
log.warn("%s: didn't find version tags with darcs, and %s don't exist." % (EXE_NAME, verfilenames))
return (rc, None)
# Filter out bad chars that can cause the XML parser to give up in despair.
# (Thanks to lelit of the tailor project and ndurner and warner for this hack.)
@ -115,15 +132,11 @@ def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_sna
# strip off trailing warning messages that darcs 2.3.1 writes to stdout
endi = output.find("</changelog>")+len("</changelog>")
output = output[:endi]
try:
doc = xml.dom.minidom.parseString(output)
except xml.parsers.expat.ExpatError, le:
le.args = tuple(le.args + (output,))
raise
doc = xml.dom.minidom.parseString(output)
changelog = doc.getElementsByTagName("changelog")[0]
patches = changelog.getElementsByTagName("patch")
regexstr = "^TAG %s-(%s)" % (pkgname, VERSION_BASE_RE_STR,)
regexstr = "^TAG %s-(%s)$" % (pkgname, VERSION_BASE_RE_STR)
version_re = re.compile(regexstr)
last_tag = None
count_since_last_patch = 0
@ -151,11 +164,11 @@ def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_sna
if not last_tag:
if errput:
log.info("%s: darcs wrote to stderr: '%s'" % (EXE_NAME, errput,))
if os.path.exists(verfilename):
log.warn("%s: I'm unable to find a tag in the darcs history matching \"%s\", so I'm leaving %s alone." % (EXE_NAME, regexstr, verfilename,))
return (0, read_version_py(verfilename))
if all([os.path.exists(vfn) for vfn in verfilenames]):
log.warn("%s: I'm unable to find a tag in the darcs history matching \"%s\", so I'm leaving %s alone." % (EXE_NAME, regexstr, verfilenames,))
return (0, read_version_py(verfilenames[0]))
else:
log.warn("%s: I'm unable to find a tag in the darcs history matching \"%s\", and %s doesn't exist." % (EXE_NAME, regexstr, verfilename,))
log.warn("%s: I'm unable to find a tag in the darcs history matching \"%s\", and %s don't exist." % (EXE_NAME, regexstr, verfilenames,))
return (0, None)
if revision_number:
@ -173,6 +186,7 @@ def update(pkgname, verfilename, revision_number=False, loud=False, abort_if_sna
# this is a release
verstr = last_tag
write_version_py(verstr, verfilename, EXE_NAME)
log.info("%s: wrote '%s' into %s" % (EXE_NAME, verstr, verfilename,))
for verfn, verbod in zip(verfilenames, verbodies):
write_version_py(verstr, verfn, EXE_NAME, verbod, pkgname)
log.info("%s: wrote '%s' into %s" % (EXE_NAME, verstr, verfn,))
return (0, verstr)

View File

@ -4,6 +4,44 @@ import setuptools
from darcsver import darcsvermodule
from distutils.errors import DistutilsSetupError
def validate_string_or_iter_of_strings(dist, attr, value):
# value is required to be a string or else a list of strings
if isinstance(value, basestring):
return
try:
for thing in value:
if not isinstance(thing, basestring):
raise DistutilsSetupError("%r is required to be a string or an iterable of strings (got %r)" % (attr, value))
except TypeError:
raise DistutilsSetupError("%r is required to be a string or an iterable of strings (got %r)" % (attr, value))
def validate_versionfiles(dist, attr, value):
return validate_string_or_iter_of_strings(dist, attr, value)
def validate_versionbodies(dist, attr, value):
return validate_string_or_iter_of_strings(dist, attr, value)
PYTHON_VERSION_BODY='''
# This is the version of this tree, as created by %(versiontool)s from the darcs patch
# information: the main version number is taken from the most recent release
# tag. If some patches have been added since the last release, this will have a
# -NN "build number" suffix, or else a -rNN "revision number" suffix. Please see
# pyutil.version_class for a description of what the different fields mean.
__pkgname__ = "%(pkgname)s"
verstr = "%(pkgversion)s"
try:
from pyutil.version_class import Version as pyutil_Version
__version__ = pyutil_Version(verstr)
except (ImportError, ValueError):
# Maybe there is no pyutil installed, or this may be an older version of
# pyutil.version_class which does not support SVN-alike revision numbers.
from distutils.version import LooseVersion as distutils_Version
__version__ = distutils_Version(verstr)
'''
class DarcsVer(setuptools.Command):
description = "generate a version number from darcs history"
user_options = [
@ -23,7 +61,16 @@ class DarcsVer(setuptools.Command):
if self.project_name is None:
self.project_name = self.distribution.get_name()
if self.version_file is None:
# If the user passed --version-file on the cmdline, override
# the setup.py's versionfiles argument.
if self.version_file is not None:
self.distribution.versionfiles = [self.version_file]
if self.abort_if_snapshot is None:
self.abort_if_snapshot=False
def run(self):
if self.distribution.versionfiles is None:
toppackage = ''
# If there is a package with the same name as the project name and
# there is a directory by that name then use that.
@ -60,11 +107,10 @@ class DarcsVer(setuptools.Command):
srcdir = self.distribution.package_dir.get('', '')
packagedir = os.path.join(srcdir, toppackage)
self.version_file = os.path.join(packagedir, '_version.py')
self.distribution.versionfiles = [os.path.join(packagedir, '_version.py')]
if self.abort_if_snapshot is None:
self.abort_if_snapshot=False
if self.distribution.versionbodies is None:
self.distribution.versionbodies = [PYTHON_VERSION_BODY]
def run(self):
(rc, verstr) = darcsvermodule.update(self.project_name, self.version_file, self.count_all_patches, abort_if_snapshot=self.abort_if_snapshot, EXE_NAME="setup.py darcsver")
(rc, verstr) = darcsvermodule.update(self.project_name, self.distribution.versionfiles, self.count_all_patches, abort_if_snapshot=self.abort_if_snapshot, EXE_NAME="setup.py darcsver", version_body=self.distribution.versionbodies)
self.distribution.metadata.version = verstr

View File

@ -1,13 +1,17 @@
darcsver - generate version numbers from darcs revision control history
=======================================================================
What Does It Do
---------------
Create _version.py, based upon the latest darcs release tag.
Create files containing version numbers, based upon the latest darcs
release tag.
If your source tree is coming from darcs (i.e. it is in a darcs repository),
this tool will determine the most recent release tag, count the patches that
have been applied since then, and compute a version number to be written into
_version.py . This version number will be available by doing:
If your source tree is coming from darcs (i.e. it is in a darcs
repository), this tool will determine the most recent release tag,
count the patches that have been applied since then, and compute a
version number to be written into _version.py (and optionally other
version files). This version number will be available by doing:
from your_package_name import __version__
@ -19,7 +23,7 @@ this tool will quietly exit without modifying the existing _version.py .
'release tags' are tags in the source repository that match the following
regexp:
^your_package_name-\d+\.\d+(\.\d+)?((a|b|c)(\d+)?)?\w*$
^your_package_name-(\d+)(\.(\d+)(\.(\d+))?)?((a|b|c|rc)(\d+))?
Installation