Changeset cdc8190 in git


Ignore:
Timestamp:
2012-02-09T23:34:21Z (13 years ago)
Author:
Brian Warner <warner@…>
Branches:
master
Children:
cdb9e79
Parents:
97f23e1
git-author:
Brian Warner <warner@…> (2012-02-09 23:29:43)
git-committer:
Brian Warner <warner@…> (2012-02-09 23:34:21)
Message:

Use versioneer-0.7 to make a version string from git metadata, when possible.

Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified .gitignore

    r97f23e1 rcdc8190  
    33/dist/
    44
    5 # _version.py is generated at build time, and never checked in
    6 /pycryptopp/_version.py
     5# extraversion.h is generated at build time, and never checked in
    76/embeddedcryptopp/extraversion.h
    87
     
    2120/ez_setup.pyc
    2221/pycryptopp/_pycryptopp.so
     22/MANIFEST
  • TabularUnified MANIFEST.in

    r97f23e1 rcdc8190  
    11include copyright COPYING.GPL COPYING.TGPPL.html ChangeLog NEWS.rst README.rst
     2include versioneer.py
    23
    34graft pycryptopp
  • TabularUnified pycryptopp/__init__.py

    r97f23e1 rcdc8190  
    33"""
    44
    5 __version__ = "unknown"
    6 try:
    7     from _version import __version__
    8 except ImportError:
    9     # We're running in a tree that hasn't run "./setup.py update_version",
    10     # and didn't come with a _version.py, so we don't know what our version
    11     # is. This should not happen very often.
    12     pass
     5def _build_versions():
     6    from pycryptopp._version import get_versions
     7    versions = get_versions()
     8    # versions_from_git (as copied from python-versioneer) returns strings
     9    # like "1.9.0-25-gb73aba9-dirty", which means we're in a tree with
     10    # uncommited changes (-dirty), the latest checkin is revision b73aba9,
     11    # the most recent tag was 1.9.0, and b73aba9 has 25 commits that weren't
     12    # in 1.9.0 . The narrow-minded NormalizedVersion parser that takes our
     13    # output (meant to enable sorting of version strings) refuses most of
     14    # that, but accepts things like "1.9.0.post25", or "1.9.0.post25.dev0",
     15    # so dumb down our output to match.
     16    pieces = versions["version"].split("-")
     17    if len(pieces) == 1:
     18        normalized_version = pieces[0]
     19    else:
     20        normalized_version = "%s.post%s" % (pieces[0], pieces[1])
     21    if pieces[-1] == "dirty":
     22        normalized_version += ".dev0"
     23    # this returns e.g.:
     24    #  0.5.29.post51,
     25    #  0.5.29-51-ga81fad1,
     26    #  a81fad1d4afae353a40cf56fe88aa6ef0eea31a8
     27    return versions["version"], normalized_version, versions["full"]
     28__real_version__, __version__, __full_version__ = _build_versions()
     29del _build_versions
    1330
    1431# we import our glue .so here, and then other modules use the copy in
  • TabularUnified setup.py

    r97f23e1 rcdc8190  
    1313from setuptools import Extension, find_packages, setup
    1414from setuptools import Command
     15
     16import versioneer
     17versioneer.versionfile_source = "pycryptopp/_version.py"
     18versioneer.versionfile_build = "pycryptopp/_version.py"
     19versioneer.tag_prefix = "pycryptopp-"
     20versioneer.parentdir_prefix = "pycryptopp-"
    1521
    1622# ECDSA=False
     
    181187
    182188PKG='pycryptopp'
    183 VERSIONFILE = os.path.join(PKG, "_version.py")
    184 verstr = "unknown"
    185 try:
    186     verstrline = open(VERSIONFILE, "rt").read()
    187 except EnvironmentError:
    188     pass # Okay, there is no version file.
    189 else:
    190     VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
    191     mo = re.search(VSRE, verstrline, re.M)
    192     if mo:
    193         verstr = mo.group(1)
    194     else:
    195         print "unable to find version in %s" % (VERSIONFILE,)
    196         raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))
    197189
    198190srcs = ['pycryptopp/_pycryptoppmodule.cpp',
     
    247239###### Version updating code
    248240
    249 PY_GIT_VERSION_BODY = '''
    250 # This _version.py is generated from git metadata by the pycryptopp setup.py.
    251 # The main version number is taken from the most recent release tag. If some
    252 # patches have been added since the last release, this will have a -NN "build
    253 # number" suffix, or else a -rNN "revision number" suffix.
    254 
    255 __pkgname__ = "%(pkgname)s"
    256 real_version = "%(version)s"
    257 full_version = "%(full)s"
    258 verstr = "%(normalized)s"
    259 __version__ = verstr
    260 '''
    261 
    262241CPP_GIT_VERSION_BODY = '''
    263242/* This _version.py is generated from git metadata by the pycryptopp
     
    270249'''
    271250
    272 def run_command(args, cwd=None, verbose=False):
    273     try:
    274         # remember shell=False, so use git.cmd on windows, not just git
    275         p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
    276     except EnvironmentError, e:
    277         if verbose:
    278             print "unable to run %s" % args[0]
    279             print e
    280         return None
    281     stdout = p.communicate()[0].strip()
    282     if p.returncode != 0:
    283         if verbose:
    284             print "unable to run %s (error)" % args[0]
    285         return None
    286     return stdout
    287 
    288 
    289 def versions_from_git(tag_prefix, verbose=False):
    290     # this runs 'git' from the directory that contains this file. That either
    291     # means someone ran a setup.py command (and this code is in
    292     # versioneer.py, thus the containing directory is the root of the source
    293     # tree), or someone ran a project-specific entry point (and this code is
    294     # in _version.py, thus the containing directory is somewhere deeper in
    295     # the source tree). This only gets called if the git-archive 'subst'
    296     # variables were *not* expanded, and _version.py hasn't already been
    297     # rewritten with a short version string, meaning we're inside a checked
    298     # out source tree.
    299 
    300     # versions_from_git (as copied from python-versioneer) returns strings
    301     # like "1.9.0-25-gb73aba9-dirty", which means we're in a tree with
    302     # uncommited changes (-dirty), the latest checkin is revision b73aba9,
    303     # the most recent tag was 1.9.0, and b73aba9 has 25 commits that weren't
    304     # in 1.9.0 . The narrow-minded NormalizedVersion parser that takes our
    305     # output (meant to enable sorting of version strings) refuses most of
    306     # that. Tahoe-LAFS uses a function named suggest_normalized_version()
    307     # that can handle "1.9.0.post25", so dumb down our output to match.
    308 
    309     try:
    310         source_dir = os.path.dirname(os.path.abspath(__file__))
    311     except NameError:
    312         # some py2exe/bbfreeze/non-CPython implementations don't do __file__
    313         return {} # not always correct
    314     GIT = "git"
    315     if sys.platform == "win32":
    316         GIT = "git.cmd"
    317     stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
    318                          cwd=source_dir)
    319     if stdout is None:
    320         return {}
    321     if not stdout.startswith(tag_prefix):
    322         if verbose:
    323             print "tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix)
    324         return {}
    325     version = stdout[len(tag_prefix):]
    326     pieces = version.split("-")
     251def get_normalized_version():
     252    pieces = versioneer.get_versions()["version"].split("-")
    327253    if len(pieces) == 1:
    328254        normalized_version = pieces[0]
    329255    else:
    330256        normalized_version = "%s.post%s" % (pieces[0], pieces[1])
    331     stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=source_dir)
    332     if stdout is None:
    333         return {}
    334     full = stdout.strip()
    335     if version.endswith("-dirty"):
    336         full += "-dirty"
     257    if pieces[-1] == "dirty":
    337258        normalized_version += ".dev0"
    338     return {"version": version, "normalized": normalized_version, "full": full}
    339 
    340 
    341 basedir = os.path.dirname(os.path.abspath(__file__))
    342 VERSIONFILES = [os.path.join('pycryptopp', '_version.py'),
    343                 os.path.join(EMBEDDED_CRYPTOPP_DIR, 'extraversion.h'),
    344                 ]
     259    return normalized_version
     260
    345261
    346262class UpdateVersion(Command):
    347     description = "update _version.py from revision-control metadata"
     263    description = "update extraversion.h from revision-control metadata"
    348264    user_options = []
    349265
     
    353269        pass
    354270    def run(self):
    355         if os.path.isdir(os.path.join(basedir, ".git")):
    356             verstr = self.try_from_git()
    357         else:
    358             print "no version-control data found, leaving _version.py alone"
    359             return
    360         if verstr:
    361             self.distribution.metadata.version = verstr
    362 
    363     def try_from_git(self):
    364         versions = versions_from_git("pycryptopp-", verbose=True)
    365         if versions:
    366             for fn in VERSIONFILES:
    367                 f = open(fn, "wb")
    368                 if fn.endswith(".py"):
    369                     BODY = PY_GIT_VERSION_BODY
    370                 else:
    371                     assert fn.endswith(".h")
    372                     BODY = CPP_GIT_VERSION_BODY
    373                 f.write(BODY %
    374                         { "pkgname": self.distribution.get_name(),
    375                           "version": versions["version"],
    376                           "normalized": versions["normalized"],
    377                           "full": versions["full"] })
    378                 f.close()
    379                 print "git-version: wrote '%s' into '%s'" % (versions["version"], fn)
    380         return versions.get("normalized", None)
     271        versions = versioneer.get_versions()
     272        fn = os.path.join(EMBEDDED_CRYPTOPP_DIR, 'extraversion.h')
     273        f = open(fn, "wb")
     274        BODY = CPP_GIT_VERSION_BODY
     275        f.write(BODY %
     276                { "pkgname": self.distribution.get_name(),
     277                  "version": versions["version"],
     278                  "normalized": get_normalized_version(),
     279                  "full": versions["full"] })
     280        f.close()
     281        print "git-version: wrote '%s' into '%s'" % (versions["version"], fn)
     282
     283commands = versioneer.get_cmdclass().copy()
     284commands["update_version"] = UpdateVersion
    381285
    382286setup(name=PKG,
    383       version=verstr,
     287      version=get_normalized_version(),
    384288      description='Python wrappers for a few algorithms from the Crypto++ library',
    385289      long_description=readmetext,
     
    401305      test_suite=PKG+".test",
    402306      zip_safe=False, # I prefer unzipped for easier access.
    403       cmdclass={"update_version": UpdateVersion},
     307      cmdclass=commands,
    404308      )
Note: See TracChangeset for help on using the changeset viewer.