Skip to content

Commit 9638aaa

Browse files
committed
fix(require.py): properly handle Windows paths
1 parent 255c971 commit 9638aaa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/pythonmonkey/require.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def statSync_inner(filename: str) -> Union[Dict[str, int], bool]:
154154
Union[Dict[str, int], False]: The mode of the file or False if the file doesn't exist.
155155
"""
156156
from os import stat
157+
filename = os.path.normpath(filename)
157158
if (os.path.exists(filename)):
158159
sb = stat(filename)
159160
return { 'mode': sb.st_mode }
@@ -166,12 +167,17 @@ def readFileSync(filename, charset) -> str:
166167
Returns:
167168
str: The contents of the file
168169
"""
170+
filename = os.path.normpath(filename)
169171
with open(filename, "r", encoding=charset) as fileHnd:
170172
return fileHnd.read()
171173

174+
def existsSync(filename: str) -> bool:
175+
filename = os.path.normpath(filename)
176+
return os.path.exists(filename)
177+
172178
bootstrap.modules.fs.statSync_inner = statSync_inner
173179
bootstrap.modules.fs.readFileSync = readFileSync
174-
bootstrap.modules.fs.existsSync = os.path.exists
180+
bootstrap.modules.fs.existsSync = existsSync
175181

176182
# Read ctx-module module from disk and invoke so that this file is the "main module" and ctx-module has
177183
# require and exports symbols injected from the bootstrap object above. Current PythonMonkey bugs
@@ -201,6 +207,7 @@ def load(filename: str) -> Dict:
201207
: The loaded python module
202208
"""
203209

210+
filename = os.path.normpath(filename)
204211
name = os.path.basename(filename)
205212
if name not in sys.modules:
206213
sourceFileLoader = machinery.SourceFileLoader(name, filename)

0 commit comments

Comments
 (0)