@@ -247,17 +247,17 @@ def _get_main_module_details(error=ImportError):
247
247
sys .modules [main_name ] = saved_main
248
248
249
249
250
- def _get_code_from_file (run_name , fname ):
250
+ def _get_code_from_file (fname ):
251
251
# Check for a compiled file first
252
252
from pkgutil import read_code
253
- decoded_path = os .path .abspath (os . fsdecode ( fname ) )
254
- with io .open_code (decoded_path ) as f :
253
+ code_path = os .path .abspath (fname )
254
+ with io .open_code (code_path ) as f :
255
255
code = read_code (f )
256
256
if code is None :
257
257
# That didn't work, so try it as normal source code
258
- with io .open_code (decoded_path ) as f :
258
+ with io .open_code (code_path ) as f :
259
259
code = compile (f .read (), fname , 'exec' )
260
- return code , fname
260
+ return code
261
261
262
262
def run_path (path_name , init_globals = None , run_name = None ):
263
263
"""Execute code located at the specified filesystem location.
@@ -279,12 +279,13 @@ def run_path(path_name, init_globals=None, run_name=None):
279
279
pkg_name = run_name .rpartition ("." )[0 ]
280
280
from pkgutil import get_importer
281
281
importer = get_importer (path_name )
282
+ path_name = os .fsdecode (path_name )
282
283
if isinstance (importer , type (None )):
283
284
# Not a valid sys.path entry, so run the code directly
284
285
# execfile() doesn't help as we want to allow compiled files
285
- code , fname = _get_code_from_file (run_name , path_name )
286
+ code = _get_code_from_file (path_name )
286
287
return _run_module_code (code , init_globals , run_name ,
287
- pkg_name = pkg_name , script_name = fname )
288
+ pkg_name = pkg_name , script_name = path_name )
288
289
else :
289
290
# Finder is defined for path, so add it to
290
291
# the start of sys.path
0 commit comments