Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'release' into stabilization

  • Loading branch information...
commit ded70e01ec58260ffe574b25a00b9058aa5ae942 2 parents 7152df1 + 4e64952
KWierso authored January 26, 2012

Showing 1 changed file with 57 additions and 15 deletions. Show diff stats Hide diff stats

  1. 72  python-lib/cuddlefish/_version.py
72  python-lib/cuddlefish/_version.py
@@ -5,7 +5,7 @@
5 5
 # directories (produced by setup.py build) will contain a much shorter file
6 6
 # that just contains the computed version number.
7 7
 
8  
-# This file is released into the public domain. Generated by versioneer-0.4
  8
+# This file is released into the public domain. Generated by versioneer-0.6
9 9
 # (https://github.com/warner/python-versioneer)
10 10
 
11 11
 # these strings will be replaced by git during git-archive
@@ -80,27 +80,36 @@ def versions_from_expanded_variables(variables, tag_prefix):
80 80
     return { "version": variables["full"].strip(),
81 81
              "full": variables["full"].strip() }
82 82
 
83  
-def versions_from_vcs(tag_prefix, verbose=False):
84  
-    # this runs 'git' from the directory that contains this file. That either
85  
-    # means someone ran a setup.py command (and this code is in
86  
-    # versioneer.py, thus the containing directory is the root of the source
87  
-    # tree), or someone ran a project-specific entry point (and this code is
88  
-    # in _version.py, thus the containing directory is somewhere deeper in
89  
-    # the source tree). This only gets called if the git-archive 'subst'
90  
-    # variables were *not* expanded, and _version.py hasn't already been
91  
-    # rewritten with a short version string, meaning we're inside a checked
92  
-    # out source tree.
  83
+def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
  84
+    # this runs 'git' from the root of the source tree. That either means
  85
+    # someone ran a setup.py command (and this code is in versioneer.py, thus
  86
+    # the containing directory is the root of the source tree), or someone
  87
+    # ran a project-specific entry point (and this code is in _version.py,
  88
+    # thus the containing directory is somewhere deeper in the source tree).
  89
+    # This only gets called if the git-archive 'subst' variables were *not*
  90
+    # expanded, and _version.py hasn't already been rewritten with a short
  91
+    # version string, meaning we're inside a checked out source tree.
93 92
 
94 93
     try:
95  
-        source_dir = os.path.dirname(os.path.abspath(__file__))
  94
+        here = os.path.abspath(__file__)
96 95
     except NameError:
97 96
         # some py2exe/bbfreeze/non-CPython implementations don't do __file__
98 97
         return {} # not always correct
  98
+
  99
+    # versionfile_source is the relative path from the top of the source tree
  100
+    # (where the .git directory might live) to this file. Invert this to find
  101
+    # the root from __file__.
  102
+    root = here
  103
+    for i in range(len(versionfile_source.split("/"))):
  104
+        root = os.path.dirname(root)
  105
+    if not os.path.exists(os.path.join(root, ".git")):
  106
+        return {}
  107
+
99 108
     GIT = "git"
100 109
     if sys.platform == "win32":
101 110
         GIT = "git.cmd"
102 111
     stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
103  
-                         cwd=source_dir)
  112
+                         cwd=root)
104 113
     if stdout is None:
105 114
         return {}
106 115
     if not stdout.startswith(tag_prefix):
@@ -108,7 +117,7 @@ def versions_from_vcs(tag_prefix, verbose=False):
108 117
             print "tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix)
109 118
         return {}
110 119
     tag = stdout[len(tag_prefix):]
111  
-    stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=source_dir)
  120
+    stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
112 121
     if stdout is None:
113 122
         return {}
114 123
     full = stdout.strip()
@@ -117,12 +126,45 @@ def versions_from_vcs(tag_prefix, verbose=False):
117 126
     return {"version": tag, "full": full}
118 127
 
119 128
 
  129
+def versions_from_parentdir(parentdir_prefix, versionfile_source, verbose=False):
  130
+    try:
  131
+        here = os.path.abspath(__file__)
  132
+        # versionfile_source is the relative path from the top of the source
  133
+        # tree (where the .git directory might live) to _version.py, when
  134
+        # this is used by the runtime. Invert this to find the root from
  135
+        # __file__.
  136
+        root = here
  137
+        for i in range(len(versionfile_source.split("/"))):
  138
+            root = os.path.dirname(root)
  139
+    except NameError:
  140
+        # try a couple different things to handle py2exe, bbfreeze, and
  141
+        # non-CPython implementations which don't do __file__. This code
  142
+        # either lives in versioneer.py (used by setup.py) or _version.py
  143
+        # (used by the runtime). In the versioneer.py case, sys.argv[0] will
  144
+        # be setup.py, in the root of the source tree. In the _version.py
  145
+        # case, we have no idea what sys.argv[0] is (some
  146
+        # application-specific runner).
  147
+        root = os.path.dirname(os.path.abspath(sys.argv[0]))
  148
+    # Source tarballs conventionally unpack into a directory that includes
  149
+    # both the project name and a version string.
  150
+    dirname = os.path.basename(root)
  151
+    if not dirname.startswith(parentdir_prefix):
  152
+        if verbose:
  153
+            print "dirname '%s' doesn't start with prefix '%s'" %                   (dirname, parentdir_prefix)
  154
+        return None
  155
+    return {"version": dirname[len(parentdir_prefix):], "full": ""}
  156
+
120 157
 tag_prefix = ""
  158
+parentdir_prefix = "addon-sdk-"
  159
+versionfile_source = "python-lib/cuddlefish/_version.py"
  160
+
121 161
 def get_versions():
122 162
     variables = { "refnames": git_refnames, "full": git_full }
123 163
     ver = versions_from_expanded_variables(variables, tag_prefix)
124 164
     if not ver:
125  
-        ver = versions_from_vcs(tag_prefix)
  165
+        ver = versions_from_vcs(tag_prefix, versionfile_source)
  166
+    if not ver:
  167
+        ver = versions_from_parentdir(parentdir_prefix, versionfile_source)
126 168
     if not ver:
127 169
         ver = {"version": "unknown", "full": ""}
128 170
     return ver

0 notes on commit ded70e0

Please sign in to comment.
Something went wrong with that request. Please try again.