|
5 | 5 | # %% auto #0 |
6 | 6 | __all__ = ['working_directory', 'add_docs', 'docs', 'coll_repr', 'is_bool', 'mask2idxs', 'cycle', 'zip_cycle', 'is_indexer', |
7 | 7 | 'product', 'flatmap', 'CollBase', 'L', 'curryable', 'splitter', 'linesplitter', 'save_config_file', |
8 | | - 'read_config_file', 'Config'] |
| 8 | + 'read_config_file', 'find_file_parents', 'Config'] |
9 | 9 |
|
10 | 10 | # %% ../nbs/02_foundation.ipynb #0f974791 |
11 | 11 | from .imports import * |
@@ -624,6 +624,12 @@ def read_config_file(file, **kwargs): |
624 | 624 | config.read(file, encoding='utf8') |
625 | 625 | return config['DEFAULT'] |
626 | 626 |
|
| 627 | +# %% ../nbs/02_foundation.ipynb #95834369 |
| 628 | +def find_file_parents(fname, frompath=None): |
| 629 | + "Search `cfg_path` and its parents to find `cfg_name`" |
| 630 | + p = Path(frompath or Path.cwd()).expanduser().absolute() |
| 631 | + return first(o for o in [p, *p.parents] if (o/fname).exists()) |
| 632 | + |
627 | 633 | # %% ../nbs/02_foundation.ipynb #e06640e8 |
628 | 634 | class Config: |
629 | 635 | "Reading and writing `ConfigParser` ini files" |
@@ -663,6 +669,5 @@ def path(self,k,default=None): |
663 | 669 | @classmethod |
664 | 670 | def find(cls, cfg_name, cfg_path=None, **kwargs): |
665 | 671 | "Search `cfg_path` and its parents to find `cfg_name`" |
666 | | - p = Path(cfg_path or Path.cwd()).expanduser().absolute() |
667 | | - return first(cls(o, cfg_name, **kwargs) |
668 | | - for o in [p, *p.parents] if (o/cfg_name).exists()) |
| 672 | + p = find_file_parents(cfg_name, cfg_path) |
| 673 | + return cls(p, cfg_name, **kwargs) |
0 commit comments