|
1 | 1 | import os |
| 2 | +import shutil |
2 | 3 | import struct |
3 | 4 |
|
4 | 5 | from setuptools import Extension, find_packages |
|
32 | 33 | else: |
33 | 34 | current_os = 'centos' |
34 | 35 |
|
| 36 | +capi_root_dir = root_path / 'dxfeed' / 'dxfeed-c-api' |
| 37 | +capi_include_dir = capi_root_dir / 'include' |
| 38 | +# capi_bin_dir = capi_root_dir / 'bin' |
| 39 | +capi_bin_dir = root_path / 'dxfeed' / 'core' |
35 | 40 | path_to_extract = root_path / 'dxfeed' / 'tmp' |
36 | | -capi_root_dir = path_to_extract / f'dxfeed-c-api-{capi_version}-no-tls' |
| 41 | +capi_extracted_root_dir = path_to_extract / f'dxfeed-c-api-{capi_version}-no-tls' |
37 | 42 |
|
38 | | -if (not os.path.exists(path_to_extract)) or (not os.path.exists(capi_root_dir)): |
39 | | - url = f'https://github.com/dxFeed/dxfeed-c-api/releases/download/{capi_version}/dxfeed-c-api-{capi_version}-{current_os}-no-tls.zip' |
| 43 | +if (not os.path.exists(path_to_extract)) or (not os.path.exists(capi_extracted_root_dir)): |
| 44 | + url = f'https://github.com/dxFeed/dxfeed-c-api/releases/download/{capi_version}/dxfeed-c-api-{capi_version}-' \ |
| 45 | + f'{current_os}-no-tls.zip ' |
40 | 46 | print(f'Downloading the "{url}"') |
41 | 47 | resp = urlopen(url) |
42 | 48 | zipfile = ZipFile(BytesIO(resp.read())) |
43 | 49 | print(f'Extracting to "{path_to_extract}"') |
44 | 50 | zipfile.extractall(path_to_extract) |
45 | 51 |
|
46 | | -if current_os == 'windows': |
| 52 | +if platform.system() == 'Windows': |
47 | 53 | if is_x64: |
48 | | - capi_library_dir = str(capi_root_dir / 'bin' / 'x64') |
| 54 | + capi_extracted_library_dir = capi_extracted_root_dir / 'bin' / 'x64' |
49 | 55 | capi_library_name = 'DXFeed_64' |
| 56 | + capi_library_file_name = f'{capi_library_name}.dll' |
| 57 | + capi_library_file_name2 = f'{capi_library_name}.lib' |
50 | 58 | else: |
51 | | - capi_library_dir = capi_root_dir / 'bin' / 'x86' |
| 59 | + capi_extracted_library_dir = capi_extracted_root_dir / 'bin' / 'x86' |
52 | 60 | capi_library_name = 'DXFeed' |
53 | | -elif current_os == 'macosx': |
| 61 | + capi_library_file_name = f'{capi_library_name}.dll' |
| 62 | + capi_library_file_name2 = f'{capi_library_name}.lib' |
| 63 | +elif platform.system() == 'Darwin': |
54 | 64 | if is_x64: |
55 | | - capi_root_dir = capi_root_dir / f'DXFeedAll-{capi_version}-x64-no-tls' |
56 | | - capi_library_dir = capi_root_dir / 'bin' / 'x64' |
| 65 | + capi_extracted_root_dir = capi_extracted_root_dir / f'DXFeedAll-{capi_version}-x64-no-tls' |
| 66 | + capi_extracted_library_dir = capi_extracted_root_dir / 'bin' / 'x64' |
57 | 67 | capi_library_name = 'DXFeed_64' |
| 68 | + capi_library_file_name = f'lib{capi_library_name}.dylib' |
58 | 69 | else: |
59 | 70 | raise Exception('Unsupported platform') |
60 | 71 | else: |
61 | 72 | if is_x64: |
62 | | - capi_root_dir = capi_root_dir / f'DXFeedAll-{capi_version}-x64-no-tls' |
63 | | - capi_library_dir = capi_root_dir / 'bin' / 'x64' |
| 73 | + capi_extracted_root_dir = capi_extracted_root_dir / f'DXFeedAll-{capi_version}-x64-no-tls' |
| 74 | + capi_extracted_library_dir = capi_extracted_root_dir / 'bin' / 'x64' |
64 | 75 | capi_library_name = 'DXFeed_64' |
| 76 | + capi_library_file_name = f'lib{capi_library_name}.so' |
65 | 77 | else: |
66 | 78 | raise Exception('Unsupported platform') |
67 | 79 |
|
68 | | -if current_os == 'windows': |
69 | | - runtime_library_dirs = [] |
| 80 | +if not os.path.exists(capi_include_dir): |
| 81 | + shutil.copytree(capi_extracted_root_dir / 'include', capi_include_dir) |
| 82 | +if not os.path.exists(capi_bin_dir / capi_library_file_name): |
| 83 | + # os.makedirs(capi_bin_dir) |
| 84 | + shutil.copyfile(capi_extracted_library_dir / capi_library_file_name, capi_bin_dir / capi_library_file_name) |
| 85 | +if platform.system() == 'Windows': |
| 86 | + # noinspection PyUnboundLocalVariable |
| 87 | + if not os.path.exists(capi_bin_dir / capi_library_file_name2): |
| 88 | + shutil.copyfile(capi_extracted_library_dir / capi_library_file_name2, capi_bin_dir / capi_library_file_name2) |
| 89 | + |
| 90 | +if platform.system() == 'Windows': |
| 91 | + runtime_library_dirs = None |
70 | 92 | else: |
71 | | - runtime_library_dirs = [str(capi_library_dir)] |
| 93 | + runtime_library_dirs = [str(capi_bin_dir)] |
72 | 94 |
|
73 | | -capi_include_dirs = [str(capi_root_dir / 'include'), str(capi_root_dir / 'src')] |
| 95 | +capi_include_dirs = [str(capi_include_dir)] |
74 | 96 |
|
75 | 97 | libs = [capi_library_name] |
76 | 98 | if platform.system() == 'Windows': |
|
82 | 104 | include_dirs=capi_include_dirs), |
83 | 105 | Extension('dxfeed.core.listeners.listener', ['dxfeed/core/listeners/listener.' + ext], |
84 | 106 | include_dirs=capi_include_dirs), |
85 | | - Extension('dxfeed.core.DXFeedPy', ['dxfeed/core/DXFeedPy.' + ext], library_dirs=[str(capi_library_dir)], |
| 107 | + Extension('dxfeed.core.DXFeedPy', ['dxfeed/core/DXFeedPy.' + ext], library_dirs=[str(capi_bin_dir)], |
86 | 108 | runtime_library_dirs=runtime_library_dirs, |
87 | 109 | libraries=libs, |
88 | 110 | include_dirs=capi_include_dirs)] |
@@ -115,3 +137,7 @@ def build_extensions(): |
115 | 137 | build_ext_cmd.ensure_finalized() |
116 | 138 | build_ext_cmd.inplace = 1 |
117 | 139 | build_ext_cmd.run() |
| 140 | + |
| 141 | + print(f'Removing the "{path_to_extract}"') |
| 142 | + if os.path.exists(path_to_extract): |
| 143 | + shutil.rmtree(path_to_extract) |
0 commit comments