@@ -107,7 +107,9 @@ async def register_dev_plugin(self) -> AsyncGenerator[tuple[str, str], None]:
107107 message : DevPluginRegistrationEndDict = {"type" : "end" }
108108 await channel .send_message (message )
109109
110- async def run_plugin (self , * , allow_local_imports : bool = True ) -> int :
110+ async def run_plugin (
111+ self , * , allow_local_imports : bool = True , debug : bool = False
112+ ) -> int :
111113 if not allow_local_imports :
112114 raise ValueError ("Local imports are always permitted for dev plugins" )
113115 async with self .register_dev_plugin () as (client_id , client_key ):
@@ -117,35 +119,40 @@ async def run_plugin(self, *, allow_local_imports: bool = True) -> int:
117119 self ._plugin_path ,
118120 client_id ,
119121 client_key ,
122+ debug ,
120123 )
121124 )
122125 return result .returncode
123126
124127
125- # TODO: support the same subprocess monitoring features as `lms dev`
128+ # TODO: support the same source code change monitoring features as `lms dev`
126129def _run_plugin_in_child_process (
127- plugin_path : Path , client_id : str , client_key : str
130+ plugin_path : Path , client_id : str , client_key : str , debug : bool = False
128131) -> subprocess .CompletedProcess [str ]:
129132 env = os .environ .copy ()
130133 env [ENV_CLIENT_ID ] = client_id
131134 env [ENV_CLIENT_KEY ] = client_key
132135 package_name = __spec__ .parent
133136 assert package_name is not None
137+ debug_option = ("--debug" ,) if debug else ()
134138 command : list [str ] = [
135139 sys .executable ,
136140 "-m" ,
137141 package_name ,
142+ * debug_option ,
138143 os .fspath (plugin_path ),
139144 ]
140145 return subprocess .run (command , text = True , env = env )
141146
142147
143- async def run_plugin_async (plugin_dir : str | os .PathLike [str ]) -> int :
148+ async def run_plugin_async (
149+ plugin_dir : str | os .PathLike [str ], * , debug : bool = False
150+ ) -> int :
144151 """Asynchronously execute a plugin in development mode."""
145152 async with DevPluginClient (plugin_dir ) as dev_client :
146- return await dev_client .run_plugin ()
153+ return await dev_client .run_plugin (debug = debug )
147154
148155
149- def run_plugin (plugin_dir : str | os .PathLike [str ]) -> int :
156+ def run_plugin (plugin_dir : str | os .PathLike [str ], * , debug : bool = False ) -> int :
150157 """Execute a plugin in development mode."""
151- return asyncio .run (run_plugin_async (plugin_dir ))
158+ return asyncio .run (run_plugin_async (plugin_dir , debug = debug ))
0 commit comments