|
53 | 53 | #endif |
54 | 54 |
|
55 | 55 | /* Set this variable to 1 in order to debug garbage collection data |
56 | | -* and threading flow for improving the debug of memory leaks and async bugs. |
57 | | -* Set it to 0 in order to remove all the noise. |
58 | | -*/ |
| 56 | + * and threading flow for improving the debug of memory leaks and async bugs. |
| 57 | + * Set it to 0 in order to remove all the noise. |
| 58 | + */ |
59 | 59 | #define DEBUG_PRINT_ENABLED 0 |
60 | 60 |
|
61 | 61 | typedef struct loader_impl_py_function_type |
62 | 62 | { |
63 | 63 | PyObject *func; |
64 | 64 | PyObject **values; // Cache and re-use the values array |
65 | 65 | loader_impl impl; |
66 | | -} * loader_impl_py_function; |
| 66 | +} *loader_impl_py_function; |
67 | 67 |
|
68 | 68 | typedef struct loader_impl_py_future_type |
69 | 69 | { |
70 | 70 | loader_impl impl; |
71 | 71 | loader_impl_py py_impl; |
72 | 72 | PyObject *future; |
73 | 73 |
|
74 | | -} * loader_impl_py_future; |
| 74 | +} *loader_impl_py_future; |
75 | 75 |
|
76 | 76 | typedef struct loader_impl_py_class_type |
77 | 77 | { |
78 | 78 | PyObject *cls; |
79 | 79 | loader_impl impl; |
80 | 80 |
|
81 | | -} * loader_impl_py_class; |
| 81 | +} *loader_impl_py_class; |
82 | 82 |
|
83 | 83 | typedef struct loader_impl_py_object_type |
84 | 84 | { |
85 | 85 | PyObject *obj; |
86 | 86 | loader_impl impl; |
87 | 87 | value obj_class; |
88 | 88 |
|
89 | | -} * loader_impl_py_object; |
| 89 | +} *loader_impl_py_object; |
90 | 90 |
|
91 | 91 | typedef struct loader_impl_py_handle_module_type |
92 | 92 | { |
93 | 93 | PyObject *instance; |
94 | 94 | PyObject *name; |
95 | 95 |
|
96 | | -} * loader_impl_py_handle_module; |
| 96 | +} *loader_impl_py_handle_module; |
97 | 97 |
|
98 | 98 | typedef struct loader_impl_py_handle_type |
99 | 99 | { |
100 | 100 | loader_impl_py_handle_module modules; |
101 | 101 | size_t size; |
102 | 102 |
|
103 | | -} * loader_impl_py_handle; |
| 103 | +} *loader_impl_py_handle; |
104 | 104 |
|
105 | 105 | struct loader_impl_py_type |
106 | 106 | { |
@@ -146,7 +146,7 @@ typedef struct loader_impl_py_await_invoke_callback_state_type |
146 | 146 | void *context; |
147 | 147 | PyObject *coroutine; |
148 | 148 |
|
149 | | -} * loader_impl_py_await_invoke_callback_state; |
| 149 | +} *loader_impl_py_await_invoke_callback_state; |
150 | 150 |
|
151 | 151 | static int py_loader_impl_check_class(loader_impl_py py_impl, PyObject *obj); |
152 | 152 |
|
@@ -200,8 +200,8 @@ static const char py_loader_capsule_null_id[] = "__metacall_capsule_null__"; |
200 | 200 | PyObject *py_loader_impl_capsule_new_null(void) |
201 | 201 | { |
202 | 202 | /* We want to create a new capsule with contents set to NULL, but PyCapsule |
203 | | - * does not allow that, instead we are going to identify our NULL capsule with |
204 | | - * this configuration (setting the capsule to Py_None) */ |
| 203 | + * does not allow that, instead we are going to identify our NULL capsule with |
| 204 | + * this configuration (setting the capsule to Py_None) */ |
205 | 205 | return PyCapsule_New((void *)Py_NonePtr(), py_loader_capsule_null_id, NULL); |
206 | 206 | } |
207 | 207 |
|
@@ -2111,11 +2111,22 @@ int py_loader_impl_initialize_import(loader_impl_py py_impl) |
2111 | 2111 | " if path == None:\n" |
2112 | 2112 | " if module_name in sys.modules:\n" |
2113 | 2113 | " return sys.modules[module_name]\n" |
2114 | | - " else:\n" |
2115 | | - " spec = importlib.util.find_spec(module_name)\n" |
2116 | | - " if spec is None:\n" |
2117 | | - " return FileNotFoundError('Module ' + module_name + ' could not be found')\n" |
2118 | | - " return load_from_spec(module_name, spec)\n" |
| 2114 | + " file_path = Path(module_name).absolute()\n" |
| 2115 | + " if file_path.suffix != \'.py\':\n" |
| 2116 | + " file_path = file_path.with_suffix(\'.py\')\n" |
| 2117 | + " current_search_location = str(file_path.parent)\n" |
| 2118 | + " if not current_search_location in sys.path:\n" |
| 2119 | + " search_location = current_search_location\n" |
| 2120 | + " sys.path.insert(0, current_search_location)\n" |
| 2121 | + " spec = importlib.util.spec_from_file_location(file_path.stem, str(file_path))\n" |
| 2122 | + " if spec is None:\n" |
| 2123 | + " if search_location is not None:\n" |
| 2124 | + " sys.path.pop(0)\n" |
| 2125 | + " return FileNotFoundError(\'Module \' + module_name + \' could not be found\')\n" |
| 2126 | + " module = load_from_spec(module_name, spec)\n" |
| 2127 | + " if search_location is not None:\n" |
| 2128 | + " sys.path.pop(0)\n" |
| 2129 | + " return module\n" |
2119 | 2130 | " else:\n" |
2120 | 2131 | " current_search_location = str(Path(path).parent.absolute())\n" |
2121 | 2132 | " if not current_search_location in sys.path:\n" |
@@ -2499,9 +2510,9 @@ loader_impl_data py_loader_impl_initialize(loader_impl impl, configuration confi |
2499 | 2510 | py_loader_impl_main_module = argv[1]; |
2500 | 2511 |
|
2501 | 2512 | /* If we are running on host, this means the main is already executed by the host, so we can skip it, |
2502 | | - * otherwise if we are not in host and we run it for the first time, we can prepare the loader |
2503 | | - * for running the main the first time |
2504 | | - */ |
| 2513 | + * otherwise if we are not in host and we run it for the first time, we can prepare the loader |
| 2514 | + * for running the main the first time |
| 2515 | + */ |
2505 | 2516 | if (host == 0) |
2506 | 2517 | { |
2507 | 2518 | py_loader_impl_run_main = 0; |
@@ -3658,7 +3669,7 @@ int py_loader_impl_discover_class(loader_impl impl, PyObject *py_class, klass c) |
3658 | 3669 | PyUnicode_AsUTF8(tuple_key), |
3659 | 3670 | args_count, |
3660 | 3671 | NULL, /* There's no need to pass the method implementation (tuple_val) here, |
3661 | | - * it is used only for introspection, not for invoking it, that's done by name */ |
| 3672 | + * it is used only for introspection, not for invoking it, that's done by name */ |
3662 | 3673 | VISIBILITY_PUBLIC, /* TODO: check @property decorator for protected access? */ |
3663 | 3674 | func_synchronicity, |
3664 | 3675 | NULL); |
@@ -3725,7 +3736,7 @@ static int py_loader_impl_validate_object(loader_impl impl, PyObject *obj, objec |
3725 | 3736 | log_write("metacall", LOG_LEVEL_DEBUG, "Discover object member %s, type %s", |
3726 | 3737 | PyUnicode_AsUTF8(dict_key), |
3727 | 3738 | type_id_name(py_loader_impl_capi_to_value_type(dict_val))); |
3728 | | - |
| 3739 | +
|
3729 | 3740 | } |
3730 | 3741 | } |
3731 | 3742 |
|
|
0 commit comments