Skip to content

Commit 20a47d4

Browse files
Merge branch 'caleb/fix/this' into philippe/pyTypeFactory-cleanup
2 parents e08f74b + 9ddda1a commit 20a47d4

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

python/pythonmonkey/require.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ def _createRequireInner(*args):
300300
module.paths.push(path + '/node_modules');
301301
module.require.path.push(python.pythonMonkey.dir + '/builtin_modules');
302302
module.require.path.push(python.pythonMonkey.nodeModules);
303+
304+
/* Add a .py loader, making it the first extension to be enumerated so py modules take precedence */
305+
const extCopy = Object.assign({}, module.require.extensions);
306+
for (let ext in module.require.extensions)
307+
delete module.require.extensions[ext];
303308
module.require.extensions['.py'] = loadPythonModule;
309+
Object.assign(module.require.extensions, extCopy);
304310
305311
if (isMain)
306312
{

tests/js/collide.simple

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @file collide.simple
3+
* Test to ensure require module identitifier collision that resolves both py and js
4+
* modules correctly prefers py modules.
5+
* @author Wes Garland <[email protected]>
6+
* @date Mar 2024
7+
*/
8+
9+
const { which } = require('./modules/collide')
10+
const whichjs = require('./modules/collide.js').which;
11+
const whichpy = require('./modules/collide.py').which;
12+
13+
if (which !== 'python')
14+
throw new Error(`python module was not preferred, got ${which} instead`)
15+
16+
if (whichpy !== 'python')
17+
throw new Error(`python module was not explicitly loaded, got ${whichpy} instead`)
18+
19+
if (whichjs !== 'javascript')
20+
throw new Error(`javascript module was not explicitly loaded, got ${whichjs} instead`)

tests/js/modules/collide.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.which = "javascript"

tests/js/modules/collide.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports['which']="python"

0 commit comments

Comments
 (0)