forked from mailgun/talon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
105 lines (81 loc) · 2.33 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
import os
import sys
import contextlib
from distutils.spawn import find_executable
from setuptools import setup, find_packages
setup(name='talon',
version='1.0.2',
description=("Mailgun library "
"to extract message quotations and signatures."),
long_description=open("README.rst").read(),
author='Mailgun Inc.',
author_email='[email protected]',
url='https://github.com/mailgun/talon',
license='APACHE2',
packages=find_packages(exclude=['tests']),
include_package_data=True,
zip_safe=True,
install_requires=[
"lxml==3.3.3",
"regex",
"chardet==2.3.0",
"dnspython==1.11.1",
"html2text",
"nose==1.2.1",
"numpy",
"mock",
"coverage",
]
)
def install_pyml():
'''
Downloads and installs PyML
'''
try:
import PyML
except:
pass
else:
return
# install numpy first
pyml_tarball = (
'https://www.dropbox.com/s/qm8tzovr0y2p4cv/PyML-0.7.9.2.tar.gz?dl=1')
pyml_srcidr = 'PyML-0.7.9'
# see if PyML tarball needs to be fetched:
# if not dir_exists(pyml_srcidr):
run("wget %s" % pyml_tarball)
run("tar -xvf PyML-0.7.9.2.tar.gz?dl=1")
# compile&install:
with cd(pyml_srcidr):
python('setup.py build')
python('setup.py install')
def run(command):
if os.system(command) != 0:
raise Exception("Failed '{}'".format(command))
else:
return 0
def python(command):
command = '{} {}'.format('/usr/bin/python3', command)
run(command)
def enforce_executable(name, install_info):
if os.system("which {}".format(name)) != 0:
raise Exception(
'{} utility is missing.\nTo install, run:\n\n{}\n'.format(
name, install_info))
def pip(command):
command = '{} {}'.format(find_executable('pip3'), command)
run(command)
def dir_exists(path):
return os.path.isdir(path)
@contextlib.contextmanager
def cd(directory):
curdir = os.getcwd()
try:
os.chdir(directory)
yield {}
finally:
os.chdir(curdir)
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] in ['develop', 'install']:
enforce_executable('curl', 'sudo aptitude install curl')
# install_pyml()