-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
executable file
·65 lines (47 loc) · 2.14 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
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()
commit_hash = subprocess.run('git show -s --format=%h', shell=True, capture_output=True, encoding='utf-8').stdout.strip()
version_commit = ''
if tag:
version_commit = tag
elif commit_hash:
commit_hash += subprocess.run("git diff --quiet HEAD || echo '-dirty'", shell=True, capture_output=True, encoding='utf-8').stdout.strip()
version_commit = 'commit: ' + commit_hash
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)