fixed checkout issue

This commit is contained in:
Anthony Scopatz 2016-06-27 23:31:15 -04:00
parent 4dffde658f
commit 3cf47dfa7d
3 changed files with 18 additions and 17 deletions

View file

@ -9,6 +9,8 @@
background.
* Sped up loading of prompt-toolkit by ~2x-3x by loading ``pkg_resources``
in background.
* ``setup.py`` will no longer git checkout to replace the version number.
Now it simply stores and reuses the original version line.
**Deprecated:** None

View file

@ -114,40 +114,41 @@ def dirty_version():
_version = _version.decode('ascii')
except (subprocess.CalledProcessError, FileNotFoundError):
return False
try:
base, N, sha = _version.strip().split('-')
except ValueError: #on base release
open('xonsh/dev.githash', 'w').close()
return False
replace_version(base, N)
with open('xonsh/dev.githash', 'w') as f:
f.write(sha)
return True
ORIGINAL_VERSION_LINE = None
def replace_version(base, N):
"""Replace version in `__init__.py` with devN suffix"""
global ORIGINAL_VERSION_LINE
with open('xonsh/__init__.py', 'r') as f:
raw = f.read()
lines = raw.splitlines()
ORIGINAL_VERSION_LINE = lines[0]
lines[0] = "__version__ = '{}.dev{}'".format(base, N)
upd = '\n'.join(lines) + '\n'
with open('xonsh/__init__.py', 'w') as f:
f.write(upd)
def discard_changes():
"""If we touch ``__init__.py``, discard changes after install"""
try:
_ = subprocess.check_output(['git',
'checkout',
'--',
'xonsh/__init__.py'])
except subprocess.CalledProcessError:
pass
def restore_version():
"""If we touch the version in __init__.py discard changes after install."""
with open('xonsh/__init__.py', 'r') as f:
raw = f.read()
lines = raw.splitlines()
lines[0] = ORIGINAL_VERSION_LINE
upd = '\n'.join(lines) + '\n'
with open('xonsh/__init__.py', 'w') as f:
f.write(upd)
class xinstall(install):
@ -168,7 +169,7 @@ class xinstall(install):
print('Installing Jupyter hook failed.')
install.run(self)
if dirty:
discard_changes()
restore_version()
@ -180,7 +181,7 @@ class xsdist(sdist):
dirty = dirty_version()
sdist.make_release_tree(self, basedir, files)
if dirty:
discard_changes()
restore_version()
#-----------------------------------------------------------------------------
@ -215,7 +216,7 @@ if HAVE_SETUPTOOLS:
dirty = dirty_version()
develop.run(self)
if dirty:
discard_changes()
restore_version()
def main():

View file

@ -9,8 +9,6 @@ else:
import sys as _sys
try:
from xonsh import __amalgam__
bg_pkg_resources = __amalgam__
_sys.modules['xonsh.bg_pkg_resources'] = __amalgam__
completer = __amalgam__
_sys.modules['xonsh.completer'] = __amalgam__
lazyasd = __amalgam__