|
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | from setuptools import setup, Extension |
4 | | -from Cython.Build import cythonize |
| 4 | +try: |
| 5 | + from Cython.Build import cythonize |
| 6 | +except ImportError: |
| 7 | + cythonize = None |
5 | 8 |
|
6 | | -current_dir = os.path.dirname(os.path.abspath(__file__)) |
7 | | -# Assume CMake build is at ../build |
8 | | -build_dir = os.path.abspath(os.path.join(current_dir, "../build")) |
9 | | -include_dir = os.path.join(build_dir, "_deps/databento-src/include") |
10 | | -lib_dir = os.path.join(build_dir, "lib/Release") |
| 9 | +ext_modules = [] |
11 | 10 |
|
12 | | -# If headers don't exist, we can't build. |
13 | | -# We will assume user runs cmake first. |
| 11 | +if cythonize: |
| 12 | + current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 13 | + # Assume CMake build is at ../build |
| 14 | + build_dir = os.path.abspath(os.path.join(current_dir, "../build")) |
| 15 | + include_dir = os.path.join(build_dir, "_deps/databento-src/include") |
| 16 | + lib_dir = os.path.join(build_dir, "lib/Release") |
14 | 17 |
|
15 | | -httplib_dir = os.path.join(build_dir, "_deps/httplib-src") |
16 | | -json_dir = os.path.join(build_dir, "_deps/json-src/include") |
| 18 | + # If headers don't exist, we can't build. |
| 19 | + # We will assume user runs cmake first. |
| 20 | + |
| 21 | + httplib_dir = os.path.join(build_dir, "_deps/httplib-src") |
| 22 | + json_dir = os.path.join(build_dir, "_deps/json-src/include") |
17 | 23 |
|
18 | | -extensions = [ |
19 | | - Extension( |
20 | | - "databento_ext", |
21 | | - ["databento.pyx"], |
22 | | - include_dirs=[include_dir, httplib_dir, json_dir], |
23 | | - library_dirs=[lib_dir, "/usr/local/lib"], |
24 | | - libraries=["databento", "zstd", "curl", "ssl", "crypto", "brotlicommon", "brotlidec", "brotlienc"], |
25 | | - language="c++", |
26 | | - extra_compile_args=["-std=c++17", "-O3", "-undefined", "dynamic_lookup"] |
27 | | - ) |
28 | | -] |
| 24 | + if os.path.exists(include_dir) and os.path.exists(lib_dir): |
| 25 | + extensions = [ |
| 26 | + Extension( |
| 27 | + "databento_ext", |
| 28 | + ["databento.pyx"], |
| 29 | + include_dirs=[include_dir, httplib_dir, json_dir], |
| 30 | + library_dirs=[lib_dir, "/usr/local/lib"], |
| 31 | + libraries=["databento", "zstd", "curl", "ssl", "crypto", "brotlicommon", "brotlidec", "brotlienc"], |
| 32 | + language="c++", |
| 33 | + extra_compile_args=["-std=c++17", "-O3", "-undefined", "dynamic_lookup"] |
| 34 | + ) |
| 35 | + ] |
| 36 | + ext_modules = cythonize(extensions, compiler_directives={'language_level': "3"}) |
| 37 | + else: |
| 38 | + print(f"Databento include/lib not found at {build_dir}, skipping extension build") |
| 39 | +else: |
| 40 | + print("Cython not found, skipping extension build") |
29 | 41 |
|
30 | 42 | setup( |
31 | 43 | name="databento_ext", |
32 | | - ext_modules=cythonize(extensions, compiler_directives={'language_level': "3"}), |
| 44 | + ext_modules=ext_modules, |
33 | 45 | ) |
0 commit comments