From 4b27a65a2ddab302d97253b677df55739696c6d7 Mon Sep 17 00:00:00 2001 From: Max Rydahl Andersen Date: Sun, 10 Feb 2019 11:46:47 +0100 Subject: [PATCH] enable deploy of git timestamped build --- .travis.yml | 1 - setup.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 20cd2b4..acc7fa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,6 @@ cache: install: pip install -U tox coveralls language: python script: travis_wait 30 tox --develop -before_deploy: script/check_release deploy: provider: pypi user: maxandersen diff --git a/setup.py b/setup.py index 8a869ad..7f25275 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 """Setup script for Home Assistant CLI.""" import codecs +import datetime from datetime import datetime as dt import os import re +import subprocess from setuptools import find_packages, setup @@ -29,7 +31,42 @@ def find_version(*file_paths): raise RuntimeError("Unable to find version string.") +def get_git_commit_datetime() -> str: + """Return timestamp from last commit""" + try: + commit_hash = ( + subprocess.check_output( + "git rev-parse HEAD", shell=True, stderr=subprocess.STDOUT + ) + .decode("utf-8") + .strip() + ) + commit_datetime = ( + subprocess.check_output( + "git show -s --format=%ci " + commit_hash, + shell=True, + stderr=subprocess.STDOUT, + ) + .decode("utf-8") + .strip() + ) + print(commit_datetime) + datetime_object = datetime.datetime.strptime( + commit_datetime, '%Y-%m-%d %H:%M:%S +%f' + ) + print("{:%Y%m%d%H%M%S}".format(datetime_object)) + return "{:%Y%m%d%H%M%S}".format(datetime_object) + except subprocess.CalledProcessError as cpe: + print(cpe.output) + return "00000000000000" + + __VERSION__ = find_version("homeassistant_cli", "const.py") # type: ignore +# Append a suffix to the version for dev builds +# Append a suffix to the version for dev builds +if 'dev' in __VERSION__: + __VERSION__ = '{v}-{s}'.format(v=__VERSION__, s=get_git_commit_datetime()) + REQUIRED_PYTHON_VER = (3, 5, 3)