Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to debug with Debugpy #7592

Open
4 tasks done
delucca opened this issue Mar 2, 2023 · 10 comments · May be fixed by #9708
Open
4 tasks done

Unable to debug with Debugpy #7592

delucca opened this issue Mar 2, 2023 · 10 comments · May be fixed by #9708
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@delucca
Copy link

delucca commented Mar 2, 2023

  • Poetry version: 1.4.0

  • Python version: 3.10

  • OS version and name: Arch Linux

  • I am on the latest stable Poetry version, installed using a recommended method.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • I have consulted the FAQ and blog for any relevant entries or release notes.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Following up on this issue, for some reason nvim-dap is not being able to attach a debugger if I'm running an application using Poetry

If I run using Python directly it works, but using Poetry it automatically closes. If I run from within a Poetry shell, it bootstraps the debugger, but whenever I set breakpoints debugpy throws an error

You can see the details on the original issue.

To replicate the issue you just need to do the following:

  1. Create the basic setup without Poetry:
python -m venv venv
venv/bin/python -m pip install Flask
  1. Create a vscode/launch.json:
{
   "version": "0.2.0",
   "configurations": [
       {
           "type": "python",
           "request": "launch",
           "name": "Flask",
           "module": "flask",
           "args": ["--app", "foo", "run"],
           "console": "integratedTerminal"
       }
   ]
}
  1. Create foo.py:
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "<p>Hello World</p>"

After this, run in your IDE, attach a debugger to it and test. You'll see that it works.

Now, do the same, but on the setup step do the setup using Poetry. After this, tried running the debugger with the Poetry setup. It would either not work (if you try using it with poetry run) or it will not be able to set any breakpoints (if you try using poetry shell)

@delucca delucca added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Mar 2, 2023
@dimbleby
Copy link
Contributor

dimbleby commented Mar 2, 2023

You don't have to poetry run everything! Just activate the virtual environment yourself and run things directly.

@delucca
Copy link
Author

delucca commented Mar 2, 2023

@dimbleby I think you're mixing this issue with the other. For this issue I'm not using poetry run (I've never said I was in this specific issue)

For this issue, even in a Poetry shell, the issue is the same. If I install the application with Poetry, Flask debugger doesnt work for some reason (with Nvim). If I install the same application without using Poetry (in a common venv) it works

To be 100% clear, in the Poetry shell the debugger is able to bootstrap, but setting breakpoints breaks the application for some reason.

@dimbleby
Copy link
Contributor

dimbleby commented Mar 2, 2023

all you have given us here is a link to another issue, in which the configuration shows that you are calling poetry run

	program = "${env:PYTHON_VENV_PATH}/bin/poetry",
	args = {
		"run",
		"flask",
		"--no-debug",
		"run",
	},

if you're now saying that's not what you're doing then I don't even

@delucca
Copy link
Author

delucca commented Mar 2, 2023

@dimbleby as I've mentioned, the same thing happens if you open a shell instead of using poetry run (as I've mentioned in the issue)

@dimbleby
Copy link
Contributor

dimbleby commented Mar 2, 2023

do you mean poetry shell? I wouldn't do that either: just activate the virtual environment in the regular way and run things directly.

This report is too involved and too confused: if you can reduce it to something that reproduces without having to install neovim and dap and flask then you'll have a better chance of someone taking an interest in it.

@delucca
Copy link
Author

delucca commented Mar 2, 2023

@dimbleby you can use the same example from the original issue (on the last comment from the nvim-dap-python author)

I can create a github repo if you want, but essentially you just need to launch any simple Python application. Unfortunately I don't see any possible alternative of exploring this issue without having to install nvim and nvim-dap, since the issue is specifically a problem with debugging in that specific tool 😄

@dimbleby
Copy link
Contributor

dimbleby commented Mar 2, 2023

you've linked to a comment which says that "it works for me.". Plainly that is not a way to reproduce your problem.

I'm gonna duck out, this is going nowhere.

Maybe I'm being grumpy but I think this is good advice: you'll have a better chance of getting help from people if you make it as easy as possible for them. Links to complicated issues, with not very much information, and contradictory comments... are not that.

@delucca
Copy link
Author

delucca commented Mar 2, 2023

@dimbleby if you really wants to help and understand the problem, take some time to read the original issue.

It isn't a "it works for me" issue. It contains a minimal reproduction. You just need to duplicate that code on your machine and run it, with and without using Poetry

As I've mentioned, if you want I can create a repository to simplify, but it is just a single file, I don't see any point of creating a repo for that

@delucca delucca changed the title Unable to use Flask debugger Unable to debug with Debugpy Mar 2, 2023
@vantaboard
Copy link

vantaboard commented Jan 17, 2024

I found a really nice way of doing this after banging my head on my desk over it.

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug: start",
            "type": "debugpy",
            "request": "launch",
            "module": "poetry",
            "args": [
                "run",
                "start"
            ],
            "justMyCode": false
        }
    ]
}

poetry.toml

[virtualenvs]
in-project = true

And then the final touch is to run

poetry add --group dev poetry

which bootstraps poetry and enables its use with debugpy without any of the extra headache of switching your environment, etc.

@TheSven73
Copy link
Contributor

Do the instructions in #9708 (comment) fix this issue?

If not, please provide clear instructions on how to reproduce, with sample code, configs, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants