Skip to content

Commit 285d3c3

Browse files
committed
fixes #151
1 parent fe16b3b commit 285d3c3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

fastcore/_nbdev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"patch_to": "02_foundation.ipynb",
102102
"patch": "02_foundation.ipynb",
103103
"patch_property": "02_foundation.ipynb",
104+
"working_directory": "02_foundation.ipynb",
104105
"add_docs": "02_foundation.ipynb",
105106
"docs": "02_foundation.ipynb",
106107
"custom_dir": "02_foundation.ipynb",

fastcore/foundation.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/02_foundation.ipynb (unless otherwise specified).
22

3-
__all__ = ['copy_func', 'patch_to', 'patch', 'patch_property', 'add_docs', 'docs', 'custom_dir', 'coll_repr', 'is_bool',
4-
'mask2idxs', 'cycle', 'zip_cycle', 'is_indexer', 'GetAttr', 'delegate_attr', 'CollBase', 'L',
5-
'save_config_file', 'read_config_file', 'Config']
3+
__all__ = ['copy_func', 'patch_to', 'patch', 'patch_property', 'working_directory', 'add_docs', 'docs', 'custom_dir',
4+
'coll_repr', 'is_bool', 'mask2idxs', 'cycle', 'zip_cycle', 'is_indexer', 'GetAttr', 'delegate_attr',
5+
'CollBase', 'L', 'save_config_file', 'read_config_file', 'Config']
66

77
# Cell
88
from .imports import *
@@ -53,6 +53,15 @@ def patch_property(f):
5353
cls = next(iter(f.__annotations__.values()))
5454
return patch_to(cls, as_prop=True)(f)
5555

56+
# Cell
57+
@contextmanager
58+
def working_directory(path):
59+
"Change working directory to `path` and return to previous on exit."
60+
prev_cwd = Path.cwd()
61+
os.chdir(path)
62+
try: yield
63+
finally: os.chdir(prev_cwd)
64+
5665
# Cell
5766
def add_docs(cls, cls_doc=None, **docs):
5867
"Copy values from `docs` to `cls` docstrings, and confirm all public methods are documented"

0 commit comments

Comments
 (0)