question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose interpreter path using API

See original GitHub issue

THIS WILL SOON BE REMOVED. CHECK https://github.com/microsoft/vscode-python/issues/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;
    };
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, Apr 23, 2020

Apologies for the confusion, I understand this was discussed, my bad. Hiding my comments & the subsequent comments to avoid confusion

1reaction
brettcannoncommented, Apr 23, 2020

@DonJayamanne

  • We know conda run is busted, but we don’t want to design ourselves into a corner if it does work someday
  • Why won’t this work for pyenv? How it is different from any other path that may be provided?

We don’t want to own running code for other extensions, we are just exposing how to run code because we and other extensions have a need for this exact functionality. And we are definitely not going to wrap execution APIs as we would then have to mirror all options provided by Node and VS Code and that is not a business we want to be in.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interpreter Mode API Additional Terms of Service
Interpreter Mode Terms. By accessing or using the Interpreter Mode API, you are agreeing to the Google APIs Terms of Service at ...
Read more >
Python/C API Reference Manual — Python 3.11.1 ...
This manual documents the API used by C and C++ programmers who want to write extension modules or embed Python. It is a...
Read more >
Add current file directory to Python interpreter path in PyCharm
1. In the first case, the IDE simply calls the OS shell with the Python interpreter as first argument and the path to...
Read more >
Chapter 4. Handling interpreter directives in Python scripts
When running pathfix.py outside an RPM build, replace %{python3} from the example above with a path for the interpreter directive, such as /usr/bin/python3...
Read more >
Python Interpreter Configuration Data Structures - PyOxidizer
The filesystem path from which relative paths will be interpreted. ... struct holds fields that are exposed by PyPreConfig and PyConfig in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found