From 26662f7df3c3da2998d7355fe3faa09a27c415da Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Tue, 28 Mar 2017 10:31:43 -0700 Subject: [PATCH] setup: generate current git_hash into autogenerated 'pywb.git_hash' file, add to .gitignore --- .gitignore | 3 +++ setup.py | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e9ba91e2..020f9704 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ nosetests.xml # Node node_modules/ + +# git_hash +git_hash.py diff --git a/setup.py b/setup.py index 0af5f244..3dbf6608 100755 --- a/setup.py +++ b/setup.py @@ -4,6 +4,8 @@ from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand import glob +import os +import sys from pywb import __version__ @@ -21,7 +23,6 @@ class PyTest(TestCommand): from gevent.monkey import patch_all; patch_all() import pytest - import sys import os os.environ.pop('PYWB_CONFIG_FILE', None) cmdline = ' --cov-config .coveragerc --cov pywb' @@ -32,11 +33,36 @@ class PyTest(TestCommand): sys.exit(errcode) + +def get_git_short_hash(): + import subprocess + try: + hash_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).rstrip() + if sys.version_info >= (3, 0): + hash_id = hash_id.decode('utf-8') + + return hash_id + except: + return '' + +def generate_git_hash_py(pkg, filename='git_hash.py'): + try: + git_hash = get_git_short_hash() + with open(os.path.join(pkg, filename), 'wt') as fh: + fh.write('git_hash = "{0}"\n'.format(git_hash)) + except: + pass + + + def load_requirements(filename): with open(filename, 'rt') as fh: return fh.read().rstrip().split('\n') +generate_git_hash_py('pywb') + + setup( name='pywb', version=__version__,