Skip to content

Commit a9e936b

Browse files
committed
fix: ownership problem for mac and py C loader implementation
1 parent d977527 commit a9e936b

2 files changed

Lines changed: 44 additions & 29 deletions

File tree

.github/workflows/release-nodejs.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ on:
44
workflow_dispatch:
55
pull_request:
66
push:
7-
branches: [ master, develop ]
7+
branches: [master, develop]
88
paths:
9-
- '.github/workflows/release-nodejs.yml'
10-
- 'source/ports/node_port/**'
9+
- ".github/workflows/release-nodejs.yml"
10+
- "source/ports/node_port/**"
1111

1212
concurrency:
1313
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -18,9 +18,9 @@ jobs:
1818
name: NodeJS Port Tests
1919
runs-on: ${{ matrix.os }}
2020
strategy:
21-
fail-fast: false
22-
matrix:
23-
os: [ubuntu-latest, windows-latest, macos-latest]
21+
fail-fast: false
22+
matrix:
23+
os: [ubuntu-latest, windows-latest, macos-latest]
2424
steps:
2525
- name: Check out the repo
2626
uses: actions/checkout@v4
@@ -33,10 +33,14 @@ jobs:
3333
if: matrix.os == 'windows-latest'
3434
run: powershell -NoProfile -ExecutionPolicy Unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/metacall/install/master/install.ps1')))"
3535

36+
- name: Fix NPM Permissions (macOS)
37+
if: matrix.os == 'macos-latest'
38+
run: sudo chown -R $(id -u):$(id -g) ~/.npm
39+
3640
- name: Set up Node.js
3741
uses: actions/setup-node@v4
3842
with:
39-
node-version: '20'
43+
node-version: "20"
4044

4145
- name: Install Dependencies
4246
working-directory: source/ports/node_port

source/loaders/py_loader/source/py_loader_impl.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,54 +53,54 @@
5353
#endif
5454

5555
/* 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+
*/
5959
#define DEBUG_PRINT_ENABLED 0
6060

6161
typedef struct loader_impl_py_function_type
6262
{
6363
PyObject *func;
6464
PyObject **values; // Cache and re-use the values array
6565
loader_impl impl;
66-
} * loader_impl_py_function;
66+
} *loader_impl_py_function;
6767

6868
typedef struct loader_impl_py_future_type
6969
{
7070
loader_impl impl;
7171
loader_impl_py py_impl;
7272
PyObject *future;
7373

74-
} * loader_impl_py_future;
74+
} *loader_impl_py_future;
7575

7676
typedef struct loader_impl_py_class_type
7777
{
7878
PyObject *cls;
7979
loader_impl impl;
8080

81-
} * loader_impl_py_class;
81+
} *loader_impl_py_class;
8282

8383
typedef struct loader_impl_py_object_type
8484
{
8585
PyObject *obj;
8686
loader_impl impl;
8787
value obj_class;
8888

89-
} * loader_impl_py_object;
89+
} *loader_impl_py_object;
9090

9191
typedef struct loader_impl_py_handle_module_type
9292
{
9393
PyObject *instance;
9494
PyObject *name;
9595

96-
} * loader_impl_py_handle_module;
96+
} *loader_impl_py_handle_module;
9797

9898
typedef struct loader_impl_py_handle_type
9999
{
100100
loader_impl_py_handle_module modules;
101101
size_t size;
102102

103-
} * loader_impl_py_handle;
103+
} *loader_impl_py_handle;
104104

105105
struct loader_impl_py_type
106106
{
@@ -146,7 +146,7 @@ typedef struct loader_impl_py_await_invoke_callback_state_type
146146
void *context;
147147
PyObject *coroutine;
148148

149-
} * loader_impl_py_await_invoke_callback_state;
149+
} *loader_impl_py_await_invoke_callback_state;
150150

151151
static int py_loader_impl_check_class(loader_impl_py py_impl, PyObject *obj);
152152

@@ -200,8 +200,8 @@ static const char py_loader_capsule_null_id[] = "__metacall_capsule_null__";
200200
PyObject *py_loader_impl_capsule_new_null(void)
201201
{
202202
/* 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) */
205205
return PyCapsule_New((void *)Py_NonePtr(), py_loader_capsule_null_id, NULL);
206206
}
207207

@@ -2111,11 +2111,22 @@ int py_loader_impl_initialize_import(loader_impl_py py_impl)
21112111
" if path == None:\n"
21122112
" if module_name in sys.modules:\n"
21132113
" 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"
21192130
" else:\n"
21202131
" current_search_location = str(Path(path).parent.absolute())\n"
21212132
" 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
24992510
py_loader_impl_main_module = argv[1];
25002511

25012512
/* 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+
*/
25052516
if (host == 0)
25062517
{
25072518
py_loader_impl_run_main = 0;
@@ -3658,7 +3669,7 @@ int py_loader_impl_discover_class(loader_impl impl, PyObject *py_class, klass c)
36583669
PyUnicode_AsUTF8(tuple_key),
36593670
args_count,
36603671
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 */
36623673
VISIBILITY_PUBLIC, /* TODO: check @property decorator for protected access? */
36633674
func_synchronicity,
36643675
NULL);
@@ -3725,7 +3736,7 @@ static int py_loader_impl_validate_object(loader_impl impl, PyObject *obj, objec
37253736
log_write("metacall", LOG_LEVEL_DEBUG, "Discover object member %s, type %s",
37263737
PyUnicode_AsUTF8(dict_key),
37273738
type_id_name(py_loader_impl_capi_to_value_type(dict_val)));
3728-
3739+
37293740
}
37303741
}
37313742

0 commit comments

Comments
 (0)