-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathsetup.py
185 lines (152 loc) · 5.38 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# -*- coding: utf-8 -*-
from setuptools import setup
from setuptools import find_packages
from distutils.cmd import Command
from distutils.extension import Extension
import os
import sys
import io
import subprocess
import platform
import numpy as np
from Cython.Build import cythonize
import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True
if "--line_trace" in sys.argv:
line_trace = True
profile = True
print("Build with line trace enabled ...")
sys.argv.remove("--line_trace")
else:
line_trace = False
profile = False
PACKAGE = "PyFin"
NAME = "Finance-Python"
__version__ = "0.9.10"
DESCRIPTION = "PyFin " + __version__
AUTHOR = "cheng li"
AUTHOR_EMAIL = "[email protected]"
URL = 'https://github.com/ChinaQuants/Finance-Python'
def git_version():
from subprocess import Popen, PIPE
gitproc = Popen(['git', 'rev-parse', 'HEAD'], stdout=PIPE)
(stdout, _) = gitproc.communicate()
return stdout.strip().decode("utf8")
class test(Command):
description = "test the distribution prior to install"
user_options = [
('test-dir=', None,
"directory that contains the test definitions"),
]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if sys.platform == 'win32':
command = "coverage run PyFin/tests/testSuite.py& coverage report& coverage html"
else:
command = "coverage run PyFin/tests/testSuite.py; coverage report; coverage html"
process = subprocess.Popen(command, shell=True)
process.wait()
class version_build(Command):
description = "test the distribution prior to install"
user_options = [
('test-dir=', None,
"directory that contains the test definitions"),
]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
git_ver = git_version()[:10]
configFiles = ['PyFin/__init__.py', 'setup.py']
for configFile in configFiles:
file_handle = open(configFile, 'r')
lines = file_handle.readlines()
newFiles = []
for line in lines:
if line.startswith('__version__'):
line = line.split('+')[0].rstrip()
line = line + " + \"-" + git_ver + "\"\n"
newFiles.append(line)
file_handle.close()
os.remove(configFile)
file_handle = open(configFile, 'w')
file_handle.writelines(newFiles)
file_handle.close()
requirements = "requirements.txt"
ext_modules = [
"PyFin/Analysis/SeriesValues.pyx",
"PyFin/Analysis/transformer.pyx",
"PyFin/Analysis/SecurityValueHolders.pyx",
"PyFin/Analysis/CrossSectionValueHolders.pyx",
"PyFin/Analysis/TechnicalAnalysis/StatefulTechnicalAnalysers.pyx",
"PyFin/Analysis/TechnicalAnalysis/StatelessTechnicalAnalysers.pyx",
"PyFin/Math/Accumulators/impl.pyx",
"PyFin/Math/Accumulators/IAccumulators.pyx",
"PyFin/Math/Accumulators/StatefulAccumulators.pyx",
"PyFin/Math/Accumulators/StatelessAccumulators.pyx",
"PyFin/Math/Distributions/NormalDistribution.pyx",
"PyFin/Math/Distributions/norm.pyx",
"PyFin/Math/ErrorFunction.pyx",
"PyFin/Math/MathConstants.pyx",
"PyFin/Math/udfs.pyx",
"PyFin/DateUtilities/Calendar.pyx",
"PyFin/DateUtilities/Date.pyx",
"PyFin/DateUtilities/Period.pyx",
"PyFin/DateUtilities/Schedule.pyx",
"PyFin/Utilities/Asserts.pyx",
"PyFin/Utilities/Tools.pyx",
"PyFin/PricingEngines/BlackFormula.pyx",
"PyFin/PricingEngines/SabrFormulaImpl.pyx",
"PyFin/PricingEngines/SVIInterpolationImpl.pyx",
"PyFin/Enums/TimeUnits.pyx",
"PyFin/Enums/BizDayConventions.pyx",
"PyFin/Enums/DateGeneration.pyx",
"PyFin/Enums/Months.pyx",
"PyFin/Enums/NormalizingType.pyx",
"PyFin/Enums/OptionType.pyx",
"PyFin/Enums/Weekdays.pyx"
]
def generate_extensions(ext_modules, line_trace=False):
extensions = []
if line_trace:
print("define cython trace to True ...")
define_macros = [('CYTHON_TRACE', 1), ('CYTHON_TRACE_NOGIL', 1)]
else:
define_macros = []
for pyxfile in ext_modules:
ext = Extension(name='.'.join(pyxfile.split('/'))[:-4],
sources=[pyxfile],
define_macros=define_macros)
extensions.append(ext)
return extensions
if platform.system() != "Windows":
import multiprocessing
n_cpu = multiprocessing.cpu_count()
else:
n_cpu = 0
ext_modules_settings = cythonize(generate_extensions(ext_modules, line_trace),
compiler_directives={"embedsignature": True,
"linetrace": line_trace,
"profile": profile,
"language_level": 3},
nthreads=n_cpu)
setup(
name=NAME,
version=__version__,
description=DESCRIPTION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
url=URL,
packages=find_packages(),
include_package_data=False,
install_requires=io.open(requirements, encoding='utf8').read(),
classifiers=[],
cmdclass={"test": test,
"version_build": version_build},
ext_modules=ext_modules_settings,
include_dirs=[np.get_include()],
)