Skip to content

Conversation

@jmcphers
Copy link
Collaborator

This change adds environment module support to Positron.

image

It is not generally possible for us to know a priori what module environments the user wants to use, and which languages they intend to use with them; attempting to scan for modules and find all possible R/Python environments that could be affected would result in a whole lot of noise. Consequently, this feature does not work without explicit configuration. The configuration looks like this:

    "positron.environmentModules.environments": {
        "R 4 Stable": {
            "languages": ["r"],
            "modules": ["R/4.4.2", "other/version"]
        },
        "Python 3.12": {
            "languages": ["python"],
            "modules": ["python/3.12.8"]
        }
    },

For each environment you need to specify:

  • a name (for display in the UI)
  • the language(s) intended for the environment
  • the module(s) to load in the environment

For convenience, there is a Manage Module Environments command that can be used to walk you through setting up a configuration the first time, and a diagnostics report that shows the current state.

All of the implementation here happens on the extension side; a new positron-environment-modules extension provides the settings and commands, and an API that other extensions can use to query for module environments.

As far as actually loading the modules, this change takes advantage of a new supervisor feature added recently to support conda; we just tell the supervisor to run module load ... in the shell before starting the kernel. posit-dev/kallichore#55

The grossest part of this change is in positron-python; because the native locator (PET) doesn't know about environment modules, we need need to run a separate, typescript-based discovery pass to discover Python installations in named module environments, and aggregate the results with those from the native locator.

Release Notes

New Features

Bug Fixes

  • N/A

QA Notes

  • Environment modules are Linux/macOS only, and practically speaking only used on Linux; the whole system should stand down on Windows
  • The module load commands are only run in R/Python kernels (i.e. consoles and notebooks). In regular terminals, or in commands run directly by extensions, the modules are not loaded. We're discussing how best to address this as it's a general problem that also affects conda, pixi, etc.
  • For testing, I recommend compiling a version of R or Python from source into e.g. /opt/software, and then adding a module that puts it on the $PATH (etc).
  • A module is expected to put the version of R or Python it wants onto the $PATH. If it does not do this, the otherwise default version of the interpreter will be discovered (e.g. the system version). This may be what you want in some circumstances as modules can also be used to pull in env vars for auth or otherwise setup an environment.

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

/**
* Detect if a module system is available and determine its type.
*/
export async function detectModuleSystem(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did brew install modules, which told me to add source /opt/homebrew/opt/modules/init/zsh to my .zshrc. Consequently I think this function can't find my installation. Is it too bash-centric right now? Might there be a more generic way to check, like looking for $MODULEPATH or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants