Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Allow -P to work for debugpy #1755

Closed
prumand opened this issue Sep 6, 2023 · 6 comments
Closed

Allow -P to work for debugpy #1755

prumand opened this issue Sep 6, 2023 · 6 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@prumand
Copy link

prumand commented Sep 6, 2023

Type: Bug

Behaviour

Expected vs. Actual

Adding the pythonArgs -P or -I to my launch config and call a script in module:

import sys
print(sys.path)

Expected:
Folder of file not in sys.path

Actual:
Folder of file is in sys.path

Steps to reproduce:

https://github.com/prumand/vscdoe-pythonargs-not-used

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.4 and 3.9.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry and plain macos
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

['${workdspaceFodler}/test', '....']

User Settings


languageServer: "Pylance"

Extension version: 2023.14.0
VS Code version: Code 1.81.1 (Universal) (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:20:33.924Z)
OS version: Darwin arm64 22.6.0
Modes:

System Info
Item Value
CPUs Apple M1 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 1, 1, 2
Memory (System) 16.00GB (0.05GB free)
Process Argv --crash-reporter-id 04e8682b-ee5a-4a44-a9ad-554467338aba
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30803845
282f8724:30602487
89544117:30613380
vscrpc:30673769
2i9eh265:30646982
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
asynctok:30821568
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572
dsvsc015cf:30829746

@karthiknadig karthiknadig removed their assignment Dec 8, 2024
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Dec 8, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Dec 8, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Dec 9, 2024

@karthiknadig isn't this handled by the extension? Those args are passed to python before running debugpy?

@rchiodo
Copy link
Contributor

rchiodo commented Dec 9, 2024

No never mind, they're passed by the launcher.

@karthiknadig
Copy link
Member

No never mind, they're passed by the launcher.

That is correct.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 9, 2024

Debugpy is passing that argument to debugpy, but it's not running your code. It's running the debugger:

Image

Which likely is not your intent. You want -P to skip the script's folder on the sys.path. In this case it's skipping the folder where the debugpy adapter is located.

I think this would require a custom way to modify the sys.path before starting the app. Or you could modify your use case to use attach and launch your app with -P.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 9, 2024

Meaning -P is working as expected:

Help from python.org for -P.

-P
Don’t prepend a potentially unsafe path to [sys.path](https://docs.python.org/3/library/sys.html#sys.path):

python -m module command line: Don’t prepend the current working directory.

python script.py command line: Don’t prepend the script’s directory. If it’s a symbolic link, resolve symbolic links.

python -c code and python (REPL) command lines: Don’t prepend an empty string, which means the current working directory.

@rchiodo rchiodo changed the title Add interpreter options Allow -P to work for debugpy Dec 9, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Dec 9, 2024

Transferring to a discussion for up votes.

@microsoft microsoft locked and limited conversation to collaborators Dec 9, 2024
@rchiodo rchiodo converted this issue into discussion #1759 Dec 9, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

5 participants