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

Expose interpreter path using API #11294

Closed
Tracked by #11015
karrtikr opened this issue Apr 21, 2020 · 6 comments
Closed
Tracked by #11015

Expose interpreter path using API #11294

karrtikr opened this issue Apr 21, 2020 · 6 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 Apr 21, 2020

THIS WILL SOON BE REMOVED. CHECK #12596 FOR THE UPDATED DESIGN PROPOSAL

This code snippet shows how to use the new API, could be helpful.

Update the API as follows by adding a settings section,

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/ptvsd_launcher.py', '--host', 'localhost', '--port', '57039', '--wait']`
         * @param {string} host
         * @param {number} port
         * @param {boolean} [waitUntilDebuggerAttaches=true]
         * @returns {Promise<string[]>}
         */
        getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>;
    };
    /**
     * Return internal settings within the extension which are stored in VSCode storage
     */
    settings: {
        /**
         * Returns the Python execution command corresponding to the specified resource, taking into account
         * any workspace-specific settings for the workspace to which this resource belongs.
         * 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.
         * @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 {(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.
         */
        getExecutionCommand(resource?: Resource): string[] | undefined;
    };
}
@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 Apr 21, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 21, 2020
@karrtikr karrtikr self-assigned this Apr 21, 2020
@karrtikr
Copy link
Author

@karrtikr
Copy link
Author

karrtikr commented Apr 22, 2020

formulahendry/vscode-code-runner#604 (comment):

We've to make sure all these 4 cases work,

  1. Old version of Code Runner + Old version of the extension -> already works
  2. New version of Code Runner + Old version of the extension
  3. New version of Code Runner + New version of the extension
  4. Old version of Code Runner + New version of the extension

Proposed changes

Code runner

In the new version of code runner,

We would check if user is using the old or the new python extension using the new setting.

  • If he is using the old one, we would look for the settings in the old way
  • If he is using the new one, we would look for the settings in the new way using the API
  • If new version of code runner is being used, the above proposed changes work fine for cases 2 & 3.

Python extension

  • Expose the interpreter path via API. Expose interpreter path using API #11294
  • Check if we are using the old version of Code runner or the new one. If using the old one, show a prompt asking user to upgrade Code runner to new version to keep using it. This will solve case 4.

How to check from extension A if user is using the old version of extension B or the new one

Introduce a flag in package.json of both the extensions. Within extension A, check if package.json of extension B has flag set. If it is set, it's the newer version of the extension.

Python extension

  • Introduce a feature flag in package.json of the extension, which states if the extension is using the new interpreter storage or not. We're adding the following to our package.json ,
"featureFlags": {
    "usingNewInterpreterStorage": true
}

So you can access the flag using,

const extension = vscode.extensions.getExtension('ms-python.python')!;
const flagValue = extension.packageJSON.featureFlags.usingNewInterpreterStorage;

Code runner

Please add a similar flag in package.json and let us know. You can use the following to call our API, which makes sure the extension is activated before calling the API:

const extension = vscode.extensions.getExtension('ms-python.python')!;
if (!extension.isActive) {
    await extension.activate();
}
const pythonPath = extension.exports.settings.getInterpreterPath(resource);

Note we will have to release Code runnner extension first, followed by the extension release. (which is targeted before May 12)

@DonJayamanne

This comment has been minimized.

@karrtikr

This comment has been minimized.

@brettcannon

This comment has been minimized.

@DonJayamanne

This comment has been minimized.

@ghost ghost removed the needs PR label May 11, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
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

3 participants