Пример #1
0
def new_sketch(sketch_name,
               interpreter=PYODIDE_INTERPRETER,
               template_file="",
               use_cdn=True):
    """
    Creates a new sketch with the required assets and a index.html file, based on pyp5js's templates

    :param sketch_name: name for new sketch
    :param interpreter: interpreter to use (transcrypt or pyodide)
    :param template_file: use a custom template for index.html instead of default one
    :param use_cdn: if false, the sketch will have copies of required static assets (p5.js and pyodide)
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """
    cfg = {
        "interpreter": interpreter,
        "index_template": template_file,
    }

    sketch = Sketch(sketch_name, **cfg)
    sketch.create_sketch_dir()
    sketch.copy_initial_files(use_cdn=use_cdn)

    index_contet = get_sketch_index_content(sketch)
    with open(sketch.index_html, "w", encoding="utf-8") as fd:
        fd.write(index_contet)

    return sketch
Пример #2
0
    def test_copy_local_files_if_not_using_cdn(self):
        files = Sketch('test', interpreter=PYODIDE_INTERPRETER)
        files.create_sketch_dir()
        files.copy_initial_files(use_cdn=False)
        pyodide_js_dir = files.static_dir / "pyodide"

        assert files.config.p5_js_url == "/static/p5.js"
        assert files.config.pyodide_js_url == "/static/pyodide/pyodide_v0.18.1.js"
        assert files.p5js.exists()
        assert pyodide_js_dir.exists()

        assert (pyodide_js_dir / "pyodide.asm.data").exists()
        assert (pyodide_js_dir / "pyodide.asm.js").exists()
        assert (pyodide_js_dir / "pyodide.asm.wasm").exists()
        assert (pyodide_js_dir / "pyodide.js.map").exists()
        assert (pyodide_js_dir / "pyodide_v0.18.1.js").exists()
        assert not (pyodide_js_dir / "packages.json").exists()