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

Change public API for execution to return an object and provide a callback which is called when interpreter setting changes #12596

Closed
Tracked by #11015
karrtikr opened this issue Jun 26, 2020 · 9 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality

Comments

@karrtikr
Copy link

karrtikr commented Jun 26, 2020

Old design: #11294

Want to have a public API that returns an object which initially contains an array of strings for the command to execute a Python interpreter. The expectation is we may need to include environment variable details at some point. Update the API as follows,

export interface IExtensionApi {
    /**
     * Promise indicating whether all parts of the extension have completed loading or not.
     * @type {Promise<void>}
     * @memberof IExtensionApi
     */
    ready: Promise<void>;
    debug: {
        /**
         * Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging.
         * Users can append another array of strings of what they want to execute along with relevant arguments to Python.
         * E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']`
         * @param {string} host
         * @param {number} port
         * @param {boolean} [waitUntilDebuggerAttaches=true]
         * @returns {Promise<string[]>}
         */
        getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>;

        /**
         * Gets the path to the debugger package used by the extension.
         * @returns {Promise<string>}
         */
        getDebuggerPackagePath(): Promise<string | undefined>;
    };
    /**
     * Return internal settings within the extension which are stored in VSCode storage
     */
    settings: {
        /**
         * An event that is emitted when execution details (for a resource) change. For instance, when interpreter configuration changes.
         */
        readonly onDidChangeExecutionDetails: Event<Uri | undefined>;
        /**
         * Returns all the details the consumer needs to execute code within the selected environment,
         * corresponding to the specified resource taking into account any workspace-specific settings
         * for the workspace to which this resource belongs.
         * @param {Resource} [resource] A resource for which the setting is asked for.
         * * When no resource is provided, the setting scoped to the first workspace folder is returned.
         * * If no folder is present, it returns the global setting.
         * @returns {({ execCommand: string[] | undefined })}
         */
        getExecutionDetails(
            resource?: Resource
        ): {
            /**
             * E.g of execution commands returned could be,
             * * `['<path to the interpreter set in settings>']`
             * * `['<path to the interpreter selected by the extension when setting is not set>']`
             * * `['conda', 'run', 'python']` which is used to run from within Conda environments.
             * or something similar for some other Python environments.
             *
             * @type {(string[] | undefined)} When return value is `undefined`, it means no interpreter is set.
             * Otherwise, join the items returned using space to construct the full execution command.
             */
            execCommand: string[] | undefined;
        };
    };
    datascience: {
        /**
         * Launches Data Viewer component.
         * @param {IDataViewerDataProvider} dataProvider Instance that will be used by the Data Viewer component to fetch data.
         * @param {string} title Data Viewer title
         */
        showDataViewer(dataProvider: IDataViewerDataProvider, title: string): Promise<void>;
    };
}
@karrtikr karrtikr added feature-request Request for new features or functionality needs PR triage-needed Needs assignment to the proper sub-team area-environments Features relating to handling interpreter environments labels Jun 26, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jun 26, 2020
@karrtikr karrtikr self-assigned this Jun 26, 2020
@karrtikr karrtikr changed the title Update the API exposing interpreter path Changed public API for execution to return an object and provide a callback which is called when interpreter setting changes Jun 26, 2020
@karrtikr karrtikr changed the title Changed public API for execution to return an object and provide a callback which is called when interpreter setting changes Change public API for execution to return an object and provide a callback which is called when interpreter setting changes Jun 26, 2020
@karrtikr
Copy link
Author

karrtikr commented Jun 29, 2020

Tracking the issue for documenting the API microsoft/vscode-docs#3829

Code runner changes: formulahendry/vscode-code-runner#635

@brettcannon
Copy link
Member

/cc @jakebailey

@jakebailey
Copy link
Member

Seems good. I would have maybe had the event include the new info, but maybe it's too expensive and users should just requery if needed.

@erictraut For awareness.

@brettcannon
Copy link
Member

@jakebailey it's a possibility. It's one of those tricky things where we are trying to design for the future which means decomposing way more than we would if we were designing just for today.

@karrtikr
Copy link
Author

@jakebailey We can send just pythonPath for now but as Brett pointed out, as the API begins to include more details, all of the execution details won't be readily available when firing the events.
So we'll have to query these ourselves to send these along with events, which seems rather unnecessary as users can do that themselves if needed.

@karrtikr
Copy link
Author

Also, the default VSCode setting change event API do not include the new info, so we are just keeping up with the trend 🙂

@jakebailey
Copy link
Member

Fine with me.

@jamilraichouni
Copy link

jamilraichouni commented Jul 19, 2020

Hi!

Would be great if getExecutionDetails were also providing the prefix of a possibly activated conda environment.

That can be identified using the path from execCommand, but then everybody has to do that by his own doing something like

  1. Check if environment variable CONDA_PREFIX is set and if not:
  2. Check, if there is a conda executable in the same path as the interpreter given in execCommand.

I have a use case where I need to get the conda env prefix during runtime of a conda Python process even if the conda env has not been activated. If there is a more stable way to do that, let me know, please.

Cheers,
Jamil

@karrtikr
Copy link
Author

@jamilraichouni I have opened up a new issue #13044 for you, we'll let you know our thoughts there.

jaguarfi added a commit to jaguarfi/vscode-restructuredtext that referenced this issue Aug 4, 2020
According to the announcement made by the vscode-python extension
microsoft/vscode-python#12596, the new user
setting python.defaultInterpreterPath can be used instead of the
existing python.pythonPath
jaguarfi added a commit to jaguarfi/vscode-restructuredtext that referenced this issue Aug 4, 2020
According to the announcement made by the vscode-python extension
microsoft/vscode-python#12596, the new user
setting `python.defaultInterpreterPath` can be used instead of the
existing `python.pythonPath`

Fix vscode-restructuredtext#222
jaguarfi added a commit to jaguarfi/vscode-restructuredtext that referenced this issue Aug 4, 2020
According to the announcement made by the vscode-python extension,
it is not posible to use the pythonPath setting anymore.
Therefore, it is necessary to make use of the API provided by the
vscode-python extension
microsoft/vscode-python#12596

Fix vscode-restructuredtext#222
jaguarfi added a commit to jaguarfi/vscode-restructuredtext that referenced this issue Aug 4, 2020
According to the announcement made by the vscode-python extension,
it is not posible to use the pythonPath setting anymore.
Therefore, it is necessary to make use of the API provided by the
vscode-python extension
microsoft/vscode-python#12596

Fix vscode-restructuredtext#222
jaguarfi added a commit to jaguarfi/vscode-restructuredtext that referenced this issue Aug 4, 2020
According to the announcement made by the vscode-python extension,
it is not posible to use the pythonPath setting anymore.
Therefore, it is necessary to make use of the API provided by the
vscode-python extension
microsoft/vscode-python#12596

Fix vscode-restructuredtext#222
jaguarfi added a commit to jaguarfi/vscode-restructuredtext that referenced this issue Aug 4, 2020
According to the announcement made by the vscode-python extension,
it is not possible to use the pythonPath setting anymore.
Therefore, it is necessary to make use of the API provided by the
vscode-python extension
microsoft/vscode-python#12596

Fix vscode-restructuredtext#222
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants