Debug a Python plugin in your IDE¶
debug_connect lets you run and debug your plugin code directly in your Python IDE (breakpoints, variables,
step by step) while AnyWave answers the requests as it would for a real plugin.
The principle: you start an AnyWave in plugin debug mode, listening on a TCP port, then your script connects to it as if it was a plugin.
1. Start AnyWave in debug mode¶
Open a terminal and start AnyWave with the port of your choice. Add the data file you want to work on:
anywave --plugin_debug --server_port 59000 /path/to/file.edf
- macOS and Ubuntu: the
anywavecommand is available from a terminal when you installed AnyWave with its package. With the AppImage, run it directly with the same arguments. - Windows: add the AnyWave installation folder to the
PATH, or write the full path ofanywave.exe.
The file is optional: you can also open it in AnyWave afterwards. Requests that need data (like get_data) fail with
the error ERROR: no file open in AnyWave... until a file is open.
2. Install the package in your IDE environment¶
pip install anywave-plugin-api
Use the Python environment of your IDE: it is not necessarily the one of AnyWave.
3. Connect¶
import anywave as aw
props = aw.debug_connect(59000) # the port given to --server_port
print(props['data_path'])
props is the dict of the settings of the plugin, the same as the one returned by get_props. It is
also available as anywave.properties. This call is not part of your plugin: use it instead of aw.init(sys.argv)
while you debug, and keep both lines in your script with a test such as:
if len(sys.argv) == 3: # started by AnyWave
aw.init(sys.argv)
else: # started by your IDE
aw.debug_connect(59000)
4. Run your code¶
You are now connected: every function of the package works.
out = aw.get_data({'labels': ['Fp1', 'Cz']})
aw.send_message('hello from my IDE')
Set breakpoints in your script as usual to go through your code line by line.
Differences with a real plugin¶
- Some settings only exist when AnyWave launches the plugin itself, like the folder of the plugin and its working directory: the dict can hold empty paths. Do not rely on them while you debug.
- If you restart AnyWave, call
debug_connectagain: AnyWave gives a new identity to the fake plugin. print()writes in the console of your IDE, not in the log of AnyWave. Usesend_messageto write in the log.
Errors¶
| message | cause |
|---|---|
Unable to connect to AnyWave: ... |
AnyWave is not started in debug mode, or the port is not the same |