Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fastcore/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"save_config_file": "02_foundation.ipynb",
"read_config_file": "02_foundation.ipynb",
"Config": "02_foundation.ipynb",
"working_dir": "03_xtras.ipynb",
"walk": "03_xtras.ipynb",
"globtastic": "03_xtras.ipynb",
"maybe_open": "03_xtras.ipynb",
Expand Down
22 changes: 16 additions & 6 deletions fastcore/xtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from __future__ import annotations


__all__ = ['walk', 'globtastic', 'maybe_open', 'image_size', 'bunzip', 'loads', 'loads_multi', 'dumps', 'untar_dir',
'repo_details', 'run', 'open_file', 'save_pickle', 'load_pickle', 'dict2obj', 'obj2dict', 'repr_dict',
'is_listy', 'mapped', 'IterLen', 'ReindexCollection', 'get_source_link', 'truncstr', 'spark_chars',
'sparkline', 'modify_exception', 'round_multiple', 'str2bool', 'set_num_threads', 'join_path_file',
'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format', 'utc2local', 'local2utc',
'trace', 'modified_env', 'ContextManagers', 'shufflish']
__all__ = ['working_dir', 'walk', 'globtastic', 'maybe_open', 'image_size', 'bunzip', 'loads', 'loads_multi', 'dumps',
'untar_dir', 'repo_details', 'run', 'open_file', 'save_pickle', 'load_pickle', 'dict2obj', 'obj2dict',
'repr_dict', 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', 'get_source_link', 'truncstr',
'spark_chars', 'sparkline', 'modify_exception', 'round_multiple', 'str2bool', 'set_num_threads',
'join_path_file', 'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format',
'utc2local', 'local2utc', 'trace', 'modified_env', 'ContextManagers', 'shufflish']

# Cell
#nbdev_comment from __future__ import annotations
Expand All @@ -24,6 +24,16 @@
from contextlib import contextmanager,ExitStack
from datetime import datetime, timezone

# Cell
@contextmanager
def working_dir(path:Path|str, # path to temporarily change the working directory to
):
"Changes working directory and returns to previous on exit."
prev_cwd = Path.cwd()
os.chdir(path)
try: yield
finally: os.chdir(prev_cwd)

# Cell
def walk(
path:Path|str, # path to start searching
Expand Down
Loading