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

Function create_plugin

helper.py:51–159  ·  view source on GitHub ↗
(slug, plugin_dir=None)

Source from the content-addressed store, hash-verified

49
50
51def create_plugin(slug, plugin_dir=None):
52 # Check slug
53 if not is_valid_slug(slug):
54 raise UserException("Slug must only contain ASCII letters, numbers, '-', and '_'.")
55
56 if not plugin_dir:
57 plugin_dir = os.path.join(slug, '')
58
59 # Check if plugin directory exists
60 if os.path.exists(plugin_dir):
61 raise UserException(f"Directory {plugin_dir} already exists")
62
63 # Create plugin directory
64 os.mkdir(plugin_dir)
65
66 # Create manifest
67 try:
68 create_manifest(slug, plugin_dir)
69 except Exception as e:
70 os.rmdir(plugin_dir)
71 raise e
72
73 # Create subdirectories
74 os.mkdir(os.path.join(plugin_dir, "src"))
75 os.mkdir(os.path.join(plugin_dir, "res"))
76
77 # Create Makefile
78 makefile = """# If RACK_DIR is not defined when calling the Makefile, default to two directories above
79RACK_DIR ?= ../..
80
81# FLAGS will be passed to both the C and C++ compiler
82FLAGS +=
83CFLAGS +=
84CXXFLAGS +=
85
86# Careful about linking to shared libraries, since you can't assume much about the user's environment and library search path.
87# Static libraries are fine, but they should be added to this plugin's build system.
88LDFLAGS +=
89
90# Add .cpp files to the build
91SOURCES += $(wildcard src/*.cpp)
92
93# Add files to the ZIP package when running `make dist`
94# The compiled plugin and "plugin.json" are automatically added.
95DISTRIBUTABLES += res
96DISTRIBUTABLES += $(wildcard LICENSE*)
97DISTRIBUTABLES += $(wildcard presets)
98
99# Include the Rack plugin Makefile framework
100include $(RACK_DIR)/plugin.mk
101"""
102 with open(os.path.join(plugin_dir, "Makefile"), "w") as f:
103 f.write(makefile)
104
105 # Create plugin.hpp
106 plugin_hpp = """#pragma once
107#include <rack.hpp>
108

Callers 1

parse_argsFunction · 0.85

Calls 5

is_valid_slugFunction · 0.85
UserExceptionClass · 0.85
create_manifestFunction · 0.85
eprintFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected