def test_create_new_sketch_with_all_required_files(self): commands.new_sketch(self.sketch_name) assert self.sketch_files.index_html.exists() assert self.sketch_files.sketch_py.exists() assert self.sketch_files.p5js.exists() assert self.sketch_files.p5_dom_js.exists()
def test_create_new_sketch_with_all_required_files(self): commands.new_sketch(self.sketch_name) assert self.sketch.index_html.exists() assert self.sketch.sketch_py.exists() assert self.sketch.p5js.exists() assert self.sketch.config_file.exists() assert self.sketch.config.interpreter == TRANSCRYPT_INTERPRETER
def test_create_sketch_with_custom_index(self): template = PYP5JS_FILES.install.parent / "docs" / "examples" / "transcrypt" / "index.html.template" commands.new_sketch(self.sketch_name, template_file=template) assert self.sketch.index_html.exists() with open(self.sketch.index_html) as fd: content = fd.read() assert "demoContainer" in content
def test_create_pyodide_sketch(self): commands.new_sketch(self.sketch_name, interpreter=PYODIDE_INTERPRETER) self.sketch = Sketch(self.sketch_name) # read config after init assert self.sketch.index_html.exists() assert self.sketch.sketch_py.exists() assert self.sketch.p5js.exists() assert self.sketch.config_file.exists() assert self.sketch.config.interpreter == PYODIDE_INTERPRETER
def configure_new_sketch(sketch_name, monitor, interpreter, template, cdn): """ Create dir and configure boilerplate - Example:\n $ pyp5js new my_sketch -i pyodide """ files = commands.new_sketch(sketch_name, interpreter, template_file=template, use_cdn=cdn) cprint.ok(f"Your sketch was created!") if not monitor: cprint.ok( f"Please, open and edit the file {files.sketch_py} to draw. When you're ready to see your results, just run:" ) cmd = f"\t pyp5js compile {sketch_name}" cprint.ok(cmd) cprint.ok( f"And open file://{files.index_html.absolute()} on your browser to see yor results!" ) else: cprint.ok(f"Please, open and edit the file {files.sketch_py} to draw.") cprint.ok( f"And open file://{files.index_html.absolute()} on your browser to see yor results!" ) commands.monitor_sketch(sketch_name)
def configure_new_sketch(sketch_name, sketch_dir, monitor): """ Create dir and configure boilerplate Params: - sketch_name: name of the sketch (will create a {sketch_name}.py) Opitionals: - sketch_dir: directory to save the sketch (defaults to {sketch_name}) Example: $ pyp5js new my_sketch """ sketch_py, index_html = commands.new_sketch(sketch_name, sketch_dir) cprint.ok(f"Your sketch was created!") if not monitor: cprint.ok( f"Please, open and edit the file {sketch_py} to draw. When you're ready to see your results, just run:" ) cmd = f"\t pyp5js transcrypt {sketch_name}" if sketch_dir: cmd += f" --sketch-dir {sketch_dir}" cprint.ok(cmd) cprint.ok( f"And open file://{index_html.absolute()} on your browser to see yor results!" ) else: cprint.ok(f"Please, open and edit the file {sketch_py} to draw.") cprint.ok( f"And open file://{index_html.absolute()} on your browser to see yor results!" ) commands.monitor_sketch(sketch_name, sketch_dir)
def add_new_sketch_view(): template = 'new_sketch_form.html' context = { 'sketches_dir': SKETCHBOOK_DIR.resolve(), 'pyodide_interpreter': PYODIDE_INTERPRETER, 'transcrypt_interpreter': TRANSCRYPT_INTERPRETER, } if request.method == 'POST': sketch_name = slugify(request.form.get('sketch_name', '').strip(), separator='_') interpreter = request.form.get('interpreter', PYODIDE_INTERPRETER) if not sketch_name: context['error'] = "You have to input a sketch name to proceed." elif interpreter not in AVAILABLE_INTERPRETERS: context[ 'error'] = f"The interpreter {interpreter} is not valid. Please, select a valid one." else: try: files = commands.new_sketch(sketch_name, interpreter=interpreter) template = 'new_sketch_success.html' context.update({ 'files': files, 'sketch_url': f'/sketch/{sketch_name}/', }) except SketchDirAlreadyExistException: path = SKETCHBOOK_DIR.joinpath(sketch_name) context['error'] = f"The sketch {path} already exists." return render_template(template, **context)
def configure_new_sketch(sketch_name, monitor): """ Create dir and configure boilerplate Params: - sketch_name: name of the sketch (will create a {sketch_name}.py) Opitionals: - monitor: start the monitor command as well Example: $ pyp5js new my_sketch """ files = commands.new_sketch(sketch_name) cprint.ok(f"Your sketch was created!") if not monitor: cprint.ok(f"Please, open and edit the file {files.sketch_py} to draw. When you're ready to see your results, just run:") cmd = f"\t pyp5js transcrypt {sketch_name}" cprint.ok(cmd) cprint.ok(f"And open file://{files.index_html.absolute()} on your browser to see yor results!") else: cprint.ok(f"Please, open and edit the file {sketch_py} to draw.") cprint.ok(f"And open file://{files.index_html.absolute()} on your browser to see yor results!") commands.monitor_sketch(sketch_name)
def add_new_sketch_view(): template = 'new_sketch_form.html' context = {'sketches_dir': SKETCHBOOK_DIR.resolve()} if request.method == 'POST': sketch_name = slugify(request.form.get('sketch_name', '').strip(), separator='_') if not sketch_name: context['error'] = "You have to input a sketch name to proceed." else: try: # web client only supports pyodide mode for now # TODO: improve post payload to accept a select files = commands.new_sketch(sketch_name, interpreter=PYODIDE_INTERPRETER) template = 'new_sketch_success.html' context.update({ 'files': files, 'sketch_url': f'/sketch/{sketch_name}/', }) except SketchDirAlreadyExistException: path = SKETCHBOOK_DIR.joinpath(sketch_name) context['error'] = f"The sketch {path} already exists." return render_template(template, **context)
def configure_new_sketch(sketch_name, sketch_dir): """ Create dir and configure boilerplate Params: - sketch_name: name of the sketch (will create a {sketch_name}.py) Opitionals - sketch_dir: directory to save the sketch (defaults to {sketch_name}) """ sketch_py = commands.new_sketch(sketch_name, sketch_dir) cprint.ok(f"Your sketch was created!") cprint.ok( f"Please, open and edit the file {sketch_py} to draw. When you're ready to see your results, just run:" ) cprint.ok(f"\t pyp5js transcrypt {sketch_name}")
def add_new_sketch_view(): template = 'new_sketch_form.html' context = {'sketches_dir': SKETCHBOOK_DIR.resolve()} if request.method == 'POST': sketch_name = slugify(request.form.get('sketch_name', '').strip(), separator='_') if not sketch_name: context['error'] = "You have to input a sketch name to proceed." try: files = commands.new_sketch(sketch_name) template = 'new_sketch_success.html' context.update({ 'files': files, 'sketch_url': f'/sketch/{sketch_name}/', }) except SketchDirAlreadyExistException: path = SKETCHBOOK_DIR.joinpath(sketch_name) context['error'] = f"The sketch {path} already exists." return render_template(template, **context)
def test_raise_exception_if_dir_already_exist(self): self.sketch_files.create_sketch_dir() with pytest.raises(SketchDirAlreadyExistException): commands.new_sketch(self.sketch_name)
def test_create_sketch_using_local_installed_assets(self): commands.new_sketch(self.sketch_name, use_cdn=False) assert self.sketch.p5js.exists()
def create_sketch_with_static_files(self, name): sketch_files = commands.new_sketch(name) commands.transcrypt_sketch(name) return sketch_files.sketch_dir
def create_sketch(self, name): return commands.new_sketch(name)
def create_sketch(self, name, interpreter=PYODIDE_INTERPRETER): return commands.new_sketch(name, interpreter=interpreter)
def create_sketch_with_static_files(self, name, use_cdn=True): sketch = commands.new_sketch(name, use_cdn=use_cdn) commands.compile_sketch(name) return sketch.sketch_dir
def create_sketch(self, name): sketch_files = commands.new_sketch(name) return sketch_files.sketch_dir