-
Notifications
You must be signed in to change notification settings - Fork 22
/
setup.py
137 lines (114 loc) · 3.93 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
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
import io
import os
import re
import sys
from setuptools import setup, find_packages
PACKAGE = 'trader'
if sys.argv[-1] == 'publish':
os.system('python setup.py sdist bdist_wheel upload')
sys.exit()
class Setup(object):
@staticmethod
def read(fname, fail_silently=False):
"""
Read the content of the given file. The path is evaluated from the
directory containing this file.
"""
try:
filepath = os.path.join(os.path.dirname(__file__), fname)
with io.open(filepath, 'rt', encoding='utf8') as f:
return f.read()
except:
if not fail_silently:
raise
return ''
@staticmethod
def requirements(fname):
"""
Create a list of requirements from the output of the pip freeze command
saved in a text file.
"""
packages = Setup.read(fname, fail_silently=True).split('\n')
packages = (p.strip() for p in packages)
packages = (p for p in packages if p and not p.startswith('#'))
packages = (p for p in packages if p and not p.startswith('https://'))
return list(packages)
@staticmethod
def get_files(*bases):
"""
List all files in a data directory.
"""
for base in bases:
basedir, _ = base.split('.', 1)
base = os.path.join(os.path.dirname(__file__), *base.split('.'))
rem = len(os.path.dirname(base)) + len(basedir) + 2
for root, dirs, files in os.walk(base):
for name in files:
yield os.path.join(basedir, root, name)[rem:]
@staticmethod
def parse_key(key):
data = Setup.read(os.path.join(PACKAGE, '__init__.py'))
value = (re.search(ur"{}\s*=\s*u?'([^']+)'".format(key), data)
.group(1).strip())
return value
@classmethod
def version(cls):
return cls.parse_key('__version__')
@classmethod
def url(cls):
return cls.parse_key('__url__')
@classmethod
def author(cls):
return cls.parse_key('__author__')
@classmethod
def email(cls):
return cls.parse_key('__email__')
@classmethod
def license(cls):
return cls.parse_key('__license__')
@staticmethod
def longdesc():
return Setup.read('README.rst') + '\n\n' + Setup.read('HISTORY.rst')
@staticmethod
def test_links():
# Test if hardlinks work. This is a workaround until
# http://bugs.python.org/issue8876 is solved
if hasattr(os, 'link'):
tempfile = __file__ + '.tmp'
try:
os.link(__file__, tempfile)
except OSError as e:
if e.errno == 1: # Operation not permitted
del os.link
else:
raise
finally:
if os.path.exists(tempfile):
os.remove(tempfile)
Setup.test_links()
setup(name=PACKAGE,
version=Setup.version(),
author=Setup.author(),
author_email=Setup.email(),
include_package_data=True,
zip_safe=False,
url=Setup.url(),
license=Setup.license(),
packages=find_packages(),
package_dir={PACKAGE: PACKAGE},
description='Algortihmic trading tool',
install_requires=Setup.requirements('requirements.txt'),
long_description=Setup.longdesc(),
entry_points=Setup.read('entry-points.ini', True),
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: {} License'.format(Setup.license()),
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
])