Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build from source if the ta-lib is not installed #135

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ env:
TA_INCLUDE_PATH=$DEPS_DIR/include
LD_LIBRARY_PATH=$DEPS_DIR/lib
TA_LIBRARY_PATH=$DEPS_DIR/lib
- WITH_TA_LIBRARY=no
cache:
directories:
- $DEPS_DIR
- pip
- directories:
- $DEPS_DIR
install:
- pip install --upgrade pip wheel
- pip install -r requirements_test.txt
Expand Down
13 changes: 13 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include README.md
include AUTHORS
include CHANGELOG
include COPYRIGHT
include DEVELOPMENT
include LICENSE
include requirements.txt
recursive-include vendor *
recursive-include talib *.py *.pyx *.pxi *.pxd *.c
prune vendor/ta-lib/temp
prune vendor/ta-lib/make
prune vendor/ta-lib/ide
prune vendor/ta-lib/src/tools
91 changes: 70 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import glob
import sys
import os
import warnings
Expand All @@ -21,19 +22,22 @@
from distutils.extension import Extension

lib_talib_name = 'ta_lib' # the underlying C library's name
sources = []

platform_supported = False
for prefix in ['darwin', 'linux', 'bsd', 'sunos']:
if prefix in sys.platform:
platform_supported = True
include_dirs = [
'/usr/include',
'/usr/local/include',
'/opt/include',
'/opt/local/include',
'/usr/include/ta-lib',
'/usr/local/include/ta-lib',
'/opt/include/ta-lib',
'/opt/local/include/ta-lib',
]
if 'TA_INCLUDE_PATH' in os.environ:
include_dirs.append(os.environ['TA_INCLUDE_PATH'])
include_dirs.append(
os.path.join(os.environ['TA_INCLUDE_PATH'], "ta-lib")
)
lib_talib_dirs = [
'/usr/lib',
'/usr/local/lib',
Expand All @@ -49,7 +53,7 @@
if sys.platform == "win32":
platform_supported = True
lib_talib_name = 'ta_libc_cdr'
include_dirs = [r"c:\ta-lib\c\include"]
include_dirs = [r"c:\ta-lib\c\include\ta-lib"]
lib_talib_dirs = [r"c:\ta-lib\c\lib"]

if not platform_supported:
Expand All @@ -66,6 +70,7 @@
except ImportError:
has_cython = False

libraries = [lib_talib_name]
for lib_talib_dir in lib_talib_dirs:
try:
files = os.listdir(lib_talib_dir)
Expand All @@ -74,7 +79,51 @@
except OSError:
pass
else:
warnings.warn('Cannot find ta-lib library, installation may fail.')
libraries = []
warnings.warn(
'Cannot find ta-lib library, will try to build from source.'
)
# find vendor/ta-lib -name "*.h" -exec dirname {} \; | sort | uniq
vendor_dir = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"vendor",
)
vendor_talib_dir = os.path.join(
vendor_dir,
"ta-lib",
)
talib_include_dirs = [
("include", ),
("src", "ta_abstract"),
("src", "ta_abstract", "frames"),
("src", "ta_common"),
("src", "ta_func"),
]
include_dirs.extend((
os.path.join(vendor_talib_dir, *path_args)
for path_args in talib_include_dirs
))

talib_source_dirs = [
("ta_abstract", ),
("ta_abstract", "frames"),
("ta_abstract", "tables"),
("ta_common", ),
("ta_func", )
]
for path_args in talib_source_dirs:
source_dir = os.path.join(vendor_talib_dir, "src", *path_args)
sources.extend(glob.glob(os.path.join(source_dir, "*.c")))
excel_glue_c_file = os.path.join(
vendor_talib_dir, "src", "ta_abstract", "excel_glue.c"
)
try:
sources.remove(excel_glue_c_file)
except ValueError:
pass
libraries = []
lib_talib_dirs = []


cmdclass = {}
if has_cython:
Expand All @@ -83,22 +132,22 @@
ext_modules = [
Extension(
'talib._ta_lib',
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'],
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'] + sources,
include_dirs=include_dirs,
library_dirs=lib_talib_dirs,
libraries=[lib_talib_name]
libraries=libraries
)
]

setup(
name = 'TA-Lib',
version = '0.4.10',
description = 'Python wrapper for TA-Lib',
author = 'John Benediktsson',
author_email = '[email protected]',
url = 'http://github.com/mrjbq7/ta-lib',
download_url = 'https://github.com/mrjbq7/ta-lib/releases',
classifiers = [
name='TA-Lib',
version='0.4.10',
description='Python wrapper for TA-Lib',
author='John Benediktsson',
author_email='[email protected]',
url='http://github.com/mrjbq7/ta-lib',
download_url='https://github.com/mrjbq7/ta-lib/releases',
classifiers=[
"License :: OSI Approved :: BSD License",
"Development Status :: 4 - Beta",
"Operating System :: Unix",
Expand All @@ -117,8 +166,8 @@
"Intended Audience :: Science/Research",
"Intended Audience :: Financial and Insurance Industry",
],
packages = ['talib'],
ext_modules = ext_modules,
cmdclass = cmdclass,
requires = ['numpy'],
packages=['talib'],
ext_modules=ext_modules,
cmdclass=cmdclass,
requires=['numpy'],
)
12 changes: 4 additions & 8 deletions talib/_ta_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,10 @@ static CYTHON_INLINE float __PYX_NAN() {

#define __PYX_HAVE__talib___ta_lib
#define __PYX_HAVE_API__talib___ta_lib
#if defined(WIN32) || defined(MS_WINDOWS)
#include "ta-libc.h"
#else
#include "ta-lib/ta_defs.h"
#include "ta-lib/ta_common.h"
#include "ta-lib/ta_abstract.h"
#include "ta-lib/ta_func.h"
#endif
#include "ta_defs.h"
#include "ta_common.h"
#include "ta_abstract.h"
#include "ta_func.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
8 changes: 4 additions & 4 deletions talib/_ta_lib.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cdef extern from "ta-lib/ta_defs.h":
cdef extern from "ta_defs.h":
ctypedef int TA_RetCode

ctypedef int TA_RetCode
Expand Down Expand Up @@ -84,7 +84,7 @@ cdef extern from "ta-lib/ta_defs.h":
TA_CandleSettingType TA_Equal = 10
TA_CandleSettingType TA_AllCandleSettings = 11

cdef extern from "ta-lib/ta_common.h":
cdef extern from "ta_common.h":
char *TA_GetVersionString()
char *TA_GetVersionMajor()
char *TA_GetVersionMinor()
Expand All @@ -109,7 +109,7 @@ cdef extern from "ta-lib/ta_common.h":
TA_RetCode TA_Initialize()
TA_RetCode TA_Shutdown()

cdef extern from "ta-lib/ta_abstract.h":
cdef extern from "ta_abstract.h":

TA_RetCode TA_GroupTableAlloc(TA_StringTable **table)
TA_RetCode TA_GroupTableFree(TA_StringTable *table)
Expand Down Expand Up @@ -192,7 +192,7 @@ cdef extern from "ta-lib/ta_abstract.h":

char* TA_FunctionDescriptionXML()

cdef extern from "ta-lib/ta_func.h":
cdef extern from "ta_func.h":
TA_RetCode TA_ACOS(int startIdx, int endIdx, const double inReal[], int *outBegIdx, int *outNBElement, double outReal[])
int TA_ACOS_Lookback()
TA_RetCode TA_AD(int startIdx, int endIdx, const double inHigh[], const double inLow[], const double inClose[], const double inVolume[], int *outBegIdx, int *outNBElement, double outReal[])
Expand Down
9 changes: 5 additions & 4 deletions tools/generate_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
# FIXME: don't return number of elements since it always equals allocation?

functions = []
include_paths = ['/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include']
include_paths = ['/usr/include/ta-lib', '/usr/local/include/ta-lib', '/opt/include/ta-lib', '/opt/local/include/ta-lib']
if sys.platform == 'win32':
include_paths = [r'c:\ta-lib\c\include']
include_paths = [r'c:\ta-lib\c\include\ta-lib']
include_paths.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), "vendor", "ta-lib", "include"))
header_found = False
for path in include_paths:
ta_func_header = os.path.join(path, 'ta-lib', 'ta_func.h')
ta_func_header = os.path.join(path, 'ta_func.h')
if os.path.exists(ta_func_header):
header_found = True
break
if not header_found:
print('Error: ta-lib/ta_func.h not found', file=sys.stderr)
print('Error: ta_func.h not found', file=sys.stderr)
sys.exit(1)
with open(ta_func_header) as f:
tmp = []
Expand Down
9 changes: 5 additions & 4 deletions tools/generate_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
# FIXME: don't return number of elements since it always equals allocation?

