diff --git a/fastcore/__init__.py b/fastcore/__init__.py index c77aefc0..96637309 100644 --- a/fastcore/__init__.py +++ b/fastcore/__init__.py @@ -1 +1 @@ -__version__ = "1.7.8" +__version__ = "1.7.9" diff --git a/fastcore/_modidx.py b/fastcore/_modidx.py index 3d86c296..13724d59 100644 --- a/fastcore/_modidx.py +++ b/fastcore/_modidx.py @@ -304,6 +304,7 @@ 'fastcore.foundation.Config.__repr__': ('foundation.html#config.__repr__', 'fastcore/foundation.py'), 'fastcore.foundation.Config.__setitem__': ( 'foundation.html#config.__setitem__', 'fastcore/foundation.py'), + 'fastcore.foundation.Config.find': ('foundation.html#config.find', 'fastcore/foundation.py'), 'fastcore.foundation.Config.get': ('foundation.html#config.get', 'fastcore/foundation.py'), 'fastcore.foundation.Config.path': ('foundation.html#config.path', 'fastcore/foundation.py'), 'fastcore.foundation.Config.save': ('foundation.html#config.save', 'fastcore/foundation.py'), diff --git a/fastcore/foundation.py b/fastcore/foundation.py index 3c220ac0..62ab99dc 100644 --- a/fastcore/foundation.py +++ b/fastcore/foundation.py @@ -286,3 +286,10 @@ def get(self,k,default=None): def path(self,k,default=None): v = self.get(k, default) return v if v is None else self.config_path/v + + @classmethod + def find(cls, cfg_name, cfg_path=None, **kwargs): + "Search `cfg_path` and its parents to find `cfg_name`" + p = Path(cfg_path or Path.cwd()).expanduser().absolute() + return first(cls(o, cfg_name, **kwargs) + for o in [p, *p.parents] if (o/cfg_name).exists()) diff --git a/nbs/02_foundation.ipynb b/nbs/02_foundation.ipynb index 457c83cb..2a6baa0c 100644 --- a/nbs/02_foundation.ipynb +++ b/nbs/02_foundation.ipynb @@ -264,7 +264,7 @@ "\n", "> is_iter (o)\n", "\n", - "Test whether `o` can be used in a `for` loop" + "*Test whether `o` can be used in a `for` loop*" ], "text/plain": [ "---\n", @@ -273,7 +273,7 @@ "\n", "> is_iter (o)\n", "\n", - "Test whether `o` can be used in a `for` loop" + "*Test whether `o` can be used in a `for` loop*" ] }, "execution_count": null, @@ -1031,24 +1031,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L112){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L114){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.__getitem__\n", "\n", "> L.__getitem__ (idx)\n", "\n", - "Retrieve `idx` (can be list of indices, or mask, or int) items" + "*Retrieve `idx` (can be list of indices, or mask, or int) items*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L112){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L114){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.__getitem__\n", "\n", "> L.__getitem__ (idx)\n", "\n", - "Retrieve `idx` (can be list of indices, or mask, or int) items" + "*Retrieve `idx` (can be list of indices, or mask, or int) items*" ] }, "execution_count": null, @@ -1084,24 +1084,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L122){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L124){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.__setitem__\n", "\n", "> L.__setitem__ (idx, o)\n", "\n", - "Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)" + "*Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L122){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L124){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.__setitem__\n", "\n", "> L.__setitem__ (idx, o)\n", "\n", - "Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)" + "*Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)*" ] }, "execution_count": null, @@ -1135,24 +1135,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L166){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L169){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.unique\n", "\n", "> L.unique (sort=False, bidir=False, start=None)\n", "\n", - "Unique items, in stable order" + "*Unique items, in stable order*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L166){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L169){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.unique\n", "\n", "> L.unique (sort=False, bidir=False, start=None)\n", "\n", - "Unique items, in stable order" + "*Unique items, in stable order*" ] }, "execution_count": null, @@ -1183,24 +1183,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L167){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L170){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.val2idx\n", "\n", "> L.val2idx ()\n", "\n", - "Dict from value to index" + "*Dict from value to index*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L167){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L170){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.val2idx\n", "\n", "> L.val2idx ()\n", "\n", - "Dict from value to index" + "*Dict from value to index*" ] }, "execution_count": null, @@ -1231,24 +1231,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L161){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L164){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.filter\n", "\n", - "> L.filter (f=, negate=False, gen=False, **kwargs)\n", + "> L.filter (f=, negate=False, **kwargs)\n", "\n", - "Create new `L` filtered by predicate `f`, passing `args` and `kwargs` to `f`" + "*Create new `L` filtered by predicate `f`, passing `args` and `kwargs` to `f`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L161){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L164){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.filter\n", "\n", - "> L.filter (f=, negate=False, gen=False, **kwargs)\n", + "> L.filter (f=, negate=False, **kwargs)\n", "\n", - "Create new `L` filtered by predicate `f`, passing `args` and `kwargs` to `f`" + "*Create new `L` filtered by predicate `f`, passing `args` and `kwargs` to `f`*" ] }, "execution_count": null, @@ -1300,24 +1300,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L157){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L160){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.argwhere\n", "\n", "> L.argwhere (f, negate=False, **kwargs)\n", "\n", - "Like `filter`, but return indices for matching items" + "*Like `filter`, but return indices for matching items*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L157){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L160){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.argwhere\n", "\n", "> L.argwhere (f, negate=False, **kwargs)\n", "\n", - "Like `filter`, but return indices for matching items" + "*Like `filter`, but return indices for matching items*" ] }, "execution_count": null, @@ -1348,24 +1348,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L158){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L161){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.argfirst\n", "\n", "> L.argfirst (f, negate=False)\n", "\n", - "Return index of first matching item" + "*Return index of first matching item*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L158){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L161){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.argfirst\n", "\n", "> L.argfirst (f, negate=False)\n", "\n", - "Return index of first matching item" + "*Return index of first matching item*" ] }, "execution_count": null, @@ -1397,24 +1397,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L156){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L159){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map\n", "\n", - "> L.map (f, *args, gen=False, **kwargs)\n", + "> L.map (f, *args, **kwargs)\n", "\n", - "Create new `L` with `f` applied to all `items`, passing `args` and `kwargs` to `f`" + "*Create new `L` with `f` applied to all `items`, passing `args` and `kwargs` to `f`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L156){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L159){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map\n", "\n", - "> L.map (f, *args, gen=False, **kwargs)\n", + "> L.map (f, *args, **kwargs)\n", "\n", - "Create new `L` with `f` applied to all `items`, passing `args` and `kwargs` to `f`" + "*Create new `L` with `f` applied to all `items`, passing `args` and `kwargs` to `f`*" ] }, "execution_count": null, @@ -1494,24 +1494,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L169){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L172){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_dict\n", "\n", - "> L.map_dict (f=, *args, gen=False, **kwargs)\n", + "> L.map_dict (f=, *args, **kwargs)\n", "\n", - "Like `map`, but creates a dict from `items` to function results" + "*Like `map`, but creates a dict from `items` to function results*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L169){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L172){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_dict\n", "\n", - "> L.map_dict (f=, *args, gen=False, **kwargs)\n", + "> L.map_dict (f=, *args, **kwargs)\n", "\n", - "Like `map`, but creates a dict from `items` to function results" + "*Like `map`, but creates a dict from `items` to function results*" ] }, "execution_count": null, @@ -1543,24 +1543,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L181){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L184){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.zip\n", "\n", "> L.zip (cycled=False)\n", "\n", - "Create new `L` with `zip(*items)`" + "*Create new `L` with `zip(*items)`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L181){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L184){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.zip\n", "\n", "> L.zip (cycled=False)\n", "\n", - "Create new `L` with `zip(*items)`" + "*Create new `L` with `zip(*items)`*" ] }, "execution_count": null, @@ -1603,24 +1603,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L183){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L186){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_zip\n", "\n", "> L.map_zip (f, *args, cycled=False, **kwargs)\n", "\n", - "Combine `zip` and `starmap`" + "*Combine `zip` and `starmap`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L183){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L186){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_zip\n", "\n", "> L.map_zip (f, *args, cycled=False, **kwargs)\n", "\n", - "Combine `zip` and `starmap`" + "*Combine `zip` and `starmap`*" ] }, "execution_count": null, @@ -1652,24 +1652,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L182){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L185){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.zipwith\n", "\n", "> L.zipwith (*rest, cycled=False)\n", "\n", - "Create new `L` with `self` zip with each of `*rest`" + "*Create new `L` with `self` zip with each of `*rest`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L182){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L185){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.zipwith\n", "\n", "> L.zipwith (*rest, cycled=False)\n", "\n", - "Create new `L` with `self` zip with each of `*rest`" + "*Create new `L` with `self` zip with each of `*rest`*" ] }, "execution_count": null, @@ -1702,24 +1702,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L184){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L187){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_zipwith\n", "\n", "> L.map_zipwith (f, *rest, cycled=False, **kwargs)\n", "\n", - "Combine `zipwith` and `starmap`" + "*Combine `zipwith` and `starmap`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L184){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L187){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_zipwith\n", "\n", "> L.map_zipwith (f, *rest, cycled=False, **kwargs)\n", "\n", - "Combine `zipwith` and `starmap`" + "*Combine `zipwith` and `starmap`*" ] }, "execution_count": null, @@ -1750,24 +1750,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L173){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L176){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.itemgot\n", "\n", "> L.itemgot (*idxs)\n", "\n", - "Create new `L` with item `idx` of all `items`" + "*Create new `L` with item `idx` of all `items`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L173){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L176){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.itemgot\n", "\n", "> L.itemgot (*idxs)\n", "\n", - "Create new `L` with item `idx` of all `items`" + "*Create new `L` with item `idx` of all `items`*" ] }, "execution_count": null, @@ -1798,24 +1798,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L177){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L180){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.attrgot\n", "\n", "> L.attrgot (k, default=None)\n", "\n", - "Create new `L` with attr `k` (or value `k` for dicts) of all `items`." + "*Create new `L` with attr `k` (or value `k` for dicts) of all `items`.*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L177){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L180){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.attrgot\n", "\n", "> L.attrgot (k, default=None)\n", "\n", - "Create new `L` with attr `k` (or value `k` for dicts) of all `items`." + "*Create new `L` with attr `k` (or value `k` for dicts) of all `items`.*" ] }, "execution_count": null, @@ -1852,24 +1852,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L136){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L139){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.sorted\n", "\n", "> L.sorted (key=None, reverse=False)\n", "\n", - "New `L` sorted by `key`. If key is str use `attrgetter`; if int use `itemgetter`" + "*New `L` sorted by `key`. If key is str use `attrgetter`; if int use `itemgetter`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L136){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L139){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.sorted\n", "\n", "> L.sorted (key=None, reverse=False)\n", "\n", - "New `L` sorted by `key`. If key is str use `attrgetter`; if int use `itemgetter`" + "*New `L` sorted by `key`. If key is str use `attrgetter`; if int use `itemgetter`*" ] }, "execution_count": null, @@ -1900,24 +1900,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L152){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L155){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.split\n", "\n", "> L.split (s, sep=None, maxsplit=-1)\n", "\n", - "Class Method: Same as `str.split`, but returns an `L`" + "*Class Method: Same as `str.split`, but returns an `L`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L152){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L155){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.split\n", "\n", "> L.split (s, sep=None, maxsplit=-1)\n", "\n", - "Class Method: Same as `str.split`, but returns an `L`" + "*Class Method: Same as `str.split`, but returns an `L`*" ] }, "execution_count": null, @@ -1948,24 +1948,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L154){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L157){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.range\n", "\n", "> L.range (a, b=None, step=None)\n", "\n", - "Class Method: Same as `range`, but returns `L`. Can pass collection for `a`, to use `len(a)`" + "*Class Method: Same as `range`, but returns `L`. Can pass collection for `a`, to use `len(a)`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L154){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L157){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.range\n", "\n", "> L.range (a, b=None, step=None)\n", "\n", - "Class Method: Same as `range`, but returns `L`. Can pass collection for `a`, to use `len(a)`" + "*Class Method: Same as `range`, but returns `L`. Can pass collection for `a`, to use `len(a)`*" ] }, "execution_count": null, @@ -1997,24 +1997,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L190){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L193){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.concat\n", "\n", "> L.concat ()\n", "\n", - "Concatenate all elements of list" + "*Concatenate all elements of list*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L190){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L193){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.concat\n", "\n", "> L.concat ()\n", "\n", - "Concatenate all elements of list" + "*Concatenate all elements of list*" ] }, "execution_count": null, @@ -2045,24 +2045,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L113){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L115){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.copy\n", "\n", "> L.copy ()\n", "\n", - "Same as `list.copy`, but returns an `L`" + "*Same as `list.copy`, but returns an `L`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L113){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L115){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.copy\n", "\n", "> L.copy ()\n", "\n", - "Same as `list.copy`, but returns an `L`" + "*Same as `list.copy`, but returns an `L`*" ] }, "execution_count": null, @@ -2094,24 +2094,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L170){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L173){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_first\n", "\n", "> L.map_first (f=, g=, *args, **kwargs)\n", "\n", - "First element of `map_filter`" + "*First element of `map_filter`*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L170){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L173){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.map_first\n", "\n", "> L.map_first (f=, g=, *args, **kwargs)\n", "\n", - "First element of `map_filter`" + "*First element of `map_filter`*" ] }, "execution_count": null, @@ -2143,24 +2143,24 @@ "text/markdown": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L194){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L197){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.setattrs\n", "\n", "> L.setattrs (attr, val)\n", "\n", - "Call `setattr` on all items" + "*Call `setattr` on all items*" ], "text/plain": [ "---\n", "\n", - "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L194){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L197){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### L.setattrs\n", "\n", "> L.setattrs (attr, val)\n", "\n", - "Call `setattr` on all items" + "*Call `setattr` on all items*" ] }, "execution_count": null, @@ -2293,7 +2293,14 @@ "\n", " def path(self,k,default=None):\n", " v = self.get(k, default)\n", - " return v if v is None else self.config_path/v" + " return v if v is None else self.config_path/v\n", + "\n", + " @classmethod\n", + " def find(cls, cfg_name, cfg_path=None, **kwargs):\n", + " \"Search `cfg_path` and its parents to find `cfg_name`\"\n", + " p = Path(cfg_path or Path.cwd()).expanduser().absolute()\n", + " return first(cls(o, cfg_name, **kwargs)\n", + " for o in [p, *p.parents] if (o/cfg_name).exists())" ] }, { @@ -2375,6 +2382,41 @@ "assert not Path('../tmp.ini').exists()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L277){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "\n", + "### Config.get\n", + "\n", + "> Config.get (k, default=None)" + ], + "text/plain": [ + "---\n", + "\n", + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/foundation.py#L277){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", + "\n", + "### Config.get\n", + "\n", + "> Config.get (k, default=None)" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "show_doc(Config.get)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -2434,6 +2476,68 @@ "test_eq(cfg.get('some_num'), 3)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Config.find\n", + "\n", + "> Config.find (cfg_name, cfg_path=None, **kwargs)\n", + "\n", + "*Search `cfg_path` and its parents to find `cfg_name`*" + ], + "text/plain": [ + "---\n", + "\n", + "### Config.find\n", + "\n", + "> Config.find (cfg_name, cfg_path=None, **kwargs)\n", + "\n", + "*Search `cfg_path` and its parents to find `cfg_name`*" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "show_doc(Config.find)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can use `Config.find` to search subdirectories for a config file, starting in the current path if no path is specified:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'fastcore'" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Config.find('settings.ini').repo" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/nbs/11_xml.ipynb b/nbs/11_xml.ipynb index bc88403c..c16dd713 100644 --- a/nbs/11_xml.ipynb +++ b/nbs/11_xml.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "8a46bf54", "metadata": {}, "outputs": [], @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "f6c9a7f5", "metadata": {}, "outputs": [], @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "42d18e5c", "metadata": {}, "outputs": [], @@ -61,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "159d3560", "metadata": {}, "outputs": [], @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "6f000a63", "metadata": {}, "outputs": [], @@ -92,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "ddc7d705", "metadata": {}, "outputs": [], @@ -109,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "df5d12c7", "metadata": {}, "outputs": [], @@ -123,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "b06c10f6", "metadata": {}, "outputs": [], @@ -164,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "06718948", "metadata": {}, "outputs": [], @@ -177,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "45489975", "metadata": {}, "outputs": [], @@ -200,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "306844ba", "metadata": {}, "outputs": [ @@ -210,7 +210,7 @@ "body((div(('hi',),{'a': 1, 'b': True, 'class': None}), p(('hi',),{'class': 'a 1', 'style': 'a:1; b:2'})),{})" ] }, - "execution_count": 11, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -222,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "500f358a", "metadata": {}, "outputs": [ @@ -232,7 +232,7 @@ "body((div(('hi',),{'a': 1, 'b': True, 'class': None}), p(('hi',),{'class': 'a 1', 'style': 'a:1; b:2'}), p(('a',),{}), p(('b',),{})),{})" ] }, - "execution_count": 12, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -253,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "39834fcb", "metadata": {}, "outputs": [], @@ -268,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "9a8b4ddb", "metadata": {}, "outputs": [ @@ -293,7 +293,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "5c6c57e9", "metadata": {}, "outputs": [ @@ -324,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "5c7f175d", "metadata": {}, "outputs": [ @@ -341,7 +341,7 @@ "p(('Some text',),{'id': 'newid'})" ] }, - "execution_count": 16, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -354,7 +354,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "116c886e", "metadata": {}, "outputs": [], @@ -374,7 +374,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "id": "254c8ff3", "metadata": {}, "outputs": [], @@ -386,7 +386,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "0255b96f", "metadata": {}, "outputs": [], @@ -408,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "id": "ea224c94", "metadata": {}, "outputs": [], @@ -427,7 +427,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "id": "a1ed9c01", "metadata": {}, "outputs": [], @@ -474,7 +474,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "id": "dd054392", "metadata": {}, "outputs": [], @@ -489,7 +489,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "id": "c2a921a2", "metadata": {}, "outputs": [], @@ -513,7 +513,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "id": "eef16b38", "metadata": {}, "outputs": [], @@ -537,7 +537,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "id": "d3d23c48", "metadata": {}, "outputs": [ @@ -567,7 +567,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "id": "85a16341", "metadata": {}, "outputs": [], @@ -591,7 +591,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "id": "61d63a79", "metadata": {}, "outputs": [ @@ -615,7 +615,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "id": "51e58821", "metadata": {}, "outputs": [ @@ -643,7 +643,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "id": "798ae1d2", "metadata": {}, "outputs": [ @@ -776,7 +776,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "id": "ad32b076", "metadata": {}, "outputs": [], @@ -796,21 +796,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "python3", "language": "python", "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.8" } }, "nbformat": 4, diff --git a/settings.ini b/settings.ini index dbf46a3d..9c203dca 100644 --- a/settings.ini +++ b/settings.ini @@ -8,7 +8,7 @@ author = Jeremy Howard and Sylvain Gugger author_email = infos@fast.ai copyright = fast.ai branch = master -version = 1.7.8 +version = 1.7.9 min_python = 3.8 audience = Developers language = English