Vscode-jupyter: DS: Support the ability to take input from users for executed cells.

Created on 12 Apr 2019  Â·  13Comments  Â·  Source: microsoft/vscode-jupyter

This is what Jupyter shows:

image.png

We show this.

image.png

Most helpful comment

Same backend, so it will work for the interactive window too.

All 13 comments

It would be great to have this fixed in VS Code.

Is anyone working on this now?

No sorry this is not a high priority at the moment. We do accept outside PR's though if you'd like to try implementing it.

We try to prioritize stuff based on feedback, so up voting certainly moves things up the priority queue.

Are there any updates on this issue?
It would be great to have this feature implemented.

Sorry it's not being looked at the moment. Feel free to up vote it. We generally work on stuff based on the number of votes and comments items have.

Would love to have this implemented as well... we're not allowed to store data or passwords locally at work, so we need to query the database each time we run out code — the lack of this feature prevents us from using the VSCode Jupyter support.

Moving back to triage. There's a LOT of up votes on this one.

I got the same issue today.

  • Extension Name: python
  • Extension Version: 2019.11.41015-dev
  • OS Version: Windows_NT x64 10.0.18362
  • VSCode version: 1.39.0-insider

input_error

sending back to triage to re-evaluate

Not sure how feasible, but I would assume this should approx. work as follows:

  1. If input(prompt) is called, open an input in VS Code, with the text being prompt (similar to the screenshot below from the Azure IoT Extension)

image

  1. Take the user input and feed it to the python runtime.

The details could be more complicated than I assume:

  1. prompt not available before execution
  2. Cells are executed in one go and the result is parsed - this could occur in the middle of a cell
  3. String encoding issues (special characters, newlines, tabs...)
  4. Signals (Ctrl C, Ctrl D, ...)

Therefore, an interim solution could be approximately the following:

Add some syntax that is recognized by the VS Code extension but ignored else, e.g.:

a = input('Python uses this prompt: ') #%I 'VS Code uses this prompt instead'

could be parsed, the prompts for the user displayed and the code that is sent to the jupyter cell for execution is rewritten as

a = r"[result from above]" # beware of r'\' and a few similar issues

This would be somewhat ugly and prone to breaking but maybe good enough as an interim solution.

I'm guessing 3 days to implement this.

I _think_ all we need to do is change this code to allow_stdin:

    private generateRequest = (code: string, silent?: boolean): Kernel.IFuture | undefined => {
        //traceInfo(`Executing code in jupyter : ${code}`);
        try {
            const cellMatcher = new CellMatcher(this.configService.getSettings().datascience);
            return this.session ? this.session.requestExecute(
                {
                    // Remove the cell marker if we have one.
                    code: cellMatcher.stripFirstMarker(code),
                    stop_on_error: false,
                    allow_stdin: false,
                    store_history: !silent // Silent actually means don't output anything. Store_history is what affects execution_count
                },
                true
            ) : undefined;
        } catch (exc) {
            // Any errors generating a request should just be logged. User can't do anything about it.
            traceError(exc);
        }

        return undefined;
    }

Then provide UI to do the input.

I have this working. Here's what it will look like:
input

Supports straight input and password based.

Looks great, though I have a questions:

It seems you're doing this in a .ipynb file. I personally never use those but the #%% magic comment syntax for cells in regular scripts.
Is it also working there (same backend maybe?) or will #%% be EOL in the near future (which would be a pity in my opinion).

Same backend, so it will work for the interactive window too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

n-a-sz picture n-a-sz  Â·  3Comments

dimitry-ishenko picture dimitry-ishenko  Â·  4Comments

AlbertDeFusco picture AlbertDeFusco  Â·  4Comments

allefeld picture allefeld  Â·  4Comments

SimonCrios picture SimonCrios  Â·  3Comments