Skip to content
Snippets Groups Projects
Commit f59714be authored by Dariusz Kędzierski's avatar Dariusz Kędzierski
Browse files

Added GitRevisionProvider class

- added specialized class as git revision provider
- build step will also update version.py
- in absence of .git dir version and git_revision will be taken
  from package distribution
parent d59f7f75
No related branches found
No related tags found
4 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!135Enable postgres monitoring on CI server,!84Upgrade of setup.py
...@@ -5,40 +5,49 @@ import os ...@@ -5,40 +5,49 @@ import os
from setuptools import find_packages from setuptools import find_packages
from setuptools import setup from setuptools import setup
from setuptools.command.install import install from setuptools.command.install import install
from setuptools.command.build_py import build_py as build_py
assert sys.version_info[0] == 3 and sys.version_info[1] >= 6, "hive requires Python 3.6 or newer" assert sys.version_info[0] == 3 and sys.version_info[1] >= 6, "hive requires Python 3.6 or newer"
VERSION = '0.0.1' VERSION = '0.0.1'
class InstallWrapper(install): class GitRevisionProvider(object):
_GIT_REVISION = None _GIT_REVISION = None
def run(self):
self._GIT_REVISION = self._get_git_version()
self._save_version_file()
install.run(self)
def _get_git_version(self): @staticmethod
def provide_git_revision():
if os.path.exists(".git"): if os.path.exists(".git"):
from subprocess import check_output from subprocess import check_output
command = 'git describe --tags --long --dirty' command = 'git describe --tags --long --dirty'
version = check_output(command.split()).decode('utf-8').strip() version = check_output(command.split()).decode('utf-8').strip()
parts = version.split('-') parts = version.split('-')
_, _, sha = parts[:3] _, _, sha = parts[:3]
return sha.lstrip('g') GitRevisionProvider._save_version_file(VERSION, sha.lstrip('g'))
return self._get_git_version_from_file() else:
from pkg_resources import get_distribution
try:
version, git_revision = get_distribution("hivemind").version.split("+")
GitRevisionProvider._save_version_file(version, git_revision)
except:
GitRevisionProvider._save_version_file(VERSION, "")
def _get_git_version_from_file(self): @staticmethod
with open("hive/version.py", 'r') as version_file: def _save_version_file(hivemind_version, git_revision):
lines = version_file.readlines()
_, git_version = lines[-1].split('=')
return git_version.strip()
def _save_version_file(self):
with open("hive/version.py", 'w') as version_file: with open("hive/version.py", 'w') as version_file:
version_file.write("# generated by setup.py\n") version_file.write("# generated by setup.py\n")
version_file.write("# contents will be overwritten\n") version_file.write("# contents will be overwritten\n")
version_file.write("VERSION = '{}'\n".format(VERSION)) version_file.write("VERSION = '{}'\n".format(hivemind_version))
version_file.write("GIT_REVISION = '{}'".format(self._GIT_REVISION)) version_file.write("GIT_REVISION = '{}'".format(git_revision))
class BuildWrapper(build_py):
def run(self):
GitRevisionProvider.provide_git_revision()
build_py.run(self)
class InstallWrapper(install):
def run(self):
GitRevisionProvider.provide_git_revision()
install.run(self)
# yapf: disable # yapf: disable
setup( setup(
...@@ -68,12 +77,14 @@ setup( ...@@ -68,12 +77,14 @@ setup(
'aiocache', 'aiocache',
'configargparse', 'configargparse',
'pdoc', 'pdoc',
'diff-match-patch', 'diff-match-patch'
], ],
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'hive=hive.cli:run', 'hive=hive.cli:run',
] ]
}, },
cmdclass={'install': InstallWrapper} cmdclass={
'install': InstallWrapper,
'build_py':BuildWrapper}
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment