Skip to content

Commit fbc436b

Browse files
committed
setup.py: Rearrange platform code.
Allow TA_INCLUDE_PATH and TA_LIBRARY_PATH to be used on all platforms.
1 parent b938d6a commit fbc436b

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

setup.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,42 @@
2020

2121
lib_talib_name = 'ta_lib' # the underlying C library's name
2222

23-
runtime_lib_dirs = []
24-
2523
platform_supported = False
26-
for prefix in ['darwin', 'linux', 'bsd', 'sunos']:
27-
if prefix in sys.platform:
28-
platform_supported = True
29-
include_dirs = [
30-
'/usr/include',
31-
'/usr/local/include',
32-
'/opt/include',
33-
'/opt/local/include',
34-
'/opt/homebrew/include',
35-
'/opt/homebrew/opt/ta-lib/include',
36-
]
37-
if 'TA_INCLUDE_PATH' in os.environ:
38-
include_dirs.append(os.environ['TA_INCLUDE_PATH'])
39-
lib_talib_dirs = [
40-
'/usr/lib',
41-
'/usr/local/lib',
42-
'/usr/lib64',
43-
'/usr/local/lib64',
44-
'/opt/lib',
45-
'/opt/local/lib',
46-
'/opt/homebrew/lib',
47-
'/opt/homebrew/opt/ta-lib/lib',
48-
]
49-
if 'TA_LIBRARY_PATH' in os.environ:
50-
runtime_lib_dirs = os.environ['TA_LIBRARY_PATH']
51-
if runtime_lib_dirs:
52-
runtime_lib_dirs = runtime_lib_dirs.split(os.pathsep)
53-
lib_talib_dirs.extend(runtime_lib_dirs)
54-
break
55-
56-
if sys.platform == "win32":
24+
25+
if any(s in sys.platform for s in ['darwin', 'linux', 'bsd', 'sunos']):
26+
platform_supported = True
27+
include_dirs = [
28+
'/usr/include',
29+
'/usr/local/include',
30+
'/opt/include',
31+
'/opt/local/include',
32+
'/opt/homebrew/include',
33+
'/opt/homebrew/opt/ta-lib/include',
34+
]
35+
library_dirs = [
36+
'/usr/lib',
37+
'/usr/local/lib',
38+
'/usr/lib64',
39+
'/usr/local/lib64',
40+
'/opt/lib',
41+
'/opt/local/lib',
42+
'/opt/homebrew/lib',
43+
'/opt/homebrew/opt/ta-lib/lib',
44+
]
45+
46+
elif sys.platform == "win32":
5747
platform_supported = True
5848
lib_talib_name = 'ta_libc_cdr'
5949
include_dirs = [r"c:\ta-lib\c\include"]
60-
lib_talib_dirs = [r"c:\ta-lib\c\lib"]
50+
library_dirs = [r"c:\ta-lib\c\lib"]
51+
52+
if 'TA_INCLUDE_PATH' in os.environ:
53+
paths = os.environ['TA_INCLUDE_PATH'].split(os.pathsep)
54+
include_dirs.extend(path for path in paths if path)
55+
56+
if 'TA_LIBRARY_PATH' in os.environ:
57+
paths = os.environ['TA_LIBRARY_PATH'].split(os.pathsep)
58+
library_dirs.extend(path for path in paths if path)
6159

6260
if not platform_supported:
6361
raise NotImplementedError(sys.platform)
@@ -68,9 +66,9 @@
6866
except ImportError:
6967
has_cython = False
7068

71-
for lib_talib_dir in lib_talib_dirs:
69+
for path in library_dirs:
7270
try:
73-
files = os.listdir(lib_talib_dir)
71+
files = os.listdir(path)
7472
if any(lib_talib_name in f for f in files):
7573
break
7674
except OSError:
@@ -135,9 +133,9 @@ def build_extensions(self):
135133
'talib._ta_lib',
136134
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'],
137135
include_dirs=include_dirs,
138-
library_dirs=lib_talib_dirs,
136+
library_dirs=library_dirs,
139137
libraries=[lib_talib_name],
140-
runtime_library_dirs=runtime_lib_dirs)
138+
runtime_library_dirs=library_dirs)
141139
]
142140

143141
from os import path

0 commit comments

Comments
 (0)