Skip to content

Commit 44c6353

Browse files
authored
Make it possible to override the Package Manager URL (#9165)
This commit introduces a new `positron.r.packageManagerRepository` setting that allows users to override the Posit Package Manager URL used to install R packages (in some scenarios). The new setting allows users of self-hosted Package Manager installations to configure Positron to use them. They also benefit from our existing logic for determining the appropriate Linux binaries automatically. It also opens the door to users pointing at a specific CRAN snapshot on Public Package Manager rather than `latest`. Under the hood this works by passing a new flag down to Ark. Companion PR: posit-dev/ark#906. ### Release Notes #### New Features - A new `positron.r.packageManagerRepository` setting allows overriding the Posit Package Manager URL used to install R packages when `positron.r.defaultRepositories` is set to `auto`. #### Bug Fixes - N/A ### QA Notes Please advise. Signed-off-by: Aaron Jacobs <[email protected]>
1 parent e973708 commit 44c6353

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

extensions/positron-r/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@
349349
],
350350
"default": "auto",
351351
"markdownDescription": "%r.configuration.defaultRepositories.description%"
352+
},
353+
"positron.r.packageManagerRepository": {
354+
"scope": "window",
355+
"type": "string",
356+
"markdownDescription": "%r.configuration.packageManagerRepository.description%"
352357
}
353358
}
354359
}

extensions/positron-r/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"r.configuration.defaultRepositories.rstudio.description": "Use the RStudio CRAN mirror (cran.rstudio.com)",
7171
"r.configuration.defaultRepositories.posit-ppm.description": "Use the Posit public package manager (packagemanager.posit.co)",
7272
"r.configuration.defaultRepositories.none.description": "Do not set a default repository or change the value of the 'repos' option",
73+
"r.configuration.packageManagerRepository.description": "The Posit Package Manager repository URL to use for R package installation, rather than the default https://packagemanager.posit.co/cran/latest.\n\nOnly takes effect when `#positron.r.defaultRepositories#` is `auto` (restart Positron to apply).",
7374
"r.walkthrough.migrateFromRStudio.title": "Migrating from RStudio to Positron",
7475
"r.walkthrough.migrateFromRStudio.description": "Learn how to get started with R in Positron as an RStudio user!",
7576
"r.walkthrough.migrateFromRStudio.panesAndUI.title": "Get to know the Positron UI",

extensions/positron-r/src/kernel-spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@ export function createJupyterKernelSpec(
8484

8585
// Set the default repositories
8686
const defaultRepos = config.get<string>('defaultRepositories') ?? 'auto';
87+
const ppmRepo = config.get<string>('packageManagerRepository');
8788
if (defaultRepos === 'auto') {
8889
const reposConf = findReposConf();
8990
if (reposConf) {
9091
// If there's a `repos.conf` file in a well-known directory, use
9192
// that.
9293
argv.push(...['--repos-conf', reposConf]);
94+
} else if (ppmRepo) {
95+
// If the user has specified a custom Package Manager URL, use it
96+
//
97+
// Note: Ark can't handle trailing slashes, so strip them here
98+
argv.push(...['--default-ppm-repo', ppmRepo.endsWith('/') ? ppmRepo.slice(0, -1) : ppmRepo]);
9399
} else if (vscode.env.uiKind === vscode.UIKind.Web) {
94100
// No repos.conf; if we're web mode use Posit's Public Package
95101
// Manager
@@ -99,6 +105,23 @@ export function createJupyterKernelSpec(
99105
// `--default-repos` at all, and let Ark choose an appropriate
100106
// repository (usually `cran.rstudio.com)
101107
} else {
108+
// Warn the user about inconsistent PPM settings.
109+
if (ppmRepo) {
110+
const openSettings = vscode.l10n.t('Open Settings');
111+
// Note: we don't `await` here to avoid stalling the kernel startup.
112+
vscode.window.showWarningMessage(
113+
vscode.l10n.t('The "Package Manager Repository" setting is ignored unless "Default Repositories" is set to "auto".'),
114+
{ title: openSettings },
115+
{ title: vscode.l10n.t('Dismiss'), isCloseAffordance: true },
116+
).then((action) => {
117+
if (action?.title === openSettings) {
118+
vscode.commands.executeCommand(
119+
'workbench.action.openSettings',
120+
'positron.r.defaultRepositories'
121+
);
122+
}
123+
});
124+
}
102125
// The remaining options map directly to Ark's `--default-repos`
103126
// command line option
104127
argv.push(...['--default-repos', defaultRepos]);

0 commit comments

Comments
 (0)