functions = []
include_paths = ['/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include']
include_paths = ['/usr/include/ta-lib', '/usr/local/include/ta-lib', '/opt/include/ta-lib', '/opt/local/include/ta-lib']
if sys.platform == 'win32':
include_paths = [r'c:\ta-lib\c\include']
include_paths = [r'c:\ta-lib\c\include\ta-lib']
include_paths.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), "vendor", "ta-lib", "include"))
header_found = False
for path in include_paths:
ta_func_header = os.path.join(path, 'ta-lib', 'ta_func.h')
ta_func_header = os.path.join(path, 'ta_func.h')
if os.path.exists(ta_func_header):
header_found = True
break
if not header_found:
print('Error: ta-lib/ta_func.h not found', file=sys.stderr)
print('Error: ta_func.h not found', file=sys.stderr)
sys.exit(1)
with open(ta_func_header) as f:
tmp = []
Expand Down
3 changes: 3 additions & 0 deletions vendor/ta-lib/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AUTOMAKE_OPTIONS = foreign 1.4
SUBDIRS = src src/tools
bin_SCRIPTS = ta-lib-config
11 changes: 11 additions & 0 deletions vendor/ta-lib/autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
echo aclocal
aclocal || exit
echo autoheader
autoheader || exit
echo libtoolize --copy --force
libtoolize --copy --force || exit
echo automake -a -c
automake -a -c || exit
echo autoconf
autoconf || exit
7 changes: 7 additions & 0 deletions vendor/ta-lib/bin/.cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gen_code
gen_data
gen_rdata
ta_regtest
ta_sql
ta_yahoo
webfetch
2 changes: 2 additions & 0 deletions vendor/ta-lib/bin/HOLDER
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Do not erase this file.
Some maintenance tools ignore empty directory. This file prevents this directory to be empty.
47 changes: 47 additions & 0 deletions vendor/ta-lib/configure.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_COPYRIGHT([(c) TicTacTec 2005, 2006])
AC_INIT([ta-lib], [SVN], [http://sourceforge.net/tracker/?group_id=8903&atid=108903])
AC_CONFIG_SRCDIR([src/ta_func/ta_AD.c])
AC_CONFIG_HEADER([include/ta_config.h])
AM_INIT_AUTOMAKE([ta-lib], [SVN])

# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL

# Checks for libraries.
AC_CHECK_LIB([dl], [dlopen])
AC_CHECK_LIB([pthread], [pthread_create])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([float.h inttypes.h limits.h locale.h stddef.h stdint.h stdlib.h string.h unistd.h wchar.h wctype.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_C_VOLATILE
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_STRCOLL
AC_FUNC_STRFTIME
AC_FUNC_STRTOD
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([floor isascii localeconv mblen memmove memset modf pow sqrt strcasecmp strchr strerror strncasecmp strrchr strstr strtol strtoul])

# Versioning:
# Only change this if library is no longer
# ABI compatible with previous version
# (e.g. function declaration changed)
TALIB_LIBRARY_VERSION=0:0:0

AC_SUBST(TALIB_LIBRARY_VERSION)

AC_CONFIG_FILES([Makefile src/Makefile src/ta_abstract/Makefile src/ta_common/Makefile src/ta_func/Makefile src/tools/Makefile src/tools/gen_code/Makefile src/tools/ta_regtest/Makefile ta-lib-config ta-lib.spec ta-lib.dpkg])
AC_OUTPUT
Loading