Skip to content

Commit dc9de54

Browse files
authored
Merge pull request #1011 from mikedep333/improve-scan-symlink-dirs
refactor(sources): use EAFP pattern instead of is_file() check
2 parents cd32d2e + 400d3bd commit dc9de54

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/fromager/sources.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,10 +867,11 @@ def scan_compiled_extensions(
867867
elif suffix not in ignore_suffixes:
868868
# Path.walk() lists symlinks to directories as filenames
869869
# rather than dirnames, causing IsADirectoryError on open().
870-
if not filepath.is_file():
870+
try:
871+
with filepath.open("rb") as f:
872+
header = f.read(_MAGIC_HEADERS_READ)
873+
except IsADirectoryError:
871874
continue
872-
with filepath.open("rb") as f:
873-
header = f.read(_MAGIC_HEADERS_READ)
874875
if header.startswith(magic_headers):
875876
relpath = filepath.relative_to(root_dir)
876877
logger.debug(

0 commit comments

Comments
 (0)