summaryrefslogtreecommitdiff
path: root/darcsver-1.6.3.egg/darcsver
diff options
context:
space:
mode:
authorbertagaz <bertagaz@ptitcanardnoir.org>2011-06-14 15:26:19 +0200
committerbertagaz <bertagaz@ptitcanardnoir.org>2011-06-14 15:26:19 +0200
commit30e9097985656920f01a72efc1088caa2b8d41b3 (patch)
treebedbdb1aaa484af467e538110ab4c0c95985b6b8 /darcsver-1.6.3.egg/darcsver
Imported Upstream version 0.5.29upstream/0.5.29
Diffstat (limited to 'darcsver-1.6.3.egg/darcsver')
-rw-r--r--darcsver-1.6.3.egg/darcsver/__init__.py8
-rw-r--r--darcsver-1.6.3.egg/darcsver/_version.py17
-rw-r--r--darcsver-1.6.3.egg/darcsver/darcsvermodule.py192
-rw-r--r--darcsver-1.6.3.egg/darcsver/setuptools_command.py116
4 files changed, 333 insertions, 0 deletions
diff --git a/darcsver-1.6.3.egg/darcsver/__init__.py b/darcsver-1.6.3.egg/darcsver/__init__.py
new file mode 100644
index 0000000..3421c13
--- /dev/null
+++ b/darcsver-1.6.3.egg/darcsver/__init__.py
@@ -0,0 +1,8 @@
+__version__ = "unknown"
+try:
+ from _version import __version__
+except ImportError:
+ # We're running in a tree that hasn't run darcsver, and didn't come with a
+ # _version.py, so we don't know what our version is. This should not happen
+ # very often.
+ pass
diff --git a/darcsver-1.6.3.egg/darcsver/_version.py b/darcsver-1.6.3.egg/darcsver/_version.py
new file mode 100644
index 0000000..9d41f7d
--- /dev/null
+++ b/darcsver-1.6.3.egg/darcsver/_version.py
@@ -0,0 +1,17 @@
+
+# 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.
+
+__pkgname__ = "darcsver"
+verstr = "1.6.3"
+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)
diff --git a/darcsver-1.6.3.egg/darcsver/darcsvermodule.py b/darcsver-1.6.3.egg/darcsver/darcsvermodule.py
new file mode 100644
index 0000000..4f03572
--- /dev/null
+++ b/darcsver-1.6.3.egg/darcsver/darcsvermodule.py
@@ -0,0 +1,192 @@
+import os, string, sys, re
+import xml.dom.minidom
+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, AttributeError):
+ # Else (perhaps a bootstrapping problem),then we'll use this
+ # regex, which was copied from the pyutil source code on
+ # 2010-09-02.
+ VERSION_BASE_RE_STR=OUR_VERSION_BASE_RE_STR
+
+def get_text(nodelist):
+ rc = ""
+ for node in nodelist:
+ if node.nodeType == node.TEXT_NODE:
+ rc = rc + node.data
+ return rc
+
+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.
+ from distutils.version import LooseVersion as distutils_Version
+ __version__ = distutils_Version(verstr)
+'''
+
+def write_version_py(verstr, outfname, EXE_NAME, version_body, pkgname):
+ f = open(outfname, "wt+")
+ f.write(version_body % {
+ 'versiontool': EXE_NAME,
+ 'pkgversion': verstr,
+ 'pkgname': pkgname,
+ })
+ f.close()
+
+def read_version_py(infname):
+ try:
+ verstrline = open(infname, "rt").read()
+ except EnvironmentError:
+ return None
+ else:
+ VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
+ mo = re.search(VSRE, verstrline, re.M)
+ if mo:
+ return mo.group(1)
+
+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
+ release tag.
+
+ 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
+
+ # 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 = 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('~'))
+ msg = ("WARNING: 'darcs' 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,))
+ pass
+ else:
+ (output, errput) = p.communicate()
+ rc = p.returncode
+
+ if rc == 0:
+ cmd = ["changes", "--xml-output"]
+ if not revision_number:
+ cmd.append("--from-tag=^%s" % (pkgname,))
+ errput = None
+ try:
+ 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 and errput:
+ log.info("%s: darcs wrote to stderr: '%s'" % (EXE_NAME, errput,))
+ 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.)
+ allbadchars = "".join([chr(i) for i in range(0x0a) + [0x0b, 0x0c] + range(0x0e, 0x20) + range(0x7f,0x100)])
+ tt = string.maketrans(allbadchars, "-"*len(allbadchars))
+ output = output.translate(tt)
+
+ # strip off trailing warning messages that darcs 2.3.1 writes to stdout
+ endi = output.find("</changelog>")+len("</changelog>")
+ output = output[:endi]
+ doc = xml.dom.minidom.parseString(output)
+
+ changelog = doc.getElementsByTagName("changelog")[0]
+ patches = changelog.getElementsByTagName("patch")
+ regexstr = "^TAG %s-(%s)$" % (pkgname, VERSION_BASE_RE_STR)
+ version_re = re.compile(regexstr)
+ last_tag = None
+ count_since_last_patch = 0
+ if abort_if_snapshot:
+ for patch in patches:
+ name = get_text(patch.getElementsByTagName("name")[0].childNodes)
+ m = version_re.match(name)
+ if m:
+ last_tag = m.group(1)
+ last_tag = last_tag.encode("utf-8")
+ break
+ else:
+ sys.exit(0) # because abort_if_snapshot
+ else:
+ for patch in patches:
+ name = get_text(patch.getElementsByTagName("name")[0].childNodes)
+ m = version_re.match(name)
+ if m:
+ last_tag = m.group(1)
+ last_tag = last_tag.encode("utf-8")
+ break
+ else:
+ count_since_last_patch += 1
+
+ if not last_tag:
+ if errput:
+ log.info("%s: darcs wrote to stderr: '%s'" % (EXE_NAME, errput,))
+ 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 don't exist." % (EXE_NAME, regexstr, verfilenames,))
+ return (0, None)
+
+ if revision_number:
+ if count_since_last_patch:
+ # this is an interim version
+ verstr = "%s-r%d" % (last_tag, len(patches))
+ else:
+ # this is a release
+ verstr = last_tag
+ else:
+ if count_since_last_patch:
+ # this is an interim version
+ verstr = "%s-%d" % (last_tag, count_since_last_patch)
+ else:
+ # this is a release
+ verstr = last_tag
+
+ 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)
diff --git a/darcsver-1.6.3.egg/darcsver/setuptools_command.py b/darcsver-1.6.3.egg/darcsver/setuptools_command.py
new file mode 100644
index 0000000..44fd50c
--- /dev/null
+++ b/darcsver-1.6.3.egg/darcsver/setuptools_command.py
@@ -0,0 +1,116 @@
+import os
+
+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 = [
+ ('project-name', None, "name of the project as it appears in the project's release tags (default's the to the distribution name)"),
+ ('version-file', None, "path to file into which the version number should be written (defaults to the package directory's _version.py)"),
+ ('count-all-patches', None, "If true, count the total number of patches in all history. If false, count the total number of patches since the most recent release tag."),
+ ('abort-if-snapshot', None, "If true, the if the current version is a snapshot (not a release tag), then immediately exit the process with exit code 0."),
+ ]
+
+ def initialize_options(self):
+ self.project_name = None
+ self.version_file = None
+ self.count_all_patches = None
+ self.abort_if_snapshot = None
+
+ def finalize_options(self):
+ if self.project_name is None:
+ self.project_name = self.distribution.get_name()
+
+ # 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.
+ packagedir = None
+ if self.distribution.packages and self.project_name in self.distribution.packages:
+ toppackage = self.project_name
+ srcdir = ''
+ if self.distribution.package_dir:
+ srcdir = self.distribution.package_dir.get(toppackage)
+ if not srcdir is None:
+ srcdir = self.distribution.package_dir.get('', '')
+ packagedir = os.path.join(srcdir, toppackage)
+
+ if packagedir is None or not os.path.isdir(packagedir):
+ # Else, if there is a singly-rooted tree of packages, use the
+ # root of that.
+ if self.distribution.packages:
+ for package in self.distribution.packages:
+ if not toppackage:
+ toppackage = package
+ else:
+ if toppackage.startswith(package+"."):
+ toppackage = package
+ else:
+ if not package.startswith(toppackage+"."):
+ # Not singly-rooted
+ toppackage = ''
+ break
+
+ srcdir = ''
+ if self.distribution.package_dir:
+ srcdir = self.distribution.package_dir.get(toppackage)
+ if srcdir is None:
+ srcdir = self.distribution.package_dir.get('', '')
+ packagedir = os.path.join(srcdir, toppackage)
+
+ self.distribution.versionfiles = [os.path.join(packagedir, '_version.py')]
+
+ if self.distribution.versionbodies is None:
+ self.distribution.versionbodies = [PYTHON_VERSION_BODY]
+
+ (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