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

use an environment variable to select port in launch.json #18841

Closed
giaco5988 opened this issue Apr 1, 2022 · 7 comments
Closed

use an environment variable to select port in launch.json #18841

giaco5988 opened this issue Apr 1, 2022 · 7 comments
Assignees
Labels
area-debugging feature-request Request for new features or functionality

Comments

@giaco5988
Copy link

Similar to microsoft/vscode-java-debug#962 I would to like use an environment variable DEBUG_PORT to set the port on which the python debugger is listening.

Now it does not seem possible because the port variable in launch.json needs to be a number. If I try setting an env variable, as in the code below, I get the following error:
}
"name": "Py listen",
"type": "python",
"request": "attach",
"listen": {
"host": "localhost",
"port": "${env:DEBUG_PORT}"
}
Screenshot 2022-04-01 at 10 27 32

@giaco5988 giaco5988 added triage-needed Needs assignment to the proper sub-team feature-request Request for new features or functionality labels Apr 1, 2022
@karthiknadig karthiknadig added needs PR area-debugging and removed triage-needed Needs assignment to the proper sub-team labels Apr 4, 2022
@karthiknadig karthiknadig self-assigned this Apr 4, 2022
@karthiknadig
Copy link
Member

@int19h debugpy supports string for port numbers right?

@giaco5988
Copy link
Author

Hi there, any news about this? Thank you

@giaco5988
Copy link
Author

giaco5988 commented Apr 25, 2022

Hi @int19h @karthiknadig , is it possible to know if this is currently supported? Thank you for your time

@int19h
Copy link

int19h commented Apr 25, 2022

We don't support it currently, but it would be a simple change. In fact, I think debugpy might as well support strings for all scalar properties, to enable substitutions everywhere.

@giaco5988
Copy link
Author

If you point me to the right part of the code, I could submit a PR. Best

@int19h
Copy link

int19h commented Apr 26, 2022

Awesome! We have a central place where type checking & conversions are performed on JSON being parsed; the code that does the actual parsing then calls into that while specifying the types it expects to receive, and various other constraints (e.g. optional or not).

I think it would be the best to tweak the type checker for numbers to allow (convertible) string values - and automatically convert them to the corresponding number before returning. This way we also get support for e.g. 64-bit integers. The relevant code is here:

https://github.com/microsoft/debugpy/blob/eaadb6c681d5375dae26093b93d239c019f0d2bc/src/debugpy/common/json.py#L106-L112

It just needs a branch for when validation without conversion fails, and one of the items in classinfo is a subtype of numbers.Number. This should cover your specific case, but it would also be nice to do the same for bool, on the oft chance that somebody might need to specify them via env vars also.

@giaco5988
Copy link
Author

Solved in microsoft/debugpy#921

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants