Skip to content

Add parsing args from environment #1624

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

Merged
merged 18 commits into from
Jul 26, 2024
Merged

Add parsing args from environment #1624

merged 18 commits into from
Jul 26, 2024

Conversation

AdamYoblick
Copy link
Contributor

@AdamYoblick AdamYoblick commented Jul 15, 2024

Fixes #1612

  • Added reading args from the environment. Command line args always take precedence.
  • Added unit tests for environment args

Testing was done in several ways:

  1. I added multiple unit tests for the new code that reads from the environment, as well as made sure that existing tests were passing.
  2. I debugged a python file locally, pointing vscode at my local debugpy source, using the following launch.json config:
{
      "name": "Python Debugger: Current File WITH ARGS",
      "type": "debugpy",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "debugAdapterPath": "E:/repos/github/debugpy/src/debugpy/adapter",
      "args" : ["--msg", "Hello World"]
    },

I verified that these extra args were passed to the file being run and that breakpoints could be hit. I also verified that this worked with no args.

  1. I opened a command prompt and starting debugpy in listen mode:

python E:\repos\github\debugpy\src\debugpy --listen 5678 --wait-for-client "C:\Users\advolker\OneDrive - Microsoft\Desktop\pythonTest\infiniteLoop.py"

Then I attached through vscode using the following launch.json config:

    {
      "name": "Attach",
      "type": "python",
      "request": "attach",
      "connect": {
        "port": 5678,
      }  

Breakpoints worked just fine.

  1. I did the same test as above, but I set the options --listen 5678 and --wait-for-client in the environment before running debugpy, like this:

set DEBUGPY_EXTRA_ARGV=--listen 5678 --wait-for-client

Then I started debugpy from the same command prompt with only the target specified. The other options were read from the environment:

python E:\repos\github\debugpy\src\debugpy "C:\Users\advolker\OneDrive - Microsoft\Desktop\pythonTest\infiniteLoop.py"

Then I attached through vscode in the same way as the previous step. Breakpoints worked just fine.

rchiodo

This comment was marked as resolved.

@AdamYoblick

This comment was marked as resolved.

@AdamYoblick AdamYoblick marked this pull request as ready for review July 17, 2024 19:46
@AdamYoblick AdamYoblick requested a review from a team as a code owner July 17, 2024 19:46
@AdamYoblick

This comment was marked as resolved.

@@ -71,7 +82,7 @@ def test_targets(cli, target_kind, mode, address, wait_for_client, script_args):
expected_options = {
"mode": mode,
"target_kind": target_kind,
"wait_for_client": bool(wait_for_client),
"wait_for_client": False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems off? The parameter is being skipped now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a refactor with no functional difference. It defaults to false, so in the case of the empty string, the conditional on line 96 will eval to false. But in the case where it has a value, line 96 will eval to true, and the default value will be overridden on line 98.

AdamYoblick and others added 3 commits July 25, 2024 16:02
Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
@AdamYoblick AdamYoblick merged commit 820d21e into main Jul 26, 2024
19 checks passed
@AdamYoblick AdamYoblick deleted the extra_argv_envvar branch July 26, 2024 15:07
@AdamYoblick AdamYoblick added the Fixed in next release This issue has been fixed, but won't be available to customers until the next release. label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in next release This issue has been fixed, but won't be available to customers until the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terminal debug experience in Python Debbuger Extension
3 participants