forked from openhive-network/hivemind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
172 lines (159 loc) · 6.45 KB
/
setup.py
File metadata and controls
172 lines (159 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# coding=utf-8
from subprocess import check_output
import sys
import os
import logging
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"
VERSION = 'notag'
GIT_REVISION = 'nogitrev'
GIT_DATE = 'nogitdate'
class GitRevisionProvider(object):
""" Static class to provide version and git revision information"""
logger = logging.getLogger('GitRevisionProvider')
@classmethod
def is_git_sha(cls, s):
from re import fullmatch
return fullmatch('^g[0-9a-f]{8}$', s) is not None
@classmethod
def get_git_revision(cls, s):
git_revision = str(GIT_REVISION)
if cls.is_git_sha(s):
git_revision = s.lstrip('g')
return git_revision
@classmethod
def get_commits_count(cls, s):
commits = None
try:
commits = int(s)
except:
pass
return commits
@classmethod
def get_git_date(cls, commit):
if commit == GIT_REVISION:
return GIT_DATE
command = "git show -s --format=%ci {}".format(commit)
hivemind_git_date_string = check_output(command.split()).decode('utf-8').strip()
return hivemind_git_date_string
@classmethod
def provide_git_revision(cls):
""" Evaluate version and git revision and save it to a version file
Evaluation is based on VERSION variable and git describe if
.git directory is present in tree.
In case when .git is not available version and git_revision is taken
from get_distribution call
"""
version = str(VERSION)
git_revision = str(GIT_REVISION)
git_date = str(GIT_DATE)
if os.path.exists(".git"):
from subprocess import check_output
command = 'git describe --tags --long --dirty'
version_string = check_output(command.split()).decode('utf-8').strip()
if version_string != 'fatal: No names found, cannot describe anything.':
# git describe -> tag-commits-sha-dirty
version_string = version_string.replace('-dirty', '')
version_string = version_string.lstrip('v')
parts = version_string.split('-')
parts_len = len(parts)
# only tag or git sha
if parts_len == 1:
if cls.is_git_sha(parts[0]):
git_revision = parts[0]
git_revision = git_revision.lstrip('g')
else:
version = parts[0]
if parts_len == 2:
version = parts[0]
git_revision = cls.get_git_revision(parts[1])
if parts_len > 2:
# git sha
git_revision = cls.get_git_revision(parts[-1])
# commits after given tag
commits = cls.get_commits_count(parts[-2])
# version based on tag
version = ''.join(parts[:-1])
if commits is not None:
version = ''.join(parts[:-2])
# normalize rc to rcN for PEP 440 compatibility
version = version.lower()
if version.endswith('rc'):
version += '0'
else:
cls.logger.warning("Git describe command failed for current git repository")
git_date = cls.get_git_date(git_revision)
else:
from pkg_resources import get_distribution
try:
version, git_revision = get_distribution("hivemind").version.split("+")
except:
cls.logger.warning("Unable to get version and git revision from package data")
cls._save_version_file(version, git_revision, git_date)
return version, git_revision
@classmethod
def _save_version_file(cls, hivemind_version, git_revision, git_date):
""" Helper method to save version.py with current version and git_revision """
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(hivemind_version))
version_file.write("GIT_REVISION = '{}'\n".format(git_revision))
version_file.write("GIT_DATE = '{}'\n".format(git_date))
VERSION, GIT_REVISION = GitRevisionProvider.provide_git_revision()
SQL_SCRIPTS_PATH = 'hive/db/sql_scripts/'
SQL_UPGRADE_PATH = 'hive/db/sql_scripts/upgrade/'
def get_sql_scripts(dir):
from os import listdir
from os.path import isfile, join
return [join(dir, f) for f in listdir(dir) if isfile(join(dir, f))]
if __name__ == "__main__":
setup(
name='hivemind',
version=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']),
data_files=[(SQL_SCRIPTS_PATH, get_sql_scripts(SQL_SCRIPTS_PATH)), (SQL_UPGRADE_PATH, get_sql_scripts(SQL_UPGRADE_PATH))],
setup_requires=[
'pytest-runner'
],
dependency_links=[
'https://github.com/bcb/jsonrpcserver/tarball/8f3437a19b6d1a8f600ee2c9b112116c85f17827#egg=jsonrpcserver-4.1.3+8f3437a'
],
install_requires=[
'aiopg @ https://github.com/aio-libs/aiopg/tarball/862fff97e4ae465333451a4af2a838bfaa3dd0bc',
'jsonrpcserver @ https://github.com/bcb/jsonrpcserver/tarball/8f3437a19b6d1a8f600ee2c9b112116c85f17827#egg=jsonrpcserver',
'simplejson',
'aiohttp',
'certifi',
'sqlalchemy',
'funcy',
'toolz',
'maya',
'ujson',
'urllib3',
'psycopg2-binary',
'aiocache',
'configargparse',
'pdoc==0.3.2',
'diff-match-patch',
'prometheus-client',
'psutil',
'atomic',
'python-dateutil>=2.8.1',
'regex'
],
extras_require={
'dev': [
'pyYAML',
'prettytable'
]
},
entry_points={
'console_scripts': [
'hive=hive.cli:run',
]
}
)