diff --git a/kwant/_common.py b/kwant/_common.py index 0015050b4a73b6afb07acb77cbc545a95d8b488f..b67d1326a53d3af9758fb752e27a12924661c9b0 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 ddd1a398a5327318bd7193a6d9133aef3791e7c3..9530ac998c43053c49ccbf5ede5955b72deba379 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 27c28b34edb3a4bba2b4b4c7a5b1ffd9016abd8c..3f5efb8d9affc92c56e426febe6ba1e816ce3444 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():