update README

This commit is contained in:
0xDEADFED5 2025-05-22 23:15:13 -07:00
parent f1384fc289
commit 5f2885f068
2 changed files with 11 additions and 54 deletions

View file

@ -1,4 +1,6 @@
# In-game debugpy command # debugpy
Contribution by electroglyph, 2025
This registers an in-game command `debugpy` which starts the debugpy debugger and listens on port 5678. This registers an in-game command `debugpy` which starts the debugpy debugger and listens on port 5678.
For now this is only available for Visual Studio Code (VS Code). For now this is only available for Visual Studio Code (VS Code).
@ -9,11 +11,8 @@ https://youtrack.jetbrains.com/issue/PY-63403/Support-debugpy
Credit for this goes to Moony on the Evennia Discord getting-help channel, thx Moony! Credit for this goes to Moony on the Evennia Discord getting-help channel, thx Moony!
0xDEADFED5 simply tied a pretty bow around it and stuck it here for everybody else.
## Installation
## Dependencies
This requires VS Code and debugpy, so make sure you're using VS Code. This requires VS Code and debugpy, so make sure you're using VS Code.
@ -21,7 +20,7 @@ From the venv where you installed Evennia run:
`pip install debugpy` `pip install debugpy`
## Enable the command in Evennia ### Enable the command in Evennia
In your Evennia mygame folder, open up `/commands/default_cmdsets.py` In your Evennia mygame folder, open up `/commands/default_cmdsets.py`
@ -31,49 +30,7 @@ in CharacterCmdSet.at_cmdset_creation add this under `super().at_cmdset_creation
`self.add(CmdDebugPy)` `self.add(CmdDebugPy)`
For a newly initialized game, the result would look like this at the top of the file: ### Add "remote attach" option to VS Code debugger
```python
"""
Command sets
All commands in the game must be grouped in a cmdset. A given command
can be part of any number of cmdsets and cmdsets can be added/removed
and merged onto entities at runtime.
To create new commands to populate the cmdset, see
`commands/command.py`.
This module wraps the default command sets of Evennia; overloads them
to add/remove commands from the default lineup. You can create your
own cmdsets by inheriting from them or directly from `evennia.CmdSet`.
"""
from evennia import default_cmds
from evennia.contrib.utils.debugpy.cmd import CmdDebugPy
class CharacterCmdSet(default_cmds.CharacterCmdSet):
"""
The `CharacterCmdSet` contains general in-game commands like `look`,
`get`, etc available on in-game Character objects. It is merged with
the `AccountCmdSet` when an Account puppets a Character.
"""
key = "DefaultCharacter"
def at_cmdset_creation(self):
"""
Populates the cmdset
"""
super().at_cmdset_creation()
#
# any commands you add below will overload the default ones.
#
self.add(CmdDebugPy)
```
## Add "remote attach" option to VS Code debugger
Start VS Code and open your launch.json like this: Start VS Code and open your launch.json like this:
@ -88,7 +45,7 @@ Add this to your configuration:
"type": "debugpy", "type": "debugpy",
"request": "attach", "request": "attach",
"connect": { "connect": {
"host": "localhost", "host": "127.0.0.1",
"port": 5678 "port": 5678
}, },
"pathMappings": [ "pathMappings": [
@ -100,7 +57,7 @@ Add this to your configuration:
}, },
``` ```
Use `localhost` for the host if you are running Evennia from the same machine you'll be debugging from. Otherwise, if you want to debug a remote server, change host (and possibly remoteRoot mapping) as necessary. Use `127.0.0.1` for the host if you are running Evennia from the same machine you'll be debugging from. Otherwise, if you want to debug a remote server, change host (and possibly remoteRoot mapping) as necessary.
Afterwards it should look something like this: Afterwards it should look something like this:
@ -124,7 +81,7 @@ Afterwards it should look something like this:
"type": "debugpy", "type": "debugpy",
"request": "attach", "request": "attach",
"connect": { "connect": {
"host": "localhost", "host": "127.0.0.1",
"port": 5678 "port": 5678
}, },
"pathMappings": [ "pathMappings": [
@ -140,7 +97,7 @@ Afterwards it should look something like this:
(notice the comma between the curly braces) (notice the comma between the curly braces)
## Use it ## Usage
Set a breakpoint in VS Code where you want the debugger to stop at. Set a breakpoint in VS Code where you want the debugger to stop at.

View file

@ -29,6 +29,6 @@ class CmdDebugPy(COMMAND_DEFAULT_CLASS):
caller = self.caller caller = self.caller
caller.msg("Waiting for debugger attach...") caller.msg("Waiting for debugger attach...")
yield 0.1 # make sure msg is sent first yield 0.1 # make sure msg is sent first
debugpy.listen(("localhost", 5678)) debugpy.listen(5678)
debugpy.wait_for_client() debugpy.wait_for_client()
caller.msg("Debugger attached.") caller.msg("Debugger attached.")