File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -439,8 +439,15 @@ def _handle_pth_file(path: Path) -> list[_SP]:
439
439
# No item is added to sys.path more than once.
440
440
# Blank lines and lines beginning with # are skipped.
441
441
# Lines starting with import (followed by space or tab) are executed.
442
- directories = []
443
- for line in path .read_text (encoding = "utf8" ).strip ().replace (";" , "\n " ).splitlines (keepends = False ):
442
+ directories : list [_SP ] = []
443
+ try :
444
+ # It turns out PyTorch recommends its users to use `.pth` as the extension
445
+ # when saving models on the disk. These model files are not encoded in UTF8.
446
+ # If UTF8 decoding fails, we skip the .pth file.
447
+ text = path .read_text (encoding = "utf8" )
448
+ except UnicodeDecodeError :
449
+ return directories
450
+ for line in text .strip ().replace (";" , "\n " ).splitlines (keepends = False ):
444
451
line = line .strip () # noqa: PLW2901
445
452
if _re_import_line .match (line ):
446
453
editable_module = path .parent / f"{ line [len ('import' ):].lstrip ()} .py"
You can’t perform that action at this time.
0 commit comments