diff --git a/.gitignore b/.gitignore index aa4d524e5..49ddb78e1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,10 @@ docs/html docs/.tadoc.org.html *.pyc -build +build/ +dist/ *.so .* *~ +*.egg-info/ diff --git a/DEVELOPMENT b/DEVELOPMENT index 6be2ee04e..fd29fec0e 100644 --- a/DEVELOPMENT +++ b/DEVELOPMENT @@ -12,34 +12,34 @@ Here's the full list of make commands (see the Makefile file): make build # builds and places libs in the project directory; required for testing make clean # cleans the local build files make install # installs talib system-wide -make generate: # generates a fresh func.pyx file. Requires talib and TA-Lib to both be installed +make generate: # generates a fresh _func.pxi, _stream.pxi file. Requires talib and TA-Lib to both be installed make perf # run performance profiling make test # run tests The source code is comprised of one python package, located in the talib -directory, which itself has three Cython modules: func, abstract, and -common. +directory, which itself has one Cython module (_ta_lib) which consists of +four parts: _common, _func, _abstract and _stream. -talib/common.pyx - An internal-use module for functionality shared between func and abstract. +talib/_common.pxi + An internal-use file for functionality shared between func and abstract. -talib/func.pyx - This file is generated automatically by tools/generate.py and any changes made +talib/_func.pxi + This file is generated automatically by tools/generate_func.py and any changes made to it directly will get overwritten! -talib/abstract.pyx +talib/_abstract.pxi This file contains the code for interfacing with the TA-Lib abstract interface and wrapping it into a pythonic Function class. -talib/libta_lib.pxd +talib/_ta_lib.pyx This "Cython header file" defines the C-level functions, variables and types we need to use in the above pyx files. -talib/stream.pyx +talib/_stream.pxi This file contains code for interfacing a "streaming" interface to TA-Lib. -tools/generate.py - A script that generates and prints func.pyx to stdout. Gets information +tools/generate_func.py,generate_stream.py + Scripts that generate and print _func.pxi or _stream.pxi to stdout. Gets information about all functions from the C headers of the installed TA-Lib. If you are interested in developing new indicator functions or whatnot on diff --git a/Makefile b/Makefile index c0897ad01..1b971b004 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,13 @@ build: install: python setup.py install -generate: - python tools/generate_func.py > talib/func.pyx +talib/_func.pxi: tools/generate_func.py + python tools/generate_func.py > talib/_func.pxi + +talib/_stream.pxi: tools/generate_stream.py + python tools/generate_stream.py > talib/_stream.pxi + +generate: talib/_func.pxi talib/_stream.pxi clean: rm -rf build talib/func*.so talib/abstract*.so talib/common*.so talib/stream*.so talib/*.pyc diff --git a/talib/_abstract.pxi b/talib/_abstract.pxi index 1d27a6a7e..8b6ef41b7 100644 --- a/talib/_abstract.pxi +++ b/talib/_abstract.pxi @@ -14,8 +14,6 @@ cimport numpy as np cimport _ta_lib as lib # NOTE: _ta_check_success, MA_Type is defined in _common.pxi -lib.TA_Initialize() - __INPUT_ARRAYS_DEFAULTS = {'open': None, 'high': None, diff --git a/talib/abstract.py b/talib/abstract.py index 3164baa23..bfb9be32f 100644 --- a/talib/abstract.py +++ b/talib/abstract.py @@ -22,4 +22,4 @@ def Function(function_name, *args, **kwargs): globals()[func_name] = Function(func_name) -__all__ = ["Function"] + __TA_FUNCTION_NAMES__ +__all__ = ["Function", "_get_defaults_and_docs"] + __TA_FUNCTION_NAMES__ diff --git a/tools/generate_func.py b/tools/generate_func.py index 35e0a78d7..61cc82896 100644 --- a/tools/generate_func.py +++ b/tools/generate_func.py @@ -51,7 +51,7 @@ from numpy import nan from cython import boundscheck, wraparound -from .common cimport _ta_check_success +# _ta_check_success: defined in _common.pxi cdef double NaN = nan @@ -63,10 +63,9 @@ np.import_array() # Initialize the NumPy C API -cimport libta_lib as lib -from libta_lib cimport TA_RetCode +cimport _ta_lib as lib +from _ta_lib cimport TA_RetCode -lib.TA_Initialize() """) # cleanup variable names to make them more pythonic @@ -338,4 +337,4 @@ def cleanup(name): print('') print('') -print('__all__ = [%s]' % ','.join(['\"%s\"' % name for name in names])) +print('__TA_FUNCTION_NAMES__ = [%s]' % ','.join(['\"%s\"' % name for name in names])) diff --git a/tools/generate_stream.py b/tools/generate_stream.py index 86509b4c2..48df55b6f 100644 --- a/tools/generate_stream.py +++ b/tools/generate_stream.py @@ -48,25 +48,12 @@ # print headers print("""\ cimport numpy as np -from numpy import nan from cython import boundscheck, wraparound +cimport _ta_lib as lib +from _ta_lib cimport TA_RetCode +# NOTE: _ta_check_success, NaN are defined in common.pxi +# NumPy C API is initialize in _func.pxi -from .common cimport _ta_check_success - -cdef double NaN = nan - -cdef extern from "numpy/arrayobject.h": - int PyArray_TYPE(np.ndarray) - object PyArray_EMPTY(int, np.npy_intp*, int, int) - int PyArray_FLAGS(np.ndarray) - object PyArray_GETCONTIGUOUS(np.ndarray) - -np.import_array() # Initialize the NumPy C API - -cimport libta_lib as lib -from libta_lib cimport TA_RetCode - -lib.TA_Initialize() """) # cleanup variable names to make them more pythonic @@ -96,7 +83,7 @@ def cleanup(name): print('@wraparound(False) # turn off relative indexing from end of lists') print('@boundscheck(False) # turn off bounds-checking for entire function') - print('def %s(' % shortname, end=' ') + print('def stream_%s(' % shortname, end=' ') docs = [' %s(' % shortname] i = 0 for arg in args: @@ -302,4 +289,3 @@ def cleanup(name): print('') print('') -print('__all__ = [%s]' % ','.join(['\"%s\"' % name for name in names]))