From 750768f4597aba35d3651b354c01b27eea4bbd80 Mon Sep 17 00:00:00 2001 From: Jeremy Howard Date: Sun, 28 Jul 2024 08:14:04 +1000 Subject: [PATCH] fixes #586 --- CHANGELOG.md | 2 +- fastcore/__init__.py | 2 +- fastcore/_modidx.py | 20 ++++++++++---------- fastcore/xml.py | 29 +++++++++++++++-------------- nbs/11_xml.ipynb | 29 +++++++++++++++-------------- settings.ini | 6 +++--- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ecdb1b..c4fddc3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,7 +143,7 @@ ### New Features - Add `process` param to `threaded` ([#550](https://github.com/fastai/fastcore/issues/550)) -- Check for `__xt__` in `to_xml` +- Check for `__ft__` in `to_xml` ## 1.5.34 diff --git a/fastcore/__init__.py b/fastcore/__init__.py index 114fc669..e4adfb83 100644 --- a/fastcore/__init__.py +++ b/fastcore/__init__.py @@ -1 +1 @@ -__version__ = "1.5.56" +__version__ = "1.6.0" diff --git a/fastcore/_modidx.py b/fastcore/_modidx.py index dade2481..33331b3b 100644 --- a/fastcore/_modidx.py +++ b/fastcore/_modidx.py @@ -560,22 +560,22 @@ 'fastcore.xdg.xdg_data_home': ('xdg.html#xdg_data_home', 'fastcore/xdg.py'), 'fastcore.xdg.xdg_runtime_dir': ('xdg.html#xdg_runtime_dir', 'fastcore/xdg.py'), 'fastcore.xdg.xdg_state_home': ('xdg.html#xdg_state_home', 'fastcore/xdg.py')}, - 'fastcore.xml': { 'fastcore.xml.Html': ('xml.html#html', 'fastcore/xml.py'), - 'fastcore.xml.XT': ('xml.html#xt', 'fastcore/xml.py'), - 'fastcore.xml.XT.__getattr__': ('xml.html#xt.__getattr__', 'fastcore/xml.py'), - 'fastcore.xml.XT.__init__': ('xml.html#xt.__init__', 'fastcore/xml.py'), - 'fastcore.xml.XT.__setattr__': ('xml.html#xt.__setattr__', 'fastcore/xml.py'), - 'fastcore.xml.XT.attrs': ('xml.html#xt.attrs', 'fastcore/xml.py'), - 'fastcore.xml.XT.children': ('xml.html#xt.children', 'fastcore/xml.py'), - 'fastcore.xml.XT.tag': ('xml.html#xt.tag', 'fastcore/xml.py'), + 'fastcore.xml': { 'fastcore.xml.FT': ('xml.html#ft', 'fastcore/xml.py'), + 'fastcore.xml.FT.__getattr__': ('xml.html#ft.__getattr__', 'fastcore/xml.py'), + 'fastcore.xml.FT.__init__': ('xml.html#ft.__init__', 'fastcore/xml.py'), + 'fastcore.xml.FT.__setattr__': ('xml.html#ft.__setattr__', 'fastcore/xml.py'), + 'fastcore.xml.FT.attrs': ('xml.html#ft.attrs', 'fastcore/xml.py'), + 'fastcore.xml.FT.children': ('xml.html#ft.children', 'fastcore/xml.py'), + 'fastcore.xml.FT.tag': ('xml.html#ft.tag', 'fastcore/xml.py'), + 'fastcore.xml.Html': ('xml.html#html', 'fastcore/xml.py'), 'fastcore.xml.__getattr__': ('xml.html#__getattr__', 'fastcore/xml.py'), 'fastcore.xml._attrmap': ('xml.html#_attrmap', 'fastcore/xml.py'), 'fastcore.xml._escape': ('xml.html#_escape', 'fastcore/xml.py'), 'fastcore.xml._to_attr': ('xml.html#_to_attr', 'fastcore/xml.py'), + 'fastcore.xml.ft': ('xml.html#ft', 'fastcore/xml.py'), 'fastcore.xml.highlight': ('xml.html#highlight', 'fastcore/xml.py'), 'fastcore.xml.showtags': ('xml.html#showtags', 'fastcore/xml.py'), - 'fastcore.xml.to_xml': ('xml.html#to_xml', 'fastcore/xml.py'), - 'fastcore.xml.xt': ('xml.html#xt', 'fastcore/xml.py')}, + 'fastcore.xml.to_xml': ('xml.html#to_xml', 'fastcore/xml.py')}, 'fastcore.xtras': { 'fastcore.xtras.ContextManagers': ('xtras.html#contextmanagers', 'fastcore/xtras.py'), 'fastcore.xtras.ContextManagers.__enter__': ('xtras.html#contextmanagers.__enter__', 'fastcore/xtras.py'), 'fastcore.xtras.ContextManagers.__exit__': ('xtras.html#contextmanagers.__exit__', 'fastcore/xtras.py'), diff --git a/fastcore/xml.py b/fastcore/xml.py index 328c0d1a..b39082c9 100644 --- a/fastcore/xml.py +++ b/fastcore/xml.py @@ -1,7 +1,7 @@ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/11_xml.ipynb. # %% auto 0 -__all__ = ['XT', 'xt', 'Html', 'to_xml', 'highlight', 'showtags', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code', +__all__ = ['FT', 'ft', 'Html', 'to_xml', 'highlight', 'showtags', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code', 'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B', 'I', 'U', 'S', 'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Nav', 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr', 'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea', 'Button', 'Select', 'Option', @@ -26,7 +26,8 @@ def _attrmap(o): return o.lstrip('_').replace('_', '-') # %% ../nbs/11_xml.ipynb -class XT(list): +class FT(list): + "A 'Fast Tag' structure, which is a `list` of `[tag,children,attrs]`" def __init__(self, tag, cs, attrs=None, void_=False, **kwargs): super().__init__([tag, cs, {**(attrs or {}), **kwargs}]) self.void_ = void_ @@ -47,11 +48,11 @@ def __getattr__(self, k): return self.attrs[k.lstrip('_').replace('_', '-')] # %% ../nbs/11_xml.ipynb -def xt(tag:str, *c, void_=False, **kw): - "Create an XML tag structure `[tag,children,attrs]` for `toxml()`" +def ft(tag:str, *c, void_=False, **kw): + "Create an `FT` structure for `to_xml()`" if len(c)==1 and isinstance(c[0], types.GeneratorType): c = tuple(c[0]) kw = {_attrmap(k):v for k,v in kw.items() if v is not None} - return XT(tag.lower(),c,kw, void_=void_) + return FT(tag.lower(),c,kw, void_=void_) # %% ../nbs/11_xml.ipynb _g = globals() @@ -65,14 +66,14 @@ def xt(tag:str, *c, void_=False, **kw): 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video', 'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot'] -for o in _all_: _g[o] = partial(xt, o.lower()) +for o in _all_: _g[o] = partial(ft, o.lower()) # %% ../nbs/11_xml.ipynb -def Html(*c, doctype=True, **kwargs)->XT: +def Html(*c, doctype=True, **kwargs)->FT: "An HTML tag, optionally preceeded by `!DOCTYPE HTML`" - res = xt('html', *c, **kwargs) + res = ft('html', *c, **kwargs) if not doctype: return res - return (xt('!DOCTYPE', html=True, void_=True), res) + return (ft('!DOCTYPE', html=True, void_=True), res) # %% ../nbs/11_xml.ipynb def _escape(s): return '' if s is None else escape(s) if isinstance(s, str) else s @@ -91,10 +92,10 @@ def _to_attr(k,v): # %% ../nbs/11_xml.ipynb def to_xml(elm, lvl=0): - "Convert `xt` element tree into an XML string" + "Convert `ft` element tree into an XML string" if elm is None: return '' if isinstance(elm, tuple): return '\n'.join(to_xml(o) for o in elm) - if hasattr(elm, '__xt__'): elm = elm.__xt__() + if hasattr(elm, '__ft__'): elm = elm.__ft__() sp = ' ' * lvl if not isinstance(elm, list): return f'{_escape(elm)}\n' @@ -107,7 +108,7 @@ def to_xml(elm, lvl=0): isvoid = getattr(elm, 'void_', False) cltag = '' if isvoid else f'' if not cs: return f'{sp}<{stag}>{cltag}\n' - if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__xt__'): + if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__ft__'): return f'{sp}<{stag}>{_escape(cs[0])}{cltag}\n' res = f'{sp}<{stag}>\n' res += ''.join(to_xml(c, lvl=lvl+2) for c in cs) @@ -125,10 +126,10 @@ def showtags(s): {escape(to_xml(s))} """ -XT._repr_markdown_ = highlight +FT._repr_markdown_ = highlight # %% ../nbs/11_xml.ipynb def __getattr__(tag): if tag.startswith('_') or tag[0].islower(): raise AttributeError - def _f(*c, target_id=None, **kwargs): return xt(tag, *c, target_id=target_id, **kwargs) + def _f(*c, target_id=None, **kwargs): return ft(tag, *c, target_id=target_id, **kwargs) return _f diff --git a/nbs/11_xml.ipynb b/nbs/11_xml.ipynb index a3ae9704..9f6474b6 100644 --- a/nbs/11_xml.ipynb +++ b/nbs/11_xml.ipynb @@ -71,7 +71,8 @@ "outputs": [], "source": [ "#|export\n", - "class XT(list):\n", + "class FT(list):\n", + " \"A 'Fast Tag' structure, which is a `list` of `[tag,children,attrs]`\"\n", " def __init__(self, tag, cs, attrs=None, void_=False, **kwargs):\n", " super().__init__([tag, cs, {**(attrs or {}), **kwargs}])\n", " self.void_ = void_\n", @@ -100,11 +101,11 @@ "outputs": [], "source": [ "#| export\n", - "def xt(tag:str, *c, void_=False, **kw):\n", - " \"Create an XML tag structure `[tag,children,attrs]` for `toxml()`\"\n", + "def ft(tag:str, *c, void_=False, **kw):\n", + " \"Create an `FT` structure for `to_xml()`\"\n", " if len(c)==1 and isinstance(c[0], types.GeneratorType): c = tuple(c[0])\n", " kw = {_attrmap(k):v for k,v in kw.items() if v is not None}\n", - " return XT(tag.lower(),c,kw, void_=void_)" + " return FT(tag.lower(),c,kw, void_=void_)" ] }, { @@ -126,7 +127,7 @@ " 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',\n", " 'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']\n", "\n", - "for o in _all_: _g[o] = partial(xt, o.lower())" + "for o in _all_: _g[o] = partial(ft, o.lower())" ] }, { @@ -134,7 +135,7 @@ "id": "732e44ab", "metadata": {}, "source": [ - "The main HTML tags are exported as `xt` partials.\n", + "The main HTML tags are exported as `ft` partials.\n", "\n", "Attributes are passed as keywords. Use 'klass' and 'fr' instead of 'class' and 'for', to avoid Python reserved word clashes." ] @@ -147,11 +148,11 @@ "outputs": [], "source": [ "#| export\n", - "def Html(*c, doctype=True, **kwargs)->XT:\n", + "def Html(*c, doctype=True, **kwargs)->FT:\n", " \"An HTML tag, optionally preceeded by `!DOCTYPE HTML`\"\n", - " res = xt('html', *c, **kwargs)\n", + " res = ft('html', *c, **kwargs)\n", " if not doctype: return res\n", - " return (xt('!DOCTYPE', html=True, void_=True), res)" + " return (ft('!DOCTYPE', html=True, void_=True), res)" ] }, { @@ -295,10 +296,10 @@ "source": [ "#| export\n", "def to_xml(elm, lvl=0):\n", - " \"Convert `xt` element tree into an XML string\"\n", + " \"Convert `ft` element tree into an XML string\"\n", " if elm is None: return ''\n", " if isinstance(elm, tuple): return '\\n'.join(to_xml(o) for o in elm)\n", - " if hasattr(elm, '__xt__'): elm = elm.__xt__()\n", + " if hasattr(elm, '__ft__'): elm = elm.__ft__()\n", " sp = ' ' * lvl\n", " if not isinstance(elm, list): return f'{_escape(elm)}\\n'\n", "\n", @@ -311,7 +312,7 @@ " isvoid = getattr(elm, 'void_', False)\n", " cltag = '' if isvoid else f''\n", " if not cs: return f'{sp}<{stag}>{cltag}\\n'\n", - " if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__xt__'):\n", + " if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__ft__'):\n", " return f'{sp}<{stag}>{_escape(cs[0])}{cltag}\\n'\n", " res = f'{sp}<{stag}>\\n'\n", " res += ''.join(to_xml(c, lvl=lvl+2) for c in cs)\n", @@ -378,7 +379,7 @@ "{escape(to_xml(s))}\n", "\"\"\"\n", "\n", - "XT._repr_markdown_ = highlight" + "FT._repr_markdown_ = highlight" ] }, { @@ -391,7 +392,7 @@ "#| export\n", "def __getattr__(tag):\n", " if tag.startswith('_') or tag[0].islower(): raise AttributeError\n", - " def _f(*c, target_id=None, **kwargs): return xt(tag, *c, target_id=target_id, **kwargs)\n", + " def _f(*c, target_id=None, **kwargs): return ft(tag, *c, target_id=target_id, **kwargs)\n", " return _f" ] }, diff --git a/settings.ini b/settings.ini index ccb8504c..40624a95 100644 --- a/settings.ini +++ b/settings.ini @@ -8,13 +8,13 @@ author = Jeremy Howard and Sylvain Gugger author_email = infos@fast.ai copyright = fast.ai branch = master -version = 1.5.56 -min_python = 3.7 +version = 1.6.0 +min_python = 3.8 audience = Developers language = English custom_sidebar = False license = apache2 -status = 4 +status = 5 nbs_path = nbs doc_path = _docs dev_requirements = numpy nbdev>=0.2.39 matplotlib pillow torch pandas nbclassic