Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Debugging via -m does not work when the target is a package #991

Closed
brettcannon opened this issue Nov 7, 2018 · 21 comments
Closed

Debugging via -m does not work when the target is a package #991

brettcannon opened this issue Nov 7, 2018 · 21 comments
Assignees
Milestone

Comments

@brettcannon
Copy link
Member

[Found by CTI]

Environment data

  • PTVSD version: Whatever is in 2018.10.0-beta
  • OS and version: N/A
  • Python version (& distribution if applicable, e.g. Anaconda): N/A
  • Using VS Code or Visual Studio: 1.29.0-insider

Actual behavior

Message stating No module named pkg.

Expected behavior

Be able to debug pkg which is a package containing a __main__.py file.

Steps to reproduce:

  1. Create a package
  2. In that package define a __main__.py
  3. Set a breakpoint in that __main__.py
  4. Run the package via -m.
@int19h
Copy link
Contributor

int19h commented Nov 7, 2018

We don't handle module (or file) launch ourselves, and just pass it on to pydevd via --module. So it looks like there's an issue on pydevd side of things.

@karthiknadig
Copy link
Member

karthiknadig commented Nov 7, 2018

this looks same as #748. @fabioz has left an explanation for that case.

@int19h
Copy link
Contributor

int19h commented Nov 7, 2018

I'm not sure I follow the explanation in that bug. Python 3 can handle -m on namespace packages just fine.

@fabioz
Copy link
Contributor

fabioz commented Nov 7, 2018

@int19h @karthiknadig you're right, my fault, sorry about that... I think I tested #748 with 2.7 and not 3.7 and this works in python 3 (and #748 was a valid bug for Python 3 and is only invalid for Python 2).

@brettcannon
Copy link
Member Author

And just to be clear, this isn't just namespace packages but any package where this is a problem.

@karthiknadig
Copy link
Member

@fabioz Prioritize this issue over others.

fabioz added a commit to fabioz/ptvsd that referenced this issue Nov 8, 2018
@fabioz
Copy link
Contributor

fabioz commented Nov 8, 2018

I just checked here and creating a pkg/__main__.py and doing a launch for pkg did work properly for me...

I investigated a bit more, and having something as pkg/sub/__main__.py and launching pkg.sub failed for me... can you confirm if that's the case for you?

-- I created a pull request fixing the issue I found launching a module with dots in the name (#995), but if launching a module without dots in the name doesn't work for you it may be something different as I was not able to reproduce that.

@DonJayamanne
Copy link
Contributor

Note, this used to work in 2018.9.* version of the Python extension.
Back then PTVSD was launched using -m using the CLI, in the new version of the extension we have a launcher script that invokes the PTVSD api.

Hope this will help narrow down the issue.

@int19h
Copy link
Contributor

int19h commented Nov 12, 2018

I doubt that this matters, because from pydevd perspective it's going to see the same argv in its main both cases, with --module ... corresponding to the module being launched.

@DonJayamanne
Copy link
Contributor

Interesting, how then did it work in the past (older version of the extension with PTVSD 4?
This can only mean its a regression in PTVSD/PyDev.

karthiknadig pushed a commit that referenced this issue Nov 13, 2018
* Fix issue launching module with -m. #991

* Add launching test for Python 2.

* Fix for test in Python 2.6
@brettcannon
Copy link
Member Author

FYI someone ran into this and asked about it on Stack Overflow.

@karthiknadig karthiknadig removed this from the Nov 2018.2 milestone Nov 19, 2018
@brettcannon
Copy link
Member Author

And another post about the same issue.

@gramster gramster added this to the Dec 2018.2 milestone Dec 5, 2018
@fabioz
Copy link
Contributor

fabioz commented Dec 13, 2018

This should be fixed in master.

@janosh
Copy link

janosh commented Jan 23, 2019

@fabioz I'm still having trouble with this. Trying to debug ./src.main.py using the configuration

{
  "name": "Python: Module",
  "type": "python",
  "request": "launch",
  "module": "src.${fileBasenameNoExtension}"
}

only results in the error No module named src.main. Running python -m src.main works fine. Any ideas how to fix this?

@fabioz
Copy link
Contributor

fabioz commented Jan 23, 2019

@janosh, can you give details on the file structure you have for your project?

@karthiknadig
Copy link
Member

@janosh the fix for this is not in a public release yet. You can try with master for this.

@janosh
Copy link

janosh commented Jan 23, 2019

@fabioz If the fix isn't released yet, I guess we can skip troubleshooting.

@karthiknadig Can you estimate how far out the release is?

@karthiknadig
Copy link
Member

@janosh I will be making a release likely by this Friday.

@janosh
Copy link

janosh commented Jan 26, 2019

@karthiknadig How does the update process work? Does ptvsd update together with VS Code's Python extension?

@DonJayamanne
Copy link
Contributor

Yes

@janosh
Copy link

janosh commented Jan 26, 2019

@karthiknadig Thanks for the quick fix! Module debugging works great now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants