Skip to content

Commit

Permalink
pass default repos (if any) to ark
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers committed Nov 27, 2024
1 parent 783ab70 commit 64ee268
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions extensions/positron-r/src/kernel-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import * as positron from 'positron';
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';

import { JupyterKernelSpec } from './jupyter-adapter';
import { getArkKernelPath } from './kernel';
import { getPandocPath } from './pandoc';
import { EXTENSION_ROOT_DIR } from './constants';

/**
* Create a new Jupyter kernel spec.
Expand Down Expand Up @@ -91,6 +93,28 @@ export function createJupyterKernelSpec(
]);
}

// Set the default repositories
const defaultRepos = config.get<string>('defaultRepositories') ?? 'auto';
if (defaultRepos === 'auto') {
const reposConf = findReposConf();
if (reposConf) {
// If there's a `repos.conf` file in a well-known directory, use
// that.
argv.push(...['--default-repos', reposConf]);
} else if (vscode.env.uiKind === vscode.UIKind.Web) {
// No repos.conf; if we're web mode use Posit's Public Package
// Manager
argv.push(...['--default-repos', 'posit-ppm']);
}
// In all other cases when `auto` is set, we don't specify
// `--default-repos` at all, and let Ark choose an appropriate
// repository (usually `cran.rstudio.com)
} else {
// The remaining options map directly to Ark's `--default-repos`
// command line option
argv.push(...['--default-repos', defaultRepos]);
}

argv.push(...[
// The arguments after `--` are passed verbatim to R
'--',
Expand Down Expand Up @@ -123,3 +147,23 @@ export function createJupyterKernelSpec(

return kernelSpec;
}

/**
* Attempt to find a `repos.conf` file in Positron or RStudio XDG
* configuration directories.
*
* Returns the path to the file if found, or `undefined` if no
*/
function findReposConf(): string | undefined {
const xdg = require('xdg-portable/cjs');
const configDirs: Array<string> = xdg.configDirs();
for (const product of ['rstudio', 'positron']) {
for (const configDir of configDirs) {
const reposConf = path.join(configDir, product, 'repos.conf');
if (fs.existsSync(reposConf)) {
return reposConf;
}
}
}
return;
}

0 comments on commit 64ee268

Please sign in to comment.