Пример #1
0
    def on_modified(self, event):
        event_id = id(event)
        if event_id == self._last_event:
            return

        cprint.info(f"New change in {event.src_path}")
        compile_sketch_js(self.sketch, TARGET_DIRNAME)
Пример #2
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
Пример #3
0
def test_compile_sketch_js_service(MockedCompiler, sketch):
    compiler = Mock(spec=TranscryptCompiler)
    MockedCompiler.return_value = compiler

    compile_sketch_js(sketch)

    MockedCompiler.assert_called_once_with(sketch)
    compiler.compile_sketch_js.assert_called_once_with()
Пример #4
0
def test_compile_sketch_js_service(MockedCompiler, files):
    compiler = Mock(spec=Pyp5jsCompiler)
    MockedCompiler.return_value = compiler

    compile_sketch_js(files)

    MockedCompiler.assert_called_once_with(files)
    compiler.compile_sketch_js.assert_called_once_with()
Пример #5
0
def transcrypt_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_files = SketchFiles(sketch_name)
    if not sketch_files.sketch_exists:
        raise PythonSketchDoesNotExist(sketch_files.sketch_py.resolve())

    compile_sketch_js(sketch_files)
    return sketch_files
Пример #6
0
    def on_modified(self, event):
        cprint.info(f"New change in {event.src_path}")

        # monkey patch on the observer handlers to avoid recursion
        handlers_config = self.observer._handlers.copy()
        handlers_copy = {}

        compile_sketch_js(self.sketch)

        queue = self.observer.event_queue
        while queue.qsize():
            queue.get()

        index_file = self.sketch.index_html
        cprint.ok(
            f"Your sketch is ready and available at file://{index_file.absolute()}"
        )
Пример #7
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
Пример #8
0
def transcrypt_sketch(sketch_name, sketch_dir):
    """
    Transcrypt the sketch python code to javascript.

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

    sketch_files = Pyp5jsSketchFiles(sketch_dir, sketch_name)
    if not sketch_files.check_sketch_exists():
        cprint.err(f"Couldn't find {sketch_name}", interrupt=True)

    compile_sketch_js(sketch_files)
    return sketch_files.index_html
Пример #9
0
def transcrypt_sketch(sketch_name, sketch_dir):
    sketch = _validate_sketch_path(sketch_name, sketch_dir)
    compile_sketch_js(sketch, TARGET_DIRNAME)
    return sketch.parent.child("index.html")