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

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

Closed
kimadeline opened this issue Nov 7, 2019 · 18 comments
Closed

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

kimadeline opened this issue Nov 7, 2019 · 18 comments
Assignees
Labels
area-debugging debt Covers everything internal: CI, testing, refactoring of the codebase, etc.

Comments

@kimadeline
Copy link

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, @karthiknadig is it only for launch or for both launch and attach?

@kimadeline kimadeline added debt Covers everything internal: CI, testing, refactoring of the codebase, etc. area-debugging needs proposal Need to make some design decisions labels Nov 7, 2019
@DonJayamanne DonJayamanne mentioned this issue Nov 7, 2019
24 tasks
@karthiknadig
Copy link
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 @int19h @DonJayamanne does this make sense?

@DonJayamanne
Copy link

"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

@luabud luabud added this to the FY20Q2 milestone Nov 19, 2019
@int19h
Copy link

int19h commented Nov 20, 2019

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.)

@int19h
Copy link

int19h commented Nov 20, 2019

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.

@DonJayamanne
Copy link

Note, there's no --

@karthiknadig
Copy link
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).

@int19h
Copy link

int19h commented Nov 20, 2019

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.

@karrtikr karrtikr assigned karrtikr and unassigned karrtikr Nov 21, 2019
@karrtikr
Copy link

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.

@karrtikr
Copy link

Blocked on microsoft/ptvsd#1944

@int19h
Copy link

int19h commented Nov 22, 2019

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.

@karrtikr
Copy link

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

@karthiknadig
Copy link
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.

@karrtikr karrtikr self-assigned this Nov 22, 2019
@karrtikr
Copy link

karrtikr commented Nov 22, 2019

debugger.vscode_b7868e94-7f63-49ed-a39b-85c511d76e0e.log
ptvsd.adapter-756.log
ptvsd.launcher-24048.log
ptvsd.server-22160.log

I get the same error on master of ptvsd as well. Here the logs again.

@karthiknadig
Copy link
Member

karthiknadig commented Nov 22, 2019

@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'
>>>

@karrtikr
Copy link

karrtikr commented Nov 22, 2019

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

@karthiknadig
Copy link
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"
             ]

@karthiknadig
Copy link
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.

@karrtikr
Copy link

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

@ghost ghost removed the needs proposal Need to make some design decisions label Nov 25, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging debt Covers everything internal: CI, testing, refactoring of the codebase, etc.
Projects
None yet
Development

No branches or pull requests

6 participants