Skip to content

Commit

Permalink
Fix issue with repeated files on Windows
Browse files Browse the repository at this point in the history
As we now find files using a glob for each individual file extension,
case insensitive filesystems will find the same file for both
extensions that only differ by case.

An alternative fix for this might be to squash all the extensions into
a single glob pattern and run that in each directory
  • Loading branch information
ZedThree committed Oct 17, 2023
1 parent ffaa522 commit b0ad5e4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ford/fortran_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import os
import toposort
from itertools import chain, product
from typing import List, Optional, Union, Dict
from typing import List, Optional, Union, Dict, Set
from pathlib import Path
from fnmatch import fnmatch

Expand Down Expand Up @@ -84,7 +84,7 @@
}


def find_all_files(settings: ProjectSettings) -> List[Path]:
def find_all_files(settings: ProjectSettings) -> Set[Path]:
"""Returns a list of all selected files below a set of directories"""

file_extensions = chain(
Expand All @@ -94,16 +94,16 @@ def find_all_files(settings: ProjectSettings) -> List[Path]:
)

# Get initial list of all files in all source directories
src_files: List[Path] = []
src_files: Set[Path] = set()

for src_dir, extension in product(settings.src_dir, file_extensions):
src_files.extend(Path(src_dir).glob(f"**/*.{extension}"))
src_files.update(Path(src_dir).glob(f"**/*.{extension}"))

# Remove files under excluded directories
for exclude_dir in settings.exclude_dir:
src_files = [
src_files = {
src for src in src_files if not fnmatch(str(src), f"{exclude_dir}/*")
]
}

bottom_level_dirs = [src_dir.name for src_dir in settings.src_dir]
# First, let's check if the files are relative paths or not
Expand All @@ -122,9 +122,9 @@ def find_all_files(settings: ProjectSettings) -> List[Path]:
settings.exclude[i] = glob_exclude

for exclude in settings.exclude:
src_files = [
src_files = {
src for src in src_files if not fnmatch(os.path.relpath(src), exclude)
]
}

return src_files

Expand Down

0 comments on commit b0ad5e4

Please sign in to comment.