-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
executable file
·74 lines (56 loc) · 2.47 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
import subprocess
import setuptools
from setuptools.command.develop import develop
from setuptools.command.install import install
class PostDevelopCommand(develop):
"""Post-installation for development mode."""
def run(self):
develop.run(self)
with open('ait/frontend/config.py', 'r') as config_file:
config = config_file.read()
config_commit = config.replace("VERSION_COMMIT = '{}'".format(version_commit), "VERSION_COMMIT = ''")
with open('ait/frontend/config.py', 'w') as config_file:
config_file.write(config_commit)
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
install.run(self)
with open('ait/frontend/config.py', 'r') as config_file:
config = config_file.read()
config_commit = config.replace("VERSION_COMMIT = '{}'".format(version_commit), "VERSION_COMMIT = ''")
with open('ait/frontend/config.py', 'w') as config_file:
config_file.write(config_commit)
tag = subprocess.run('git describe --tags --exact-match HEAD', shell=True, capture_output=True, encoding='utf-8').stdout.strip()
dirty = subprocess.run('git diff', shell=True, capture_output=True)
commit_hash = subprocess.run('git show -s --format=%h', shell=True, capture_output=True, encoding='utf-8').stdout.strip()
commit_file = subprocess.run('cat COMMIT', shell=True, capture_output=True, encoding='utf-8').stdout.strip()
version_commit = ''
if dirty.stdout and not dirty.returncode:
if commit_hash:
version_commit = 'commit: ' + commit_hash + '-dirty'
elif commit_file:
version_commit = 'commit: ' + commit_file + '-dirty'
else:
if tag:
version_commit = tag
elif commit_hash:
version_commit = 'commit: ' + commit_hash
elif commit_file:
version_commit = 'commit: ' + commit_file
if version_commit:
with open('ait/frontend/config.py', 'r') as config_file:
config = config_file.read()
config_commit = config.replace("VERSION_COMMIT = ''", "VERSION_COMMIT = '{}'".format(version_commit))
with open('ait/frontend/config.py', 'w') as config_file:
config_file.write(config_commit)
with open('README.md', 'r') as fh:
long_description = fh.read()
setuptools.setup(
cmdclass={
'develop': PostDevelopCommand,
'install': PostInstallCommand,
}
)
if version_commit:
with open("ait/frontend/config.py", "w") as config_file:
config_file.write(config)