Skip to content

Commit 23b3dfc

Browse files
committed
tools: Update scripts for generating code
1 parent 4bab2a0 commit 23b3dfc

File tree

7 files changed

+34
-42
lines changed

7 files changed

+34
-42
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ docs/html
22
docs/.tadoc.org.html
33

44
*.pyc
5-
build
5+
build/
6+
dist/
67
*.so
78
.*
89
*~
10+
*.egg-info/
911

Diff for: DEVELOPMENT

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@ Here's the full list of make commands (see the Makefile file):
1212
make build # builds and places libs in the project directory; required for testing
1313
make clean # cleans the local build files
1414
make install # installs talib system-wide
15-
make generate: # generates a fresh func.pyx file. Requires talib and TA-Lib to both be installed
15+
make generate: # generates a fresh _func.pxi, _stream.pxi file. Requires talib and TA-Lib to both be installed
1616
make perf # run performance profiling
1717
make test # run tests
1818

1919
The source code is comprised of one python package, located in the talib
20-
directory, which itself has three Cython modules: func, abstract, and
21-
common.
20+
directory, which itself has one Cython module (_ta_lib) which consists of
21+
four parts: _common, _func, _abstract and _stream.
2222

23-
talib/common.pyx
24-
An internal-use module for functionality shared between func and abstract.
23+
talib/_common.pxi
24+
An internal-use file for functionality shared between func and abstract.
2525

26-
talib/func.pyx
27-
This file is generated automatically by tools/generate.py and any changes made
26+
talib/_func.pxi
27+
This file is generated automatically by tools/generate_func.py and any changes made
2828
to it directly will get overwritten!
2929

30-
talib/abstract.pyx
30+
talib/_abstract.pxi
3131
This file contains the code for interfacing with the TA-Lib abstract interface
3232
and wrapping it into a pythonic Function class.
3333

34-
talib/libta_lib.pxd
34+
talib/_ta_lib.pyx
3535
This "Cython header file" defines the C-level functions, variables and types we
3636
need to use in the above pyx files.
3737

38-
talib/stream.pyx
38+
talib/_stream.pxi
3939
This file contains code for interfacing a "streaming" interface to TA-Lib.
4040

41-
tools/generate.py
42-
A script that generates and prints func.pyx to stdout. Gets information
41+
tools/generate_func.py,generate_stream.py
42+
Scripts that generate and print _func.pxi or _stream.pxi to stdout. Gets information
4343
about all functions from the C headers of the installed TA-Lib.
4444

4545
If you are interested in developing new indicator functions or whatnot on

Diff for: Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
.PHONY: build
2+
13
build:
24
python setup.py build_ext --inplace
35

46
install:
57
python setup.py install
68

7-
generate:
8-
python tools/generate_func.py > talib/func.pyx
9+
talib/_func.pxi: tools/generate_func.py
10+
python tools/generate_func.py > talib/_func.pxi
11+
12+
talib/_stream.pxi: tools/generate_stream.py
13+
python tools/generate_stream.py > talib/_stream.pxi
14+
15+
generate: talib/_func.pxi talib/_stream.pxi
916

1017
clean:
1118
rm -rf build talib/func*.so talib/abstract*.so talib/common*.so talib/stream*.so talib/*.pyc

Diff for: talib/_abstract.pxi

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ cimport numpy as np
1414
cimport _ta_lib as lib
1515
# NOTE: _ta_check_success, MA_Type is defined in _common.pxi
1616

17-
lib.TA_Initialize()
18-
1917

2018
__INPUT_ARRAYS_DEFAULTS = {'open': None,
2119
'high': None,

Diff for: talib/abstract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def Function(function_name, *args, **kwargs):
2222
globals()[func_name] = Function(func_name)
2323

2424

25-
__all__ = ["Function"] + __TA_FUNCTION_NAMES__
25+
__all__ = ["Function", "_get_defaults_and_docs"] + __TA_FUNCTION_NAMES__

Diff for: tools/generate_func.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from numpy import nan
5252
from cython import boundscheck, wraparound
5353
54-
from .common cimport _ta_check_success
54+
# _ta_check_success: defined in _common.pxi
5555
5656
cdef double NaN = nan
5757
@@ -63,10 +63,9 @@
6363
6464
np.import_array() # Initialize the NumPy C API
6565
66-
cimport libta_lib as lib
67-
from libta_lib cimport TA_RetCode
66+
cimport _ta_lib as lib
67+
from _ta_lib cimport TA_RetCode
6868
69-
lib.TA_Initialize()
7069
""")
7170

7271
# cleanup variable names to make them more pythonic
@@ -338,4 +337,4 @@ def cleanup(name):
338337
print('')
339338
print('')
340339

341-
print('__all__ = [%s]' % ','.join(['\"%s\"' % name for name in names]))
340+
print('__TA_FUNCTION_NAMES__ = [%s]' % ','.join(['\"%s\"' % name for name in names]))

Diff for: tools/generate_stream.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,12 @@
4848
# print headers
4949
print("""\
5050
cimport numpy as np
51-
from numpy import nan
5251
from cython import boundscheck, wraparound
52+
cimport _ta_lib as lib
53+
from _ta_lib cimport TA_RetCode
54+
# NOTE: _ta_check_success, NaN are defined in common.pxi
55+
# NumPy C API is initialize in _func.pxi
5356
54-
from .common cimport _ta_check_success
55-
56-
cdef double NaN = nan
57-
58-
cdef extern from "numpy/arrayobject.h":
59-
int PyArray_TYPE(np.ndarray)
60-
object PyArray_EMPTY(int, np.npy_intp*, int, int)
61-
int PyArray_FLAGS(np.ndarray)
62-
object PyArray_GETCONTIGUOUS(np.ndarray)
63-
64-
np.import_array() # Initialize the NumPy C API
65-
66-
cimport libta_lib as lib
67-
from libta_lib cimport TA_RetCode
68-
69-
lib.TA_Initialize()
7057
""")
7158

7259
# cleanup variable names to make them more pythonic
@@ -96,7 +83,7 @@ def cleanup(name):
9683

9784
print('@wraparound(False) # turn off relative indexing from end of lists')
9885
print('@boundscheck(False) # turn off bounds-checking for entire function')
99-
print('def %s(' % shortname, end=' ')
86+
print('def stream_%s(' % shortname, end=' ')
10087
docs = [' %s(' % shortname]
10188
i = 0
10289
for arg in args:
@@ -302,4 +289,3 @@ def cleanup(name):
302289
print('')
303290
print('')
304291

305-
print('__all__ = [%s]' % ','.join(['\"%s\"' % name for name in names]))

0 commit comments

Comments
 (0)