MCPcopy Create free account
hub / github.com/VCVRack/Rack / create_module

Function create_module

helper.py:200–274  ·  view source on GitHub ↗
(slug, panel_filename=None, source_filename=None)

Source from the content-addressed store, hash-verified

198
199
200def create_module(slug, panel_filename=None, source_filename=None):
201 # Check slug
202 if not is_valid_slug(slug):
203 raise UserException("Slug must only contain ASCII letters, numbers, '-', and '_'.")
204
205 # Read manifest
206 manifest_filename = 'plugin.json'
207 with open(manifest_filename, "r") as f:
208 manifest = json.load(f)
209
210 # Check if module manifest exists
211 module_manifest = find(lambda m: m['slug'] == slug, manifest['modules'])
212 if module_manifest:
213 eprint(f"Module {slug} already exists in plugin.json. Edit this file to modify the module manifest.")
214
215 else:
216 # Add module to manifest
217 module_manifest = {}
218 module_manifest['slug'] = slug
219 module_manifest['name'] = input_default("Module name", slug)
220 module_manifest['description'] = input_default("One-line description (optional)")
221 tags = input_default("Tags (comma-separated, case-insensitive, see https://vcvrack.com/manual/Manifest#modules-tags for list)")
222 tags = tags.split(",")
223 tags = [tag.strip() for tag in tags]
224 if len(tags) == 1 and tags[0] == "":
225 tags = []
226 module_manifest['tags'] = tags
227
228 manifest['modules'].append(module_manifest)
229
230 # Write manifest
231 with open(manifest_filename, "w") as f:
232 json.dump(manifest, f, indent=" ")
233
234 eprint(f"Added {slug} to {manifest_filename}")
235
236 # Check filenames
237 if panel_filename:
238 if not os.path.exists(panel_filename):
239 raise UserException(f"Panel not found at {panel_filename}.")
240
241 if source_filename and os.path.exists(source_filename):
242 if input_default(f"{source_filename} already exists. Overwrite? (y/n)", "n").lower() != "y":
243 return
244
245 # Read SVG XML
246 try:
247 tree = xml.etree.ElementTree.parse(panel_filename)
248 except:
249 raise UserException("Invalid SVG")
250
251 components = panel_to_components(tree)
252
253 # Tell user to add model to plugin.hpp and plugin.cpp
254 identifier = str_to_identifier(slug)
255 eprint(f"""
256To enable the module, add
257

Callers 1

parse_argsFunction · 0.85

Calls 9

is_valid_slugFunction · 0.85
UserExceptionClass · 0.85
findFunction · 0.85
eprintFunction · 0.85
input_defaultFunction · 0.85
panel_to_componentsFunction · 0.85
str_to_identifierFunction · 0.85
components_to_sourceFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected