Skip to content

Commit

Permalink
restrict wsi_dir.glob to files (#190)
Browse files Browse the repository at this point in the history
* restrict wsi_dir.glob to files

fixes #189

* use iterdir and is_file to glob files

---------

Co-authored-by: Jakub Kaczmarzyk <jakub.kaczmarzyk@gmail.com>
  • Loading branch information
xalexalex and kaczmarj authored Sep 19, 2023
1 parent 123d7c1 commit 59c0f5c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion wsinfer/cli/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def run(
# different directory, both directories need to be bind mounted onto the container.
# If only the symlinked directory is included, then the patching script will fail,
# even though it looks like there are files in the wsi_dir directory.
files_in_wsi_dir = [p for p in wsi_dir.glob("*") if p.exists()]
files_in_wsi_dir = [p for p in wsi_dir.iterdir() if p.is_file()]
if not files_in_wsi_dir:
raise FileNotFoundError(f"no files exist in the slide directory: {wsi_dir}")

Expand Down
2 changes: 1 addition & 1 deletion wsinfer/modellib/run_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run_inference(
wsi_dir = Path(wsi_dir)
if not wsi_dir.exists():
raise errors.WholeSlideImageDirectoryNotFound(f"directory not found: {wsi_dir}")
wsi_paths = list(wsi_dir.glob("*"))
wsi_paths = [p for p in wsi_dir.iterdir() if p.is_file()]
if not wsi_paths:
raise errors.WholeSlideImagesNotFound(wsi_dir)
results_dir = Path(results_dir)
Expand Down
2 changes: 1 addition & 1 deletion wsinfer/patchlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def segment_and_patch_directory_of_slides(

_validate_wsi_directory(wsi_dir)

slide_paths = sorted(wsi_dir.glob("*"))
slide_paths = sorted([p for p in wsi_dir.iterdir() if p.is_file()])

# NOTE: we could use multi-processing here but then the logs would get
# discombobulated.
Expand Down
2 changes: 1 addition & 1 deletion wsinfer/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get_avg_mpp(slide_path: Path | str) -> float:
def _validate_wsi_directory(wsi_dir: str | Path) -> None:
"""Validate a directory of whole slide images."""
wsi_dir = Path(wsi_dir)
maybe_slides = sorted(wsi_dir.glob("*"))
maybe_slides = [p for p in wsi_dir.iterdir() if p.is_file()]
uniq_stems = set(p.stem for p in maybe_slides)
if len(uniq_stems) != len(maybe_slides):
raise DuplicateFilePrefixesFound(
Expand Down

0 comments on commit 59c0f5c

Please sign in to comment.