Skip to content

R: find a way to retain a runtime's home and bin path #2022

Closed

Description

@jennybc

Here's Positron's current definition of ILanguageRuntimeMetadata

/* ILanguageRuntimeMetadata contains information about a language runtime that is known
* before the runtime is started.
*/
export interface ILanguageRuntimeMetadata {
/** The path to the kernel. */
readonly runtimePath: string;
/** A unique identifier for this runtime; usually a GUID */
readonly runtimeId: string;
/** The name of the language that this runtime can execute; e.g. "R" */
readonly languageName: string;
/** The internal ID of the language that this runtime can execute; e.g. "r" */
readonly languageId: string;
/** The version of the language in question; e.g. "4.3.3" */
readonly languageVersion: string;
/** The Base64-encoded icon SVG for the language. */
readonly base64EncodedIconSvg: string | undefined;
/** The identifier of the extension that provides the language support. */
readonly extensionId: ExtensionIdentifier;
/**
* The fully qualified name of the runtime displayed to the user; e.g. "R 4.2 (64-bit)".
* Should be unique across languages.
*/
readonly runtimeName: string;
/**
* A language specific runtime name displayed to the user; e.g. "4.2 (64-bit)".
* Should be unique within a single language.
*/
readonly runtimeShortName: string;
/** The internal version of the runtime that wraps the language; e.g. "1.0.3" */
readonly runtimeVersion: string;
/** The runtime's source or origin; e.g. PyEnv, System, Homebrew, Conda, etc. */
readonly runtimeSource: string;
/** Whether the runtime should start up automatically or wait until explicitly requested */
readonly startupBehavior: LanguageRuntimeStartupBehavior;
}

Let's focus on:

/** The path to the kernel. */
readonly runtimePath: string;

Over in the R extension, we keep re-discovering that, for R specifically, it would be really handy to hold on to TWO paths: the "home" path and the path to the binary.

Inside positron-r, sometimes we need one, sometimes we need the other, sometimes this even varies across OSes, and the way to get home path from bin path (or vice versa) can also vary across OSes.

We already obtain both of these paths when instatiating an RInstallation. The problem is that only one of them can be stored in the official runtime metadata because of the single runtimePath field.

@jmcphers (or anyone): any thoughts on the least disruptive way to accommodate a second path in the runtime metadata for R's sake? Possibilities:

  • Introduce a second path-y field in ILanguageRuntimeMetadata. If Python has no equivalent, it could be left undefined?
  • Generalize runtimePath to an object or array instead of a single string, so each language has more flexibility to store whatever it needs.

Activity

  1. jmcphers commented on Jan 5, 2024

    @jmcphers
    Collaborator

    In my view, the runtime metadata structure should really only contain the fields that are relevant to Positron (and displayed in the UI). If we need additional context/data in a language pack, it's up to the language pack to work it out.

    In this case, I think it'd be very straightforward to hang on to the RInstallation object and use it as a constructor argument when constructing an RRuntime. Then all interactions with the runtime will have access to all of the discovered info about the R installation.

    i.e. we construct the RRuntime here, which is during a loop over RInstallation:

    https://github.com/posit-dev/positron/blob/0c8a8b66597fd29aa1d71de726659e1c9dbc897e/extensions/positron-r/src/provider.ts#L241C34-L241C34

    Would that do what you want?

  2. jennybc commented on Jan 5, 2024

    @jennybc
    MemberAuthor

    If we need additional context/data in a language pack, it's up to the language pack to work it out.

    OK yes this helps. We will work this out for ourselves in RRuntime then.

  3. jmcphers commented on Jan 5, 2024

    @jmcphers
    Collaborator

    Oh, now that I read through all the connected issues I see that this issue is probably less about "give me the home/bin path for the version of R I am using" and more about "create a full RInstallation metadata from a Positron Runtime Metadata object".

    I think the best way to approach that might be to use something other than (or in addition to) the Positron Runtime Metadata to remember/replay the active runtime. It could really just be an opaque token or object + the extension ID. Positron can put the token in storage and hand it back to the extension to start the runtime.

  4. jennybc commented on Feb 23, 2024

    @jennybc
    MemberAuthor

    This remains an issue for the R extension but I also think it should wait until @jmcphers current work on refactoring runtimes is done. I'm associating it with the "Future" milestone because it's not user-facing. The timing of the work will be determined by when the next obvious person is working in the "neighborhood".

  5. added this to the Future milestone on Feb 23, 2024
  6. jmcphers commented on Feb 23, 2024

    @jmcphers
    Collaborator

    I'm going to handle this work as part of the refactor, as an extraData field extensions can use to supply their own extra fields to be recorded/played back with the metadata supplied to Positron.

    // Save the R home path and binary path as extra data.
    const extraData: RMetadataExtra = {
    homepath: rInst.homepath,
    binpath: rInst.binpath,
    };
    const metadata: positron.LanguageRuntimeMetadata = {
    runtimeId,
    runtimeName,
    runtimeShortName,
    runtimePath,
    runtimeVersion: packageJson.version,
    runtimeSource,
    languageId: 'r',
    languageName: kernelSpec.language,
    languageVersion: rVersion,
    base64EncodedIconSvg:
    fs.readFileSync(
    path.join(context.extensionPath, 'resources', 'branding', 'r-icon.svg')
    ).toString('base64'),
    startupBehavior,
    extraData
    };

  7. jmcphers commented on Mar 8, 2024

    @jmcphers
    Collaborator

    This is now implemented as part of #2415.

  8. jmcphers commented on Mar 12, 2024

    @jmcphers
    Collaborator

    Ready to verify. There isn't any user-facing behavior change, but could be verified by setting a breakpoint here:

    const metadataExtra = runtimeMetadata.extraRuntimeData as RMetadataExtra;
    const kernelExtra = createJupyterKernelExtra();
    const kernelSpec = createJupyterKernelSpec(this._context,
    metadataExtra.homepath,

    and verifying that Positron is indeed retaining and passing R_HOME back to the R extension.

  9. jennybc commented on Mar 13, 2024

    @jennybc
    MemberAuthor

    Yes I can confirm that the homepath is available in the R_HOME env var in the kernelSpec's env. I'm not entirely clear how using it is going to play out exactly, but I'm sure that will work itself out.

    Screenshot 2024-03-13 at 1 07 21 PM
  10. locked as resolved and limited conversation to collaborators on Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions