forked from mailpile/Mailpile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·101 lines (83 loc) · 3.01 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
#!/usr/bin/env python2
from datetime import date
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
import datetime
import os
import re
import subprocess
from glob import glob
here = os.path.abspath(os.path.dirname(__file__))
########################################################
##################### PBR Fix ##########################
## Issue: https://bugs.launchpad.net/pbr/+bug/1530867 ##
## PR: https://review.openstack.org/#/c/263297/ ########
########################################################
import pbr.git
def _get_submodules(git_dir):
submodules = pbr.git._run_git_command(['submodule', 'status'], git_dir)
submodules = [s.strip().split(' ')[1]
for s in submodules.split('\n')
if s != '']
return submodules
def _find_git_files(dirname='', git_dir=None):
"""Behave like a file finder entrypoint plugin.
We don't actually use the entrypoints system for this because it runs
at absurd times. We only want to do this when we are building an sdist.
"""
file_list = []
if git_dir is None:
git_dir = pbr.git._run_git_functions()
if git_dir:
file_list = pbr.git._run_git_command(['ls-files', '-z'], git_dir)
file_list += pbr.git._run_git_command(
['submodule', 'foreach', '--quiet', 'ls-files', '-z'],
git_dir
)
# Users can fix utf8 issues locally with a single commit, so we are
# strict here.
file_list = file_list.split(b'\x00'.decode('utf-8'))
submodules = _get_submodules(git_dir)
return [f for f in file_list if f and f not in submodules]
pbr.git._find_git_files = _find_git_files
########## end of pbr fix ######
## This figures out what version we want to call ourselves ###################
try:
GIT_HEAD = open('.git/HEAD').read().strip().split('/')[-1]
BRANCH = {
'master': 'dev',
'release': ''
}.get(GIT_HEAD, GIT_HEAD)
except (OSError, IOError):
BRANCH = None
if BRANCH:
BRANCHVER = '.%s%s' % (BRANCH, str(datetime.date.today()).replace('-', ''))
else:
BRANCHVER = ''
APPVER = '%s%s' % (next(
line.strip() for line in open('mailpile/config/defaults.py', 'r')
if re.match(r'^APPVER\s*=', line)
).split('"')[1], BRANCHVER)
## Cleanup ###################################################################
try:
assert(0 == subprocess.call(['make', 'clean'], cwd=here))
except:
print "Faild to run 'make clean'. Bailing out."
exit(1)
## Install ###################################################################
class Builder(build_py):
def run(self):
try:
assert(0 == subprocess.call(['make', 'bdist-prep'], cwd=here))
except:
print "Error building package. Try running 'make'."
exit(1)
else:
build_py.run(self)
## "Main" ####################################################################
setup(
setup_requires=['pbr'],
version=APPVER,
pbr=True,
cmdclass={'build_py': Builder},
)