You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spike - Activation script sent to terminal after debugger starts (Use Conda run) #5664
To try this out, I added the following to src/client/debugger/debugAdapter/DebugClients/LocalDebugClient.ts (right before the existing const termArgs: ... line in launchExternalTerminal():
A. DebugSession.runInTerminalRequest() does not support re-using a terminal from an earlier call; so we can't just call that API once for activation, followed by once for the debugger
B. runInTerminalRequest() does not support sending multiple commands (sort of)
C. we can't use runInTerminalRequest() directly for activation commands (they do things like "source" and runInTerminalRequest() prepends the env vars to the "command" string that gets executed, which is incompatible with "source")
D. getting the activation commands to the debugger isn't trivial
So we have a few options at this point if we want to activate environments:
make the status quo work (via TerminalAutoActivation)
suboptions dealing with problem D:
a. pass the activation commands via the launch config
- requires getting them into the config dynamically
b. use a custom DAP request to get the activation commands from the extension
- only custom events are currently supported?
c. use a custom DAP event to request the activation commands from the extension
- we already have the machinery in the extension for custom DAP events
- how to get them back? through a file?
suboptions to deal with problems A, B, and C:
d. wrap activation commands and debugger command in a script to run via runInTerminalRequest()
- requires a temporary shell script written to disk
- requires quoting, etc.
e. add a static script that decodes its args into multiple commands and runs them
- takes advantage of VSC arg quoting, etc.
f. (upstream) get runInTerminalRequest() updated to solve the problem
- support multiple requests against the same terminal (by PID or some other ID)
- (or support passing multiple commands in a single request)
- support "source", etc commands (move env vars to end?)
g. chain the commands (e.g. with && or ;) and wrap the whole thing in e.g. sh -c ""
suboptions to deal with problems A, and B:
h. chain commands, e.g. with && or ;
- env vars might only apply to the first command (need to check)
suboptions to deal with problems C:
i. chain the activation command with a preceding noop (e.g. true && source ...)
- env vars might only apply to the first command (need to check)
do as much as possible in the extension
not affected by the problems from above
solution (in debug adapter):
add a way to trigger starting the debugger from the extension (via the debug adapter protocol)
use a custom DAP request
only custom events are currently supported?
use a custom DAP event
we already have the machinery in the extension for custom DAP events
how to indicate ready? through a file?
trigger that event/request (send debugger command and env vars)
wait for the debugger to start (necessary for some internal VSC debugger functionality)
solution (in extension)
add DAP event handler
create terminal
activate environment in terminal (like normal)
run debugger command in terminal
notify debug adapter
Might be necessary:
generate activation commands as multiple argv (string[][]) instead of a single string
changed the title [-]Activation script sent to terminal after debugger starts[/-][+]Spike - Activation script sent to terminal after debugger starts[/+]on Jul 31, 2019
changed the title [-]Spike - Activation script sent to terminal after debugger starts[/-][+]Spike - Activation script sent to terminal after debugger starts (Use Conda run)[/+]on Jul 31, 2019
Activity
9 remaining items
ericsnowcurrently commentedon Jul 9, 2019
To try this out, I added the following to
src/client/debugger/debugAdapter/DebugClients/LocalDebugClient.ts(right before the existingconst termArgs: ...line inlaunchExternalTerminal():Unfortunately, it opened a separate terminal for each request. We we're back to the drawing board.
The only other realistic solutions (without upstream changes):
ericsnowcurrently commentedon Jul 15, 2019
I ran into the following problems:
A.
DebugSession.runInTerminalRequest()does not support re-using a terminal from an earlier call; so we can't just call that API once for activation, followed by once for the debuggerB.
runInTerminalRequest()does not support sending multiple commands (sort of)C. we can't use
runInTerminalRequest()directly for activation commands (they do things like "source" andrunInTerminalRequest()prepends the env vars to the "command" string that gets executed, which is incompatible with "source")D. getting the activation commands to the debugger isn't trivial
So we have a few options at this point if we want to activate environments:
TerminalAutoActivation)a. pass the activation commands via the launch config
- requires getting them into the config dynamically
b. use a custom DAP request to get the activation commands from the extension
- only custom events are currently supported?
c. use a custom DAP event to request the activation commands from the extension
- we already have the machinery in the extension for custom DAP events
- how to get them back? through a file?
d. wrap activation commands and debugger command in a script to run via
runInTerminalRequest()- requires a temporary shell script written to disk
- requires quoting, etc.
e. add a static script that decodes its args into multiple commands and runs them
- takes advantage of VSC arg quoting, etc.
f. (upstream) get
runInTerminalRequest()updated to solve the problem- support multiple requests against the same terminal (by PID or some other ID)
- (or support passing multiple commands in a single request)
- support "source", etc commands (move env vars to end?)
g. chain the commands (e.g. with
&∨) and wrap the whole thing in e.g.sh -c ""h. chain commands, e.g. with
&∨- env vars might only apply to the first command (need to check)
i. chain the activation command with a preceding noop (e.g.
true && source ...)- env vars might only apply to the first command (need to check)
Might be necessary:
string[][]) instead of a singlestringspawnandOther notes:
runInTerminalRequestworks like a cross between child_process.exec and spawnargs: string[]), but the eventual execution is a single string sent to the shell&&as an arg, since it gets run in a shell (but I'm not sure what guarantees we havestring[]command/argssourceterminal.sendTest()serverReadyActionlaunch config depends on the terminal identified by therunInTerminalrequest--so it could mean that we have to userunInTerminal(but other extensions don't run in terminal, so maybe not)[-]Activation script sent to terminal after debugger starts[/-][+]Spike - Activation script sent to terminal after debugger starts[/+]karrtikr commentedon Jul 31, 2019
Spike
conda runwork in terminal (works, this is a documented solution)conda runin background process work (spawn('conda run xyz.py')), i.e. we're not running in a terminal.<fully qualified path to conda executable> runwork` in terminal<fully qualified path to conda executable> runwork` in background process.[-]Spike - Activation script sent to terminal after debugger starts[/-][+]Spike - Activation script sent to terminal after debugger starts (Use Conda run)[/+]