From d002a2de2a02457402a65fde8aedefe94d966b25 Mon Sep 17 00:00:00 2001 From: Dariusz Kedzierski <dkedzierski@syncad.com> Date: Thu, 6 Aug 2020 17:37:08 +0200 Subject: [PATCH] Added version file - Setup will create version file with current version info --- hive/server/hive_api/public.py | 7 +++---- hive/server/serve.py | 5 +++-- hive/version.py | 4 ++++ setup.py | 17 ++++++++++++++++- 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 hive/version.py diff --git a/hive/server/hive_api/public.py b/hive/server/hive_api/public.py index 37d336268..b68ec808f 100644 --- a/hive/server/hive_api/public.py +++ b/hive/server/hive_api/public.py @@ -116,12 +116,11 @@ async def get_info(context): sql = "SELECT num FROM hive_blocks ORDER BY num DESC LIMIT 1" database_head_block = await db.query_one(sql) - import pkg_resources - hivemind_version, hivemind_git_rev = pkg_resources.get_distribution("hivemind").version.split("+") + from hive.version import VERSION, GIT_REVISION ret = { - "hivemind_version" : hivemind_version, - "hivemind_git_rev" : hivemind_git_rev, + "hivemind_version" : VERSION, + "hivemind_git_rev" : GIT_REVISION, "database_schema_version" : SCHEMA_DB_VERSION, "database_head_block" : database_head_block } diff --git a/hive/server/serve.py b/hive/server/serve.py index 2d62d620c..23770fb7f 100644 --- a/hive/server/serve.py +++ b/hive/server/serve.py @@ -230,8 +230,9 @@ def run_server(conf): import pkg_resources hivemind_version, hivemind_git_rev = pkg_resources.get_distribution("hivemind").version.split("+") - log.info("hivemind_version : %s", hivemind_version) - log.info("hivemind_git_rev : %s", hivemind_git_rev) + from hive.version import VERSION, GIT_REVISION + log.info("hivemind_version : %s", VERSION) + log.info("hivemind_git_rev : %s", GIT_REVISION) from hive.db.schema import DB_VERSION as SCHEMA_DB_VERSION log.info("database_schema_version : %s", SCHEMA_DB_VERSION) diff --git a/hive/version.py b/hive/version.py new file mode 100644 index 000000000..d0ae1a49a --- /dev/null +++ b/hive/version.py @@ -0,0 +1,4 @@ +# generated by setup.py +# contents will be overwritten +VERSION = '0.0.1' +GIT_REVISION = '5c0b832' diff --git a/setup.py b/setup.py index 7ade2c647..ee620402e 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,20 @@ # coding=utf-8 import sys +import os from setuptools import find_packages from setuptools import setup assert sys.version_info[0] == 3 and sys.version_info[1] >= 6, "hive requires Python 3.6 or newer" +def get_git_version(): + from git import Repo + repo = Repo(os.path.abspath(".")) + return repo.git.rev_parse('--short', 'HEAD') + +VERSION = '0.0.1' +GIT_REVISION = get_git_version() + tests_require = [ 'pytest', 'pytest-cov', @@ -17,10 +26,16 @@ tests_require = [ 'yapf', ] +with open("hive/version.py", 'w') as version_file: + version_file.write("# generated by setup.py\n") + version_file.write("# contents will be overwritten\n") + version_file.write("VERSION = '{}'\n".format(VERSION)) + version_file.write("GIT_REVISION = '{}'\n".format(GIT_REVISION)) + # yapf: disable setup( name='hivemind', - version_format='0.0.1+{gitsha}', + version_format=VERSION + "+" + GIT_REVISION, description='Developer-friendly microservice powering social networks on the Steem blockchain.', long_description=open('README.md').read(), packages=find_packages(exclude=['scripts']), -- GitLab