forked from txomon/abot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
128 lines (107 loc) · 4.56 KB
/
setup.py
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
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import subprocess
from setuptools import find_packages, setup
import abot
def git_remote_tags():
tags = subprocess.check_output('git ls-remote git://github.com/txomon/abot --tags v*'.split()).decode()
valid_tags = {}
for tag in tags.splitlines():
# 8626062a1526fdf239fd52d35d91cf7896729e8f refs/tags/test^{}
if tag.endswith('^{}'):
splits = [p for p in tag.split() if p]
commit, tagname = splits
tagname = tagname[len('refs/tags/'):-len('^{}')]
valid_tags[commit] = tagname
return valid_tags
def git_remote_commits():
subprocess.check_output('git fetch git://github.com/txomon/abot master:refs/reference'.split()).decode()
git_log = subprocess.check_output('git log --format=%H refs/reference'.split()).decode()
return git_log.splitlines()
def git_get_closest_commit(valid_tags, remote_commits):
git_log = subprocess.check_output('git log --format=%H'.split()).decode()
common_commit = None
common_to_current = None
current_commit = None
for number, commit in enumerate(git_log.splitlines()):
if not current_commit:
current_commit = commit
if not common_commit and commit in remote_commits:
common_commit = commit
common_to_current = number
if commit in valid_tags:
return {
'tag': valid_tags[commit],
'tag_to_current': number,
'commit': current_commit,
'common_commit': common_commit,
'common_to_current': common_to_current,
}
def get_version():
# Badass revision v1.2.9a1.post0.dev40+20.ab31d12b-dirty
# ********############@@@@@@@@@@@@++++++
# ----------/ ----/ -----/ /
# / / / /
# {version_string}{dev_string}{local_string}{status_string}
try:
dev_string = local_string = status_string = ''
# Get dirtiness
valid_tags = git_remote_tags()
remote_commits = git_remote_commits()
info = git_get_closest_commit(valid_tags, remote_commits)
if not info: # If there is no match, just go to offline mode
raise Exception()
# First, public release string (v1.2.12a3) AKA version_string
version_string = info["tag"]
code_version = f'v{abot.__version__}'
if version_string != code_version:
raise TypeError(f'ABot version in abot/__init__.py needs to be updated to {version_string}')
common_to_current = info['common_to_current']
if common_to_current is None:
raise TypeError(f'This repo and upstream are messy, no common commits. Report this situation!')
tag_to_current = info['tag_to_current']
if common_to_current > tag_to_current:
raise TypeError(f'This is an impossible situation, no tag can exist in uncommon path')
tag_to_common = tag_to_current - common_to_current
# Second, official non-public dev release string (.dev30) AKA dev_string
if tag_to_common != 0:
dev_string = f'.post0.dev{tag_to_common}'
# Third, non-official non-public user release number (+29-ab38ecd99)
if common_to_current:
local_string = f'+{common_to_current}.{info["commit"][:8]}'
# Fourth, dirtiness flag
is_dirty = bool(subprocess.check_output('git status -s'.split()).decode())
if is_dirty:
status_string = '.dirty'
return f'{version_string}{dev_string}{local_string}{status_string}'
except TypeError:
raise
except Exception:
version = abot.__version__
return f'v{version}+unknown'
setup(
name='abot',
version=get_version(),
description='Bot creation library',
long_description=open('README.rst').read(),
url='https://github.com/txomon/abot',
author='Javier Domingo Cansino',
author_email='[email protected]',
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
],
packages=find_packages(exclude=['tests']),
license='MIT',
python_requires='>=3.7',
include_package_data=True,
zip_safe=False,
keywords=['slack', 'dubtrack', 'bot', 'async', 'asyncio'],
install_requires=[
'aiohttp',
'click',
],
)