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

Add special python args to subprocess patch #465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nielstron
Copy link

Awesome project! I was recently adapting the patch utilities for subprocesses for a personal project and noticed that in some particular cases (i.e. when tracing tox) the patches don't work. The issue was resolved when I added the following python commands that take parameters (-X, -W and --check-hash-based-pycs) as special cases - otherwise their argument would be parsed as "script" parameter.

Example
python3 -X dev -m pytest would be split to python3 -X (patch-script) dev -m pytest instead of the correct python3 -X dev (patch-script) -m pytest.

@gaogaotiantian
Copy link
Owner

I don't have my dev machine near me recently so I'll have to test this myself later. However, I don't believe the solution is the right way to go. I believe the current regex is meant to detect the actual script part - so it should detect the -m pytest part and insert all the other py_args before -m. If it's not, then we should fix the regex, instead of adding an exception for a specific option. I believe it's because the file regex is too loose on detecting files.

@nielstron
Copy link
Author

nielstron commented Aug 11, 2024

I see and I tried this before, however I think it's not so natural using the current approach. For example a valid parameterization for python is python3 -X dev.

The current approach splits the arguments by space and thus encounters first -X then dev. But it is perfectly possible that there is a script in the current directory with the filename dev. To distinguish the two you would need to suddenly look back in the arg history.

But feel free to try and implement it the other way around.

@gaogaotiantian
Copy link
Owner

Okay that makes sense. But in that case you probably need to take out all the dash options with arguments before identifying the file. I can work on this later when I finish my moving.

@gaogaotiantian
Copy link
Owner

Hi, sorry it took me so long to get back at this. I think the code should work fine. Do you mind adding a regression test for this?

@nielstron
Copy link
Author

I'll have a look. Any suggestions on a related test case that I could adapt?

@gaogaotiantian
Copy link
Owner

It depends on how difficult it is to do a minimum repro. If you can repro this with a normal script on command line usage, checkout tests in test_cmdline.py, you can put the test in that file or test_regression.py. If it's hard to do it normally, check out test_patch.py, there are some coverage tests in that file to test corner cases. Or maybe you can do both :). I think in test_patch.py there are tests specifically for parsing subprocess args.

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

Successfully merging this pull request may close these issues.

2 participants