Skip to content

Commit

Permalink
docs: How to debug in VS Code without poetry as dev dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mmartinortiz committed Sep 27, 2024
1 parent b4e7387 commit adf0771
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,44 +274,34 @@ can be set to alter this value.

### How to debug the main script of your project using Poetry, VS Code and `launch.json`

To debug a project that is managed by `poetry` and has a main script, you need to install `poetry` as a development dependency and use the `poetry run` command to execute the script via the `launch.json` file, and configure `poetry` to create the virtual environment in the project directory.
Make sure that VS Code is using the `venv` created by `poetry` as the Python interpreter. You can obtain this information running `poetry env info` in the terminal.

Make sure that `poetry` creates the virtual environment in your project directory. If that is not your case, you will have to recreate your virtual environment after the configuration options is changed.
Given that your entry point is located at `src/my_package/my_program.py` and it looks like:

```bash
poetry config virtualenvs.in-project true
```

Given that your `pyproject.toml` has the following entry:

```toml
[tool.poetry.scripts]
my_program = "my_package.my_program:main"
```
```python
def main():
print("Hello, World!")

Add `poetry` as a development dependency:

```bash
poetry add --group dev poetry
if __name__ == "__main__":
main()
```

Then, create a `launch.json` file (if it does not exists already) in the `.vscode` directory of your project with the following content:
Create a `launch.json` file in the `.vscode` directory of your project with the following content:

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug my_program",
"type": "python",
"type": "debugpy",
"request": "launch",
"console": "integratedTerminal",
"module": "poetry",
"args": [
"run",
"my_program",
// Add other arguments for your program here if the are required
]
"cwd": "${workspaceFolder}",
// Remember to adjust this setting
"module": "my_package.my_program",
"justMyCode": false,
// You can include other arguments for your program here if they are required
"args": []
}
]
}
Expand Down

0 comments on commit adf0771

Please sign in to comment.