Skip to content

Commit 7a1a576

Browse files
committed
fixes #747
1 parent c7f7d28 commit 7a1a576

File tree

2 files changed

+111
-44
lines changed

2 files changed

+111
-44
lines changed

fastcore/tools.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ def valid_path(path:str, must_exist:bool=True) -> Path:
5353
return p
5454

5555
# %% ../nbs/12_tools.ipynb
56-
def _fmt_path(f, p):
56+
def _fmt_path(f, p, skip_folders=()):
5757
'Format path with emoji for dirs/symlinks or size for files'
58-
if any(part.startswith('.') for part in f.relative_to(p).parts): return None
58+
parts = f.relative_to(p).parts
59+
if any(part.startswith('.') for part in parts): return None
60+
if any(part in skip_folders for part in parts): return None
5961
if f.is_symlink(): return f'{f} 🔗'
6062
if f.is_dir(): return f'{f} 📁'
6163
return f'{f} ({f.stat().st_size/1024:.1f}k)'
@@ -64,14 +66,15 @@ def _fmt_path(f, p):
6466
def view(
6567
path:str, # Path to directory or file to view
6668
view_range:tuple[int,int]=None, # Optional 1-indexed (start, end) line range for files, end=-1 for EOF. Do NOT use unless it's known that the file is too big to keep in context—simply view the WHOLE file when possible
67-
nums:bool=False # Whether to show line numbers
69+
nums:bool=False, # Whether to show line numbers
70+
skip_folders:tuple[str,...]=('_proc','__pycache__') # Folder names to skip when listing directories
6871
):
6972
'View directory or file contents with optional line range and numbers'
7073
try:
7174
p = valid_path(path)
7275
header = None
7376
if p.is_dir():
74-
lines = [s for f in p.glob('**/*') if (s := _fmt_path(f, p))]
77+
lines = [s for f in p.glob('**/*') if (s := _fmt_path(f, p, skip_folders))]
7578
header = f'Directory contents of {p}:'
7679
else: lines = p.read_text().splitlines()
7780
s, e = 1, len(lines)

0 commit comments

Comments
 (0)