intellij-community icon indicating copy to clipboard operation
intellij-community copied to clipboard

Patch path so it reflects changes in patched arguments

Open superjkl opened this issue 1 year ago • 5 comments

Given arguments in the form of: os.execv("../file.py", ["../file.py", arg1, ...]) They will be patched to: os.execv("../file.py", ["python", "../../pydevd.py", "--host", "--port", "--file", "../file.py", arg1, ...]) This will end up with os.execv thinking the actual executable is "../file.py" thus running it instead of pydevd resulting in the error file.py: error: unrecognized arguments: host, port

I think this bug was introduced by commit 7ec061b4182a183ef3193a24ecb9c6b0490799ad so I was careful to make sure my changes wouldn't reintroduce the bug from PY-37311.

superjkl avatar Mar 07 '23 22:03 superjkl

@superjkl hello! Thank you for your PR. Could you please clarify your OS and version of Python? I can't reproduce this bug.

EliseevEgor avatar May 08 '23 08:05 EliseevEgor

So sorry for leaving out that crucial info. OS: Centos 7.9 Python: 2.7

superjkl avatar May 08 '23 22:05 superjkl

Thanks for the info!

How do you make a .py file executable? Are you adding #!/usr/bin/env python?

EliseevEgor avatar May 09 '23 12:05 EliseevEgor

Yes both the original script and subprocess script use #!/usr/bin/env python

Here's a small example I can replicate the bug with:

tester1.py

#!/usr/bin/env python
import os
args = [os.path.abspath('./tester2.py')]
os.execv(args[0], args)

tester2.py

#!/usr/bin/env python
import argparse

a = argparse.ArgumentParser()
a.add_argument('--option')
a.parse_args()

superjkl avatar May 09 '23 14:05 superjkl

Thank you!

EliseevEgor avatar May 09 '23 14:05 EliseevEgor