Merge pull request #1344 from xonsh/dirty_sha

Dirty version numbers
This commit is contained in:
Anthony Scopatz 2016-06-26 12:01:25 -04:00 committed by GitHub
commit e16d0ada81
5 changed files with 95 additions and 2 deletions

1
.gitignore vendored
View file

@ -19,6 +19,7 @@ xonsh.egg-info/
docs/_build/
docs/envvarsbody
docs/xontribsbody
xonsh/dev.githash
# temporary files from vim and emacs
*~

14
news/dirtyversion.rst Normal file
View file

@ -0,0 +1,14 @@
**Added:**
* dev versions now display a ``devN`` counter at the end and ``xonfig info``
also displays the git sha of the current build
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -7,6 +7,7 @@ from __future__ import print_function, unicode_literals
import os
import sys
import json
import subprocess
try:
from tempfile import TemporaryDirectory
@ -101,11 +102,61 @@ def install_jupyter_hook(prefix=None, root=None):
d, 'xonsh', user=user, replace=True, prefix=prefix)
def dirty_version():
"""
If install/sdist is run from a git directory (not a conda install), add
a devN suffix to reported version number and write a gitignored file
that holds the git hash of the current state of the repo to be queried
by ``xonfig``
"""
try:
_version = subprocess.check_output(['git', 'describe', '--tags'])
_version = _version.decode('ascii')
except subprocess.CalledProcessError:
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
def replace_version(base, N):
"""Replace version in `__init__.py` with devN suffix"""
with open('xonsh/__init__.py', 'r') as f:
raw = f.read()
lines = raw.splitlines()
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
class xinstall(install):
"""Xonsh specialization of setuptools install class."""
def run(self):
clean_tables()
build_tables()
# add dirty version number
dirty = dirty_version()
# install Jupyter hook
root = self.root if self.root else None
prefix = self.prefix if self.prefix else None
@ -116,6 +167,9 @@ class xinstall(install):
traceback.print_exc()
print('Installing Jupyter hook failed.')
install.run(self)
if dirty:
discard_changes()
class xsdist(sdist):
@ -123,7 +177,10 @@ class xsdist(sdist):
def make_release_tree(self, basedir, files):
clean_tables()
build_tables()
dirty = dirty_version()
sdist.make_release_tree(self, basedir, files)
if dirty:
discard_changes()
#-----------------------------------------------------------------------------
@ -155,7 +212,10 @@ if HAVE_SETUPTOOLS:
def run(self):
clean_tables()
build_tables()
dirty = dirty_version()
develop.run(self)
if dirty:
discard_changes()
def main():
@ -192,7 +252,7 @@ def main():
packages=['xonsh', 'xonsh.ply', 'xonsh.ptk', 'xonsh.parsers',
'xonsh.xoreutils', 'xontrib', 'xonsh.completers'],
package_dir={'xonsh': 'xonsh', 'xontrib': 'xontrib'},
package_data={'xonsh': ['*.json'], 'xontrib': ['*.xsh']},
package_data={'xonsh': ['*.json', '*.githash'], 'xontrib': ['*.xsh']},
cmdclass=cmdclass,
scripts=scripts,
)

View file

@ -125,6 +125,23 @@ def is_readline_available():
return (spec is not None)
#
# Dev release info
#
@functools.lru_cache(1)
def githash():
install_base = os.path.dirname(__file__)
try:
with open('{}/dev.githash'.format(install_base), 'r') as f:
sha = f.read().strip()
if not sha:
sha = None
except FileNotFoundError:
sha = None
return sha
#
# Encoding
#

View file

@ -20,7 +20,7 @@ from xonsh import __version__ as XONSH_VERSION
from xonsh.environ import is_template_string
from xonsh.platform import (is_readline_available, ptk_version,
PYTHON_VERSION_INFO, pygments_version, ON_POSIX, ON_LINUX, linux_distro,
ON_DARWIN, ON_WINDOWS, ON_CYGWIN, DEFAULT_ENCODING)
ON_DARWIN, ON_WINDOWS, ON_CYGWIN, DEFAULT_ENCODING, githash)
from xonsh.tools import (to_bool, is_string, print_exception, is_superuser,
color_style_names, print_color, color_style)
from xonsh.xontribs import xontrib_metadata, find_xontrib
@ -352,6 +352,7 @@ def _info(ns):
('on cygwin', ON_CYGWIN),
('is superuser', is_superuser()),
('default encoding', DEFAULT_ENCODING),
('git SHA', githash())
])
formatter = _xonfig_format_json if ns.json else _xonfig_format_human
s = formatter(data)