add githash file to setup, manifest and gitignore

This commit is contained in:
Gil Forsyth 2016-06-26 09:46:43 -04:00
parent ce3d21e21d
commit 08d6112a46
3 changed files with 43 additions and 1 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
*~

View file

@ -1 +1,2 @@
include logo.txt
include githash

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,47 @@ 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')
try:
base, N, sha = _version.strip().split('-')
except ValueError: #on base release
open('xonsh/dev.githash', 'w').close()
return
except subprocess.CalledProcessError:
return
replace_version(base, N)
with open('xonsh/dev.githash', 'w') as f:
f.write(sha)
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)
class xinstall(install):
"""Xonsh specialization of setuptools install class."""
def run(self):
clean_tables()
build_tables()
# add dirty version number
dirty_version()
# install Jupyter hook
root = self.root if self.root else None
prefix = self.prefix if self.prefix else None
@ -123,9 +160,11 @@ class xsdist(sdist):
def make_release_tree(self, basedir, files):
clean_tables()
build_tables()
dirty_version()
sdist.make_release_tree(self, basedir, files)
#-----------------------------------------------------------------------------
# Hack to overcome pip/setuptools problem on Win 10. See:
# https://github.com/tomduck/pandoc-eqnos/issues/6
@ -155,6 +194,7 @@ if HAVE_SETUPTOOLS:
def run(self):
clean_tables()
build_tables()
dirty_version()
develop.run(self)
@ -192,7 +232,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,
)