classification
Title: Run modules with pdb
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ericvw, jason.coombs, mariocj89, ncoghlan
Priority: normal Keywords: patch

Created on 2017-12-03 13:36 by mariocj89, last changed 2018-02-02 05:16 by mariocj89. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4752 merged mariocj89, 2017-12-07 20:25
PR 5111 merged mariocj89, 2018-01-06 10:35
PR 5474 merged mariocj89, 2018-02-02 05:16
PR 5474 merged mariocj89, 2018-02-02 05:16
Messages (10)
msg307513 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2017-12-03 13:36
Since PEP 338 we can run python modules as a script via `python -m module_name` but there is no way to run pdb on those (AFAIK).

The proposal is to add a new argument "-m" to the pdb module to allow users to run `python -m pdb -m my_module_name`

This is especially useful when working on cli tools that use entrypoints in setup.py, as there is no other way to run them.


I have a WIP here: https://github.com/mariocj89/cpython/commit/f47d1b779333657d7d87b21db841d5d3ad6cfa5c

Haven't sent the PR as I am still polishing some issues. If it sounds like a good idea I'll clean it up and open the PR.
msg309493 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-05 07:44
Linking back to the overall RFE for improved executable module support for standard library modules that run other scripts: https://bugs.python.org/issue9325
msg309540 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-06 07:53
New changeset 9f1e5f1b7f074e026843a5d70834233a95a6bf9d by Nick Coghlan (Mario Corchero) in branch 'master':
bpo-32206: Pdb can now run modules (GH-4752)
https://github.com/python/cpython/commit/9f1e5f1b7f074e026843a5d70834233a95a6bf9d
msg309541 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-06 07:55
Thanks for the patch!
msg309548 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-06 14:57
Re-opening for the CLI help updates.
msg310780 - (view) Author: Jason R. Coombs (jason.coombs) * (Python committer) Date: 2018-01-26 18:10
Thanks for creating this functionality. I'm so excited to use it that I've published a backport [https://pypi.org/project/backports.pdb], which seems to work for at least the basic use cases on Python 2.7+.
msg310882 - (view) Author: Jason R. Coombs (jason.coombs) * (Python committer) Date: 2018-01-27 19:34
Adopting the backport, I believe I've found a defect. I filed the defect with the backport as [backports.pdb 1](https://github.com/jaraco/backports.pdb/issues/1).

Essentially, the issue is that `__package__` gets set to the module name instead of the package name, causing issues with `from .mod` imports.

Feel free to take the relevant parts of the fix in the backport to adjust the implementation here, and definitely let me know if you think the adjustment I've made is somehow incorrect.

Full disclosure, I have not tested the canonical implementation in Python 3.7, only the backport in Python 3.6 and 2.7.

Please let me know if you would like me to file a separate issue.
msg310883 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2018-01-27 19:38
Hi Jason, thanks a lot! 

I’ll have a look to the bug you reported on Monday. Out for holidays atm ^^
msg310916 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-28 04:58
New changeset fcf8b4c1022bc2d2f84dcef5d72eabf40a25ea19 by Nick Coghlan (Mario Corchero) in branch 'master':
bpo-32206: Update pdb usage to include new module option (GH-5111)
https://github.com/python/cpython/commit/fcf8b4c1022bc2d2f84dcef5d72eabf40a25ea19
msg310918 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-28 05:07
I checked the original PR, and I'm pretty sure the reference implementation is going to have the same bug.

To keep the NEWS entries clear (since the buggy implementation already shipped in the alpha releases), I've created a new issue here: https://bugs.python.org/issue32691
History
Date User Action Args
2018-02-02 05:16:57mariocj89setpull_requests: + pull_request5322
2018-02-02 05:16:57mariocj89setpull_requests: + pull_request5321
2018-02-01 16:25:25mariocj89setpull_requests: - pull_request5301
2018-02-01 15:58:04mariocj89setpull_requests: + pull_request5301
2018-01-28 05:07:16ncoghlansetstatus: open -> closed
resolution: fixed
messages: + msg310918

stage: needs patch -> resolved
2018-01-28 04:58:50ncoghlansetmessages: + msg310916
2018-01-27 19:38:22mariocj89setmessages: + msg310883
2018-01-27 19:34:36jason.coombssetmessages: + msg310882
2018-01-26 18:10:03jason.coombssetmessages: + msg310780
2018-01-26 16:33:32jason.coombssetnosy: + jason.coombs
2018-01-06 14:57:09ncoghlansetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg309548

stage: resolved -> needs patch
2018-01-06 10:35:22mariocj89setpull_requests: + pull_request4978
2018-01-06 07:55:20ncoghlansetstatus: open -> closed
type: enhancement
messages: + msg309541

resolution: fixed
stage: patch review -> resolved
2018-01-06 07:53:09ncoghlansetmessages: + msg309540
2018-01-05 07:44:21ncoghlansetnosy: + ncoghlan
messages: + msg309493
2018-01-05 07:34:30ncoghlanlinkissue9325 dependencies
2017-12-07 20:25:10mariocj89setkeywords: + patch
stage: patch review
pull_requests: + pull_request4654
2017-12-03 17:20:13ericvwsetnosy: + ericvw
2017-12-03 13:36:40mariocj89create