Beispiel #1
0
def compile_sketch(sketch_name,
                   generate_index=False,
                   index_template=None,
                   force_local=False):
    """
    Transcrypt the sketch python code to javascript.

    :param sketch_name: name for new sketch
    :param generate_index: boolean to flag if the index.html file should be updated
    :param force_local: boolean to flag to force local run (used by web editor only)
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch = Sketch(sketch_name)
    sketch.validate_name()

    if not sketch.sketch_exists:
        raise PythonSketchDoesNotExist(sketch)

    compile_sketch_js(sketch, force_local=force_local)
    if generate_index:
        # to be able to overwrite default index template file
        # useful for generating the docs or debugging
        sketch.config.index_template = index_template
        index_contet = get_sketch_index_content(sketch)
        with open(sketch.index_html, "w", encoding="utf-8") as fd:
            fd.write(index_contet)
        cprint.info(f"{sketch.index_html.resolve()} updated")

    return sketch
Beispiel #2
0
def compile_sketch(sketch_name):
    """
    Transcrypt the sketch python code to javascript.

    :param sketch_name: name for new sketch
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch = Sketch(sketch_name)
    sketch.validate_name()

    if not sketch.sketch_exists:
        raise PythonSketchDoesNotExist(sketch)

    compile_sketch_js(sketch)
    return sketch
Beispiel #3
0
def monitor_sketch(sketch_name):
    """
    Monitor for any change in any .py inside the sketch dir.
    For every new change, runs the transcrypt to update the js files.

    :param sketch_name: name for new sketch
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch = Sketch(sketch_name)
    sketch.validate_name()

    if not sketch.sketch_exists:
        raise PythonSketchDoesNotExist(sketch)

    cprint(f"Monitoring for changes in {sketch.sketch_dir.resolve()}...")

    try:
        monitor_sketch_service(sketch)
    except KeyboardInterrupt:
        cprint.info("Exiting monitor...")
Beispiel #4
0
 def test_raise_exception_when_name_contains_non_alphanumeric_chars(self):
     files = Sketch('name&')
     with pytest.raises(InvalidName):
         files.validate_name()
Beispiel #5
0
 def test_raise_exception_when_name_starts_with_numbers(self):
     files = Sketch('123name')
     with pytest.raises(InvalidName):
         files.validate_name()