Skip to content

Commit

Permalink
Merge branch 'master' into release/4.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Dec 22, 2016
2 parents 7e4a18a + 61a3fa2 commit 66854ea
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
_VERSION_FILENAME = os.path.join(PKG_PATHNAME, '_version.py')


def read_version_py(path):
""" Read a _version.py file in a safe way. """
with open(path, 'r') as fp:
code = compile(fp.read(), 'chaco._version', 'exec')
context = {}
exec(code, context)
return context['git_revision'], context['full_version']


def git_version():
""" Parse version information from the current git commit.
Expand Down Expand Up @@ -85,17 +94,19 @@ def write_version_py(filename=_VERSION_FILENAME):
# write_version_py(), otherwise the import of _version messes
# up the build under Python 3.
fullversion = VERSION
chaco_version_path = os.path.join(
os.path.dirname(__file__), 'chaco', '_version.py')
if os.path.exists('.git'):
git_rev, dev_num = git_version()
elif os.path.exists(filename):
# must be a source distribution, use existing version file
try:
from chaco._version import git_revision as git_rev
from chaco._version import full_version as full_v
except ImportError:
msg = ("Unable to import 'git_revision' or 'full_revision'. "
"Try removing {} and the build directory before building.")
raise ImportError(msg.format(_VERSION_FILENAME))
git_revision, full_version = read_version_py(chaco_version_path)
except (SyntaxError, KeyError):
raise RuntimeError("Unable to read git_revision. Try removing "
"chaco/_version.py and the build directory "
"before building.")


match = re.match(r'.*?\.dev(?P<dev_num>\d+)', full_v)
if match is None:
Expand Down

0 comments on commit 66854ea

Please sign in to comment.