Skip to content

Spike - Use 'conda run' when debugging user code #8421

Description

Use conda run when debugging user code, sequel to the conda run work in #7696.
Modify the in-memory config (in the debug configuration resolver) to add 'conda run' if necessary, Karthik Nadig (@karthiknadig) is it only for launch or for both launch and attach?

Activity

  1. karthiknadig commented on Nov 7, 2019

    @karthiknadig
    Member

    These notes are for the python debug adapter only.

    • For attach there is no python involved from the extension side so there is nothing to do there. Also the communication happens over socket so it is not impacted by conda run weirdness with streaming stdin/stdout.
    • For launch:
      • The adapter itself should be started using the python binary. This is because the python adapter communicates with VS Code via stdin/stdout. conda run does not stream hence this prevents any communication between extension and adapter. So ensure DebugAdapterExecutable has the right path to the python executable.
      • The debug configuration that will be passed to the python debug adapter (via launch request) should use conda run as the pythonPath. This can be done in LaunchConfigurationResolver . Should look some thing like this for current file config for example:
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "pythonPath": "conda run" // <--- This is what you will have to add
            }

    I need to confirm this from the debugger side that we will use pythonPath if it is provided.
    /cc Pavel Minaev (@int19h) Don Jayamanne (@DonJayamanne) does this make sense?

  2. DonJayamanne commented on Nov 18, 2019

    @DonJayamanne

    "pythonPath": "conda run"

    I wouldn't use pythonPath for this. conda run isn't an executable it's a command. We might have to escape environment names or do other stuff...
    Why not be specific rather than using it for some other meaning.

    Today it's meant to point to the executable.
    I.e use another setting launchCommand pythonLaunchCmd

  3. added this to the FY20Q2 milestone on Nov 19, 2019
  4. int19h commented on Nov 20, 2019

    @int19h

    We deprecated "pythonPath" in 5.x - it's just "python" now, and it can be an array to allow for arguments to the interpreter.

    In this case, I think it's reasonable to say that "conda" is the interpreter (and it doesn't have to be fully spelled out - indeed, we default to "python" if nothing is specified, it's just that VSC always specifies it in practice), and "run" is an argument to that interpreter. So, this should do the right thing, and take care of proper escaping etc:

    "python": ["conda", "run"]

    ("conda run" as a single value won't work, because it will be quoted as a single command-line argument when the launcher performs run-in-terminal or spawn.)

  5. int19h commented on Nov 20, 2019

    @int19h

    Slight correction: if I'm understanding the docs right, you still need to tell Conda that you're running Python. So:

    "python": ["conda", "run", ..., "--", "python"]

    Where "..." is where environment name etc goes, as needed.

  6. DonJayamanne commented on Nov 20, 2019

    @DonJayamanne

    Note, there's no --

  7. karthiknadig commented on Nov 20, 2019

    @karthiknadig
    Member

    Adding this for ease of reference:

    conda run --help
    usage: conda-script.py run [-h] [-n ENVIRONMENT | -p PATH] [-v] [--dev]
                               [--debug-wrapper-scripts] [--cwd CWD]
                               ...
    
    Run an executable in a conda environment. [Experimental]
    
    Use '--' (double dash) to separate CLI flags for 'conda run' from CLI flags sent to
    the process being launched.
    
    Example usage:
    
        $ conda create -y -n my-python-2-env python=2
        $ conda run -n my-python-2-env python --version
    
    Options:
    
    positional arguments:
      executable_call       Executable name, with additional arguments to be
                            passed to the executable on invocation.
    
    optional arguments:
      -h, --help            Show this help message and exit.
      -v, --verbose         Use once for info, twice for debug, three times for
                            trace.
      --dev                 Sets `CONDA_EXE` to `python -m conda`, assuming the
                            CWD containsthe root of conda development sources.
                            This is mainly for useduring tests where we test new
                            conda source against old Pythonversions.
      --debug-wrapper-scripts
                            When this is set, where implemented, the shell wrapper
                            scriptswill echo to stderr a lot of debugging
                            information.
      --cwd CWD             Current working directory for command to run in.
                            Defaults to cwd
    
    Target Environment Specification:
      -n ENVIRONMENT, --name ENVIRONMENT
                            Name of environment.
      -p PATH, --prefix PATH
                            Full path to environment location (i.e. prefix).
    
  8. int19h commented on Nov 20, 2019

    @int19h

    Per the docs, -- is not required, but I think it's safer to always use it. It'll also make the command line clearer in the terminal, especially once we add all the ptvsd switches in there.

  9. karrtikr commented on Nov 22, 2019

    @karrtikr

    I was trying out this launch config,

    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "python": ["conda", "run", "-n","base", "--", "python"]
    }
    

    but run into this error.
    image
    Seems that I am not able to add "python" in the launch config.

  10. karrtikr commented on Nov 22, 2019

    @karrtikr
  11. int19h commented on Nov 22, 2019

    @int19h

    The error message above is because the extension itself injects "pythonPath" into the config, and ptvsd doesn't know which one it is supposed to use when it sees both.

  12. karrtikr commented on Nov 22, 2019

    @karrtikr

    Yes, I corrected that. It's now blocked on the ptvsd issue.

  13. karthiknadig commented on Nov 22, 2019

    @karthiknadig
    Member

    Looking at the logs on that debugger issue, the debuggee is being launched using conda run.

    Command line: [
                     "conda",
                     "run",
                     "-n",
                     "base",
                     "python",
                     "c:\\Users\\karraj\\Desktop\\vscode-python\\pythonFiles\\lib\\python\\new_ptvsd\\wheels\\ptvsd",
                     "--client",
                     "--host",
                     "127.0.0.1",
                     "--port",
                     "54984",
                     "c:\\Users\\karraj\\Desktop\\yo\\tests\\test_one.py"
                 ]
    

    That is all the we want the extension to do, i.e., send the right launch configuration. The issue has been fixed and is available in master of ptvsd.

  14. karrtikr commented on Nov 22, 2019

    @karrtikr
  15. karthiknadig commented on Nov 22, 2019

    @karthiknadig
    Member

    Kartik Raj (@karrtikr) It looks like it is still using 5.0.0a8 not master. You may have to delete the new_ptvsd directory. then run the following commands, from the extension project root.

    pip install -t .\pythonFiles\lib\python\new_ptvsd\no_wheels git+https://github.com/microsoft/ptvsd.git
    pip install -t .\pythonFiles\lib\python\new_ptvsd\wheels git+https://github.com/microsoft/ptvsd.git
    

    The version looks like this when you install from master:

    >py -3.7
    Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ptvsd
    >>> ptvsd.__version__
    '5.0.0a8+1.gad36606'
    >>>
    
  16. karrtikr commented on Nov 22, 2019

    @karrtikr

    Not sure what was happening. But I deleted the directory multiple times and it's now using master.

    image

    The prior error is gone now. The extension is sending the right launch configuration, but I was expecting to see conda run... when I launch the debugger. Is this expected?

    Logs

    ptvsd.adapter-12800.log
    ptvsd.launcher-10280.log
    ptvsd.server-16972.log
    debugger.vscode_775fa546-2dd6-4cea-a4db-35599cf22df4.log

  17. karthiknadig commented on Nov 22, 2019

    @karthiknadig
    Member

    Yep that is as expected. User code is actually running in using conda run if you see launcher.logs

                 Command line: [
                     "conda",
                     "run",
                     "-n",
                     "base",
                     "python",
                     "c:\\Users\\karraj\\Desktop\\vscode-python\\pythonFiles\\lib\\python\\new_ptvsd\\wheels\\ptvsd",
                     "--client",
                     "--host",
                     "127.0.0.1",
                     "--port",
                     "51637",
                     "c:\\Users\\karraj\\Desktop\\wheels\\mytest.py"
                 ]
    
  18. karthiknadig commented on Nov 22, 2019

    @karthiknadig
    Member

    The launcher itself gets launched using the same python executable as the adapter. This is so that we don't have mismatch issues since both adapter and launcher are tightly coupled. User code will be started using the conda.

  19. karrtikr commented on Nov 25, 2019

    @karrtikr

    Listed the findings of the spike in #8422 (comment). Closing the spike now.

  20. ghost removed
    needs proposalNeed to make some design decisions
    on Nov 25, 2019
  21. locked as resolved and limited conversation to collaborators on Dec 2, 2019
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions