From a215c8cfea960b8f3746bd9f3f39feaee7aea24b Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph.weston08@gmail.com>
Date: Sat, 7 Nov 2015 19:00:09 +0100
Subject: [PATCH] simplified version file format

Now we exec _kwant_version.py into a namespace and get
the version from that.
---
 kwant/_common.py        | 11 ++++-------
 kwant/_kwant_version.py |  2 +-
 setup.py                |  4 ++--
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/kwant/_common.py b/kwant/_common.py
index 0015050b..b67d1326 100644
--- a/kwant/_common.py
+++ b/kwant/_common.py
@@ -68,14 +68,11 @@ def get_version_from_git():
 
 
 
-# version file contains comments (lines starting with '#')
-# followed by the version string on its own on a single line
+# populate the version_info dictionary with values stored in the version file
+version_info = {}
 with open(os.path.join(package_root, version_file), 'r') as f:
-    cruft="\"'\n\t\r "  # strip whitespace and quotes
-    line = next(f).strip(cruft)
-    while line.startswith('#'):
-        line = next(f).strip(cruft)
-    version = line
+    exec(f.read(), {}, version_info)
+version = version_info['version']
 version_is_from_git = (version == "__use_git__")
 if version_is_from_git:
     version = get_version_from_git()
diff --git a/kwant/_kwant_version.py b/kwant/_kwant_version.py
index ddd1a398..9530ac99 100644
--- a/kwant/_kwant_version.py
+++ b/kwant/_kwant_version.py
@@ -1,4 +1,4 @@
 # This file will be overwritten by setup.py when a source or binary
 # distribution is made.  The magic value "__use_git__" is interpreted by
 # _common.py in this directory.
-"__use_git__"
+version = "__use_git__"
diff --git a/setup.py b/setup.py
index 27c28b34..3f5efb8d 100755
--- a/setup.py
+++ b/setup.py
@@ -173,7 +173,7 @@ def git_lsfiles():
 
     if p.wait() != 0:
         return
-    return p.communicate()[0].split('\n')[:-1]
+    return p.communicate()[0].decode().split('\n')[:-1]
 
 
 # Make the command "sdist" depend on "build".  This verifies that the
@@ -235,7 +235,7 @@ def write_version(fname):
         pass
     with open(fname, 'w') as f:
         f.write("# This file has been created by setup.py.\n")
-        f.write(version)
+        f.write("version = '{}'".format(version))
 
 
 def long_description():
-- 
GitLab