sdpython / jyquickhelper

@@ -19,7 +19,7 @@
Loading
19 19
20 20
    def __init__(self, url, code):
21 21
        Exception.__init__(
22 -
            self, "Url not found: returned code={0} for '{1}'".format(code, url))
22 +
            self, f"Url not found: returned code={code} for '{url}'")
23 23
24 24
25 25
class JavascriptScriptError(ValueError):
@@ -39,7 +39,7 @@
Loading
39 39
    except liberror.URLError as e:
40 40
        raise UrlNotFoundError(url, e.reason) from e
41 41
    except Exception as e:
42 -
        raise Exception("Issue with url '{0}'".format(url)) from e
42 +
        raise Exception(f"Issue with url '{url}'") from e
43 43
44 44
45 45
class RenderJSRaw:
@@ -76,22 +76,22 @@
Loading
76 76
        if style is None:
77 77
            style = ''
78 78
            if width is not None and 'width' not in style:
79 -
                style += "width:{0};".format(width)
79 +
                style += f"width:{width};"
80 80
            if height is not None and 'height' not in style:
81 -
                style += "height:{0};".format(height)
81 +
                style += f"height:{height};"
82 82
            if not style:
83 83
                style = None
84 84
        else:
85 85
            if width is not None and 'width' not in style:
86 -
                style += "width:{0};".format(width)
86 +
                style += f"width:{width};"
87 87
            if height is not None and 'height' not in style:
88 -
                style += "height:{0};".format(height)
88 +
                style += f"height:{height};"
89 89
        self.style = style
90 90
        self.only_html = only_html
91 91
        self.div_class = div_class
92 92
        if "__ID__" not in script:
93 93
            raise JavascriptScriptError(
94 -
                "The sript does not contain any string __ID__. It is replaced by the ID value in script:\n{0}".format(script))
94 +
                f"The sript does not contain any string __ID__. It is replaced by the ID value in script:\n{script}")
95 95
        self.local = local
96 96
        self.css, self.libs = self._copy_local(css, libs, local)
97 97
        if check_urls and not local:
@@ -128,7 +128,7 @@
Loading
128 128
129 129
        for js in to_copy:
130 130
            if not os.path.exists(js):
131 -
                raise FileNotFoundError("Unable to find '{0}'".format(js))
131 +
                raise FileNotFoundError(f"Unable to find '{js}'")
132 132
            dest = local if isinstance(local, str) else os.getcwd()
133 133
            shutil.copy(js, dest)
134 134
@@ -155,16 +155,16 @@
Loading
155 155
                    `Javascript <http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.Javascript>`_ text
156 156
        """
157 157
        if self.style:
158 -
            style = ' style="{0}"'.format(self.style)
158 +
            style = f' style="{self.style}"'
159 159
        else:
160 160
            style = ""
161 161
        if self.div_class:
162 -
            divcl = ' class="{0}"'.format(self.div_class)
162 +
            divcl = f' class="{self.div_class}"'
163 163
        else:
164 164
            divcl = ""
165 165
        if self.css:
166 166
            css = "".join(
167 -
                '<link rel="stylesheet" href="{0}" type="text/css" />'.format(c) for c in self.css)
167 +
                f'<link rel="stylesheet" href="{c}" type="text/css" />' for c in self.css)
168 168
            ht = '<div id="{uuid}-css">{css}<div{divcl} id="{uuid}"{style}></div></div>'.format(
169 169
                uuid=self.uuid, css=css, style=style, divcl=divcl)
170 170
        else:
@@ -189,7 +189,7 @@
Loading
189 189
                        paths.append((name, path))
190 190
                    else:
191 191
                        raise KeyError(
192 -
                            "unable to find 'path' in {0}".format(lib))
192 +
                            f"unable to find 'path' in {lib}")
193 193
                    names.append(name)
194 194
                    args.append(name)
195 195
                    if "exports" in lib:
@@ -210,13 +210,13 @@
Loading
210 210
                raise ValueError(
211 211
                    "names is empty.\nlibs={0}\npaths={1}\nshims={2}\nexports={3}".format(
212 212
                        self.libs, paths, shims, exports))
213 -
            require = ",".join("'{0}'".format(na) for na in names)
213 +
            require = ",".join(f"'{na}'" for na in names)
214 214
215 215
            config = ["require.config({"]
216 216
            if len(paths) > 0:
217 217
                config.append("paths:{")
218 218
                for name, path in paths:
219 -
                    config.append("'{0}':'{1}',".format(name, path))
219 +
                    config.append(f"'{name}':'{path}',")
220 220
                config.append("},")
221 221
            if len(shims) > 0:
222 222
                config.append("shim:{")
@@ -229,7 +229,7 @@
Loading
229 229
                            k, v if isinstance(v, list) else "'{0}'".format(v)))
230 230
                    return "{%s}" % ",".join(rows)
231 231
                for k, v in sorted(shims.items()):
232 -
                    config.append("'{0}':{1},".format(k, vd(v)))
232 +
                    config.append(f"'{k}':{vd(v)},")
233 233
                config.append("},")
234 234
            config.append("});")
235 235
            if len(config) > 2:
@@ -242,7 +242,7 @@
Loading
242 242
        else:
243 243
            js = script
244 244
        if self.only_html:
245 -
            ht += "\n<script>\n%s\n</script>" % js
245 +
            ht += f"\n<script>\n{js}\n</script>"
246 246
            return ht, None
247 247
        return ht, js
248 248
@@ -280,5 +280,5 @@
Loading
280 280
        """
281 281
        ht, js = self.generate_html()
282 282
        if js is not None:
283 -
            ht += "\n<script>\n{0}\n</script>\n".format(js)
283 +
            ht += f"\n<script>\n{js}\n</script>\n"
284 284
        return ht

@@ -75,6 +75,6 @@
Loading
75 75
        @return             javascript
76 76
        """
77 77
        dot = dot.replace('"', '\\"').replace('\n', '\\n')
78 -
        script = """var svgGraph = Viz("{0}");\ndocument.getElementById('__ID__').innerHTML = svgGraph;""".format(
79 -
            dot)
78 +
        script = f"""var svgGraph = Viz("{dot}");
79 +
document.getElementById('__ID__').innerHTML = svgGraph;"""
80 80
        return script

@@ -78,7 +78,7 @@
Loading
78 78
            ]
79 79
        else:
80 80
            raise NotImplementedError(
81 -
                "Unable to generate a script for class '{0}'".format(class_vis))
81 +
                f"Unable to generate a script for class '{class_vis}'")
82 82
83 83
        if local:
84 84
            this = os.path.dirname(__file__)
@@ -124,14 +124,14 @@
Loading
124 124
                                                      'sortMethod': "directed"}}
125 125
            else:
126 126
                opts = {k: v for k, v in options.items() if v is not None}
127 -
            st = 'var options = {0};'.format(RenderJsVis._options2js(opts))
127 +
            st = f'var options = {RenderJsVis._options2js(opts)};'
128 128
            jsadd += "\n" + st + "\n"
129 129
130 130
        checks = ['var data =', 'var options =']
131 131
        for ch in checks:
132 132
            if ch not in jsadd:
133 133
                raise JavascriptVisError(
134 -
                    "String '{0}' was not found in\n{1}".format(ch, js))
134 +
                    f"String '{ch}' was not found in\n{js}")
135 135
        script = jsadd + "\nvar container = document.getElementById('__ID__');" + \
136 136
            "\nvar network = new vis.Network(container, data, options);\n"
137 137
        return script
@@ -150,7 +150,7 @@
Loading
150 150
            if isinstance(v, dict):
151 151
                rows.append(RenderJsVis._options2js(v))
152 152
            else:
153 -
                rows.append('"{0}"'.format(v))
153 +
                rows.append(f'"{v}"')
154 154
            rows.append(', ')
155 155
        rows.append('}')
156 156
        return "".join(rows)

@@ -53,7 +53,7 @@
Loading
53 53
        this = os.path.dirname(__file__)
54 54
        js = os.path.join(this, '..', 'js', 'renderjson', 'renderjson.js')
55 55
        if not os.path.exists(js):
56 -
            raise FileNotFoundError("Unable to find '{0}'".format(js))
56 +
            raise FileNotFoundError(f"Unable to find '{js}'")
57 57
        dest = local if isinstance(local, str) else os.getcwd()
58 58
        shutil.copy(js, dest)
59 59
@@ -92,7 +92,7 @@
Loading
92 92
93 93
    def _repr_html_(self):
94 94
        ht, js = self.generate_html()
95 -
        ht += "\n<script>\n{0}\n</script>\n".format(js)
95 +
        ht += f"\n<script>\n{js}\n</script>\n"
96 96
        return ht
97 97
98 98

@@ -19,7 +19,7 @@
Loading
19 19
    path = os.path.join(this, ext)
20 20
    if not os.path.exists(path):
21 21
        raise FileNotFoundError(
22 -
            "Unable to find extension '{0}' in '{1}'".format(ext, this))
22 +
            f"Unable to find extension '{ext}' in '{this}'")
23 23
    dest = install_nbextension(
24 24
        path, user=True, destination=ext, overwrite=overwrite)
25 25
    return dest
@@ -52,7 +52,7 @@
Loading
52 52
                <p>Loads extension '__EXT__'.</p>""".replace("                ", "")
53 53
    code = code.replace('__EXT__', ext)
54 54
    code = code.replace('__REQ__', ',\n'.join(
55 -
        "'{0}/{1}'".format(ext, _) for _ in js))
55 +
        f"'{ext}/{_}'" for _ in js))
56 56
    code = code.replace('__CSS__', ';\n'.join(
57 57
        "load_jyq_css_{0}('{0}/{1}')".format(ext, _) for _ in css) + ';')
58 58
    if kind == "html":

@@ -199,8 +199,7 @@
Loading
199 199
    """
200 200
    if keep_item is not None:
201 201
        menu_id += str(keep_item)
202 -
    html = '<div id="{0}">run previous cell, wait for 2 seconds</div>'.format(
203 -
        menu_id)
202 +
    html = f'<div id="{menu_id}">run previous cell, wait for 2 seconds</div>'
204 203
205 204
    add_notebook_menu_js = _add_notebook_menu_js()
206 205
    js = add_notebook_menu_js.replace("                ", "") \
@@ -208,13 +207,13 @@
Loading
208 207
                             .replace("__FIRST__", str(first_level)) \
209 208
                             .replace("__LAST__", str(last_level))
210 209
211 -
    full = "{0}\n<script>{1}</script>".format(html, js)
210 +
    full = f"{html}\n<script>{js}</script>"
212 211
    if keep_item is None:
213 212
        keep_item = -1
214 213
215 214
    if format == "html":
216 215
        if header is not None and len(header) > 0:
217 -
            header = "<b>{0}</b>\n".format(header)
216 +
            header = f"<b>{header}</b>\n"
218 217
        else:
219 218
            header = ""
220 219
        full = header + \
@@ -226,7 +225,7 @@
Loading
226 225
            .replace("__END_FORMAT__", "'</li>'")
227 226
    elif format == "rst":
228 227
        if header is not None and len(header) > 0:
229 -
            header = "{0}\n\n".format(header)
228 +
            header = f"{header}\n\n"
230 229
        else:
231 230
            header = ""
232 231
        full = header + \
@@ -254,4 +253,4 @@
Loading
254 253
255 254
    @param      name        extension name
256 255
    """
257 -
    return Javascript("IPython.utils.load_extensions('%s')" % name)
256 +
    return Javascript(f"IPython.utils.load_extensions('{name}')")
Files Coverage
src/jyquickhelper 92.61%
Project Totals (22 files) 92.61%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading