Skip to content

Commit d749da9

Browse files
committed
Reflect latest changes in README
1 parent 3b9caf8 commit d749da9

1 file changed

Lines changed: 69 additions & 44 deletions

File tree

README.md

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ tree sitter parser for Python.
1818

1919
### Debugpy
2020

21-
It is recommended to install debugpy into a dedicated virtualenv. To do so:
21+
You need to install `debugpy` using either your package manager or via `pip`.
22+
For example:
2223

2324
```bash
2425
mkdir .virtualenvs
@@ -27,13 +28,19 @@ python -m venv debugpy
2728
debugpy/bin/python -m pip install debugpy
2829
```
2930

30-
The debugger will automatically pick-up another virtual environment if it is
31-
activated before neovim is started.
32-
31+
If you're using virtual environments for your project it will automatically get
32+
picked up if it is active before `nvim` starts, or if it is in a default
33+
location. See [Python dependencies and
34+
virtualenv](#python-dependencies-and-virtualenv)
3335

3436
### Tree-sitter
3537

36-
Install either:
38+
If you're using a properly packaged `nvim` version 0.10+, a python tree-sitter
39+
parser should be included and you're all set.
40+
41+
If you're using an older version, or your distribution excluded the parser you
42+
can install it manually using either:
43+
3744

3845
- Via `:TSInstall python` of [nvim-treesitter][4]
3946
- Compile the parser from [tree-sitter-python][5] and copy it into `.config/nvim/parser/`:
@@ -44,47 +51,63 @@ Install either:
4451

4552
## Usage
4653

47-
1. Call `setup` in your `init.vim` to register the adapter and configurations:
54+
1. Call `setup` in your `init.lua` to register the adapter and configurations.
4855

49-
```vimL
50-
lua require('dap-python').setup('~/.virtualenvs/debugpy/bin/python')
51-
```
56+
If installed in a virtual environment:
5257

53-
The argument to `setup` is the path to the python installation which contains the `debugpy` module.
58+
```lua
59+
require("dap-python").setup("/path/to/venv/bin/python")
60+
-- If using the above, then `/path/to/venv/bin/python -m debugpy --version`
61+
-- must work in the shell
62+
```
5463

64+
Or if installed globally:
5565

56-
2. Use nvim-dap as usual.
66+
```lua
67+
require("dap-python").setup("python")
68+
-- If using the above, then `python -m debugpy --version`
69+
-- must work in the shell
70+
```
5771

58-
- Call `:lua require('dap').continue()` to start debugging.
59-
- See `:help dap-mappings` and `:help dap-api`.
60-
- Use `:lua require('dap-python').test_method()` to debug the closest method above the cursor.
6172

62-
Supported test frameworks are `unittest`, `pytest` and `django`. By default it
63-
tries to detect the runner by probing for `pytest.ini` and `manage.py`, if
64-
neither are present it defaults to `unittest`.
73+
2. Use `nvim-dap` as usual.
6574

66-
To configure a different runner, change the `test_runner` variable. For example
67-
to configure `pytest` set the test runner like this in `vimL`:
75+
- Call `:lua require('dap').continue()` to start debugging.
76+
- See `:help dap-mappings` and `:help dap-api`.
77+
- Use `:lua require('dap-python').test_method()` to debug the closest method above the cursor.
6878

69-
```vimL
70-
lua require('dap-python').test_runner = 'pytest'
71-
```
79+
Supported test frameworks are `unittest`, `pytest` and `django`. By default it
80+
tries to detect the runner by probing for `pytest.ini` and `manage.py`, if
81+
neither are present it defaults to `unittest`.
7282

73-
You can also add custom runners. An example in `Lua`:
83+
To configure a different runner, change the `test_runner` variable. For
84+
example, to configure `pytest` set the test runner like this in your
85+
`init.lua`:
7486

75-
```lua
76-
local test_runners = require('dap-python').test_runners
77-
78-
-- `test_runners` is a table. The keys are the runner names like `unittest` or `pytest`.
79-
-- The value is a function that takes three arguments:
80-
-- The classname, a methodname and the opts
81-
-- (The `opts` are coming passed through from either `test_method` or `test_class`)
82-
-- The function must return a module name and the arguments passed to the module as list.
83-
test_runners.your_runner = function(classname, methodname, opts)
84-
local args = {classname, methodname}
85-
return 'modulename', args
86-
end
87-
```
87+
```lua
88+
require('dap-python').test_runner = 'pytest'
89+
```
90+
91+
You can also add custom runners. An example in `Lua`:
92+
93+
```lua
94+
local test_runners = require('dap-python').test_runners
95+
96+
-- `test_runners` is a table. The keys are the runner names like `unittest` or `pytest`.
97+
-- The value is a function that takes two arguments:
98+
-- The classnames and a methodname
99+
-- The function must return a module name and the arguments passed to the module as list.
100+
101+
---@param classnames string[]
102+
---@param methodname string?
103+
test_runners.your_runner = function(classnames, methodname)
104+
local path = table.concat({
105+
table.concat(classnames, ":"),
106+
methodname,
107+
}, "::")
108+
return 'modulename', {"-s", path}
109+
end
110+
```
88111

89112

90113
### Documentation
@@ -104,12 +127,18 @@ vnoremap <silent> <leader>ds <ESC>:lua require('dap-python').debug_selection()<C
104127

105128
## Custom configuration
106129

107-
If you call the `require('dap-python').setup` method it will create a few `nvim-dap` configuration entries. These configurations are general purpose configurations suitable for many use cases, but you may need to customize the configurations - for example if you want to use Docker containers.
130+
If you call the `require('dap-python').setup` method it will create a few
131+
`nvim-dap` configuration entries. These configurations are general purpose
132+
configurations suitable for many use cases, but you may need to customize the
133+
configurations - for example if you want to use Docker containers.
108134

109-
To add your own entries, you can extend the `dap.configurations.python` list after calling the `setup` function:
135+
To add your own entries you can create per project `.vscode/launch.json`
136+
configuration files. See `:help dap-launch.json`.
110137

111-
```vimL
112-
lua << EOF
138+
Or you can add your own global entries by extending the
139+
`dap.configurations.python` list after calling the `setup` function:
140+
141+
```lua
113142
require('dap-python').setup('/path/to/python')
114143
table.insert(require('dap').configurations.python, {
115144
type = 'python',
@@ -118,12 +147,8 @@ table.insert(require('dap').configurations.python, {
118147
program = '${file}',
119148
-- ... more options, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
120149
})
121-
EOF
122150
```
123151

124-
An alternative is to use project specific `.vscode/launch.json` files, see `:help dap-launch.json`.
125-
126-
127152
The [Debugpy Wiki][debugpy_wiki] contains a list of all supported configuration options.
128153

129154

0 commit comments

Comments
 (0)