Skip to content

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

Closed

Description

@giaco5988

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

Activity

  1. karthiknadig commented on Apr 5, 2022

    @karthiknadig
    Member

    Pavel Minaev (@int19h) debugpy supports string for port numbers right?

  2. giaco5988 commented on Apr 11, 2022

    @giaco5988
    Author

    Hi there, any news about this? Thank you

  3. giaco5988 commented on Apr 25, 2022

    @giaco5988
    Author

    Hi Pavel Minaev (@int19h) Karthik Nadig (@karthiknadig) , is it possible to know if this is currently supported? Thank you for your time

  4. int19h commented on Apr 25, 2022

    @int19h

    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.

  5. giaco5988 commented on Apr 26, 2022

    @giaco5988
    Author

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

  6. int19h commented on Apr 26, 2022

    @int19h

    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.

  7. giaco5988 commented on May 19, 2022

    @giaco5988
    Author
  8. locked as resolved and limited conversation to collaborators on Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions