|
8 | 8 | from cppimport.find import _check_first_line_contains_cppimport
|
9 | 9 |
|
10 | 10 | settings = dict(
|
11 |
| - force_rebuild=False, |
| 11 | + force_rebuild=False, # `force_rebuild` with multiple processes is not supported |
12 | 12 | file_exts=[".cpp", ".c"],
|
13 | 13 | rtld_flags=ctypes.RTLD_LOCAL,
|
| 14 | + lock_suffix=".lock", |
| 15 | + lock_timeout=10 * 60, |
14 | 16 | remove_strict_prototypes=True,
|
15 | 17 | release_mode=os.getenv("CPPIMPORT_RELEASE_MODE", "0").lower()
|
16 | 18 | in ("true", "yes", "1"),
|
@@ -57,19 +59,26 @@ def imp_from_filepath(filepath, fullname=None):
|
57 | 59 | module : the compiled and loaded Python extension module
|
58 | 60 | """
|
59 | 61 | from cppimport.importer import (
|
| 62 | + build_safely, |
60 | 63 | is_build_needed,
|
61 | 64 | load_module,
|
62 | 65 | setup_module_data,
|
63 |
| - template_and_build, |
64 | 66 | try_load,
|
65 | 67 | )
|
66 | 68 |
|
| 69 | + filepath = os.path.abspath(filepath) |
67 | 70 | if fullname is None:
|
68 | 71 | fullname = os.path.splitext(os.path.basename(filepath))[0]
|
69 | 72 | module_data = setup_module_data(fullname, filepath)
|
| 73 | + # The call to try_load is necessary here because there are times when the |
| 74 | + # only evidence a rebuild is needed comes from attempting to load an |
| 75 | + # existing extension module. For example, if the extension was built on a |
| 76 | + # different architecture or with different Python headers and will produce |
| 77 | + # an error when loaded, then the load will fail. In that situation, we will |
| 78 | + # need to rebuild. |
70 | 79 | if is_build_needed(module_data) or not try_load(module_data):
|
71 |
| - template_and_build(filepath, module_data) |
72 |
| - load_module(module_data) |
| 80 | + build_safely(filepath, module_data) |
| 81 | + load_module(module_data) |
73 | 82 | return module_data["module"]
|
74 | 83 |
|
75 | 84 |
|
@@ -108,17 +117,19 @@ def build_filepath(filepath, fullname=None):
|
108 | 117 | ext_path : the path to the compiled extension.
|
109 | 118 | """
|
110 | 119 | from cppimport.importer import (
|
| 120 | + build_safely, |
111 | 121 | is_build_needed,
|
| 122 | + load_module, |
112 | 123 | setup_module_data,
|
113 |
| - template_and_build, |
114 | 124 | )
|
115 | 125 |
|
| 126 | + filepath = os.path.abspath(filepath) |
116 | 127 | if fullname is None:
|
117 | 128 | fullname = os.path.splitext(os.path.basename(filepath))[0]
|
118 | 129 | module_data = setup_module_data(fullname, filepath)
|
119 | 130 | if is_build_needed(module_data):
|
120 |
| - template_and_build(filepath, module_data) |
121 |
| - |
| 131 | + build_safely(filepath, module_data) |
| 132 | + load_module(module_data) |
122 | 133 | # Return the path to the built module
|
123 | 134 | return module_data["ext_path"]
|
124 | 135 |
|
|
0 commit comments