-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
150 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { IExecutableDetails, RExecutableType } from '../service'; | ||
import { CondaVirtualRExecutable } from '../service/class'; | ||
|
||
export function isCondaInstallation(executablePath: string): boolean { | ||
return fs.existsSync(condaMetaDirPath(executablePath)); | ||
} | ||
|
||
export function isCondaExecutable(executable: RExecutableType) { | ||
return executable instanceof CondaVirtualRExecutable; | ||
} | ||
|
||
export function getRDetailsFromCondaMetaHistory(executablePath: string): IExecutableDetails { | ||
try { | ||
const reg = new RegExp(/([0-9]{2})::r-base-([0-9.]*)/g); | ||
const historyContent = fs.readFileSync(condaHistoryPath(executablePath))?.toString(); | ||
const res = reg.exec(historyContent); | ||
return { | ||
arch: res?.[1] ? `${res[1]}-bit` : '', | ||
version: res?.[2] ? res[2] : '' | ||
}; | ||
} catch (error) { | ||
return { | ||
arch: '', | ||
version: '' | ||
}; | ||
} | ||
} | ||
|
||
export function condaName(executablePath: string): string { | ||
return path.basename(condaPrefixPath(executablePath)); | ||
} | ||
|
||
function condaPrefixPath(executablePath: string): string { | ||
return path.dirname(condaMetaDirPath(executablePath)); | ||
} | ||
|
||
function condaMetaDirPath(executablePath: string): string { | ||
let envDir: string = executablePath; | ||
for (let index = 0; index < 4; index++) { | ||
envDir = path.dirname(envDir); | ||
} | ||
return path.join(envDir, 'conda-meta'); | ||
} | ||
|
||
function condaHistoryPath(executablePath: string): string { | ||
return path.join(condaMetaDirPath(executablePath), 'history'); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { isCondaExecutable } from './conda'; | ||
import { CondaVirtualRExecutable } from '../service/class'; | ||
import { isMambaExecutable } from './mamba'; | ||
import { MambaVirtualRExecutable } from '../service/class'; | ||
import { rExecutableManager } from '../../extension'; | ||
import { getRterm } from '../../util'; | ||
import { AbstractRExecutable, AbstractVirtualRExecutable , RExecutableType } from '../service'; | ||
|
||
export * from './conda'; | ||
export * from './mamba'; | ||
export * from './renv'; | ||
|
||
export function isVirtual(executable: AbstractRExecutable): executable is AbstractVirtualRExecutable { | ||
return executable instanceof AbstractVirtualRExecutable; | ||
} | ||
|
||
export interface IProcessArgs { | ||
cmd: string; | ||
args?: string[]; | ||
} | ||
|
||
function virtualAwareArgs( | ||
executable: CondaVirtualRExecutable | MambaVirtualRExecutable, | ||
interactive: boolean, | ||
shellArgs: string[] | ReadonlyArray<string>): IProcessArgs { | ||
const rpath = interactive ? getRterm() : executable.rBin; | ||
const cmd: 'conda' | 'mamba' = isCondaExecutable(executable) ? 'conda' : | ||
isMambaExecutable(executable) ? 'mamba' : | ||
(() => { throw 'Unknown virtual executable'; })(); | ||
|
||
if (!rpath) { | ||
throw 'Bad R executable path'; | ||
} | ||
|
||
const args = [ | ||
'run', | ||
'-n', | ||
executable.name, | ||
...(interactive ? ['--no-capture-output'] : []), | ||
rpath, | ||
...(shellArgs ? shellArgs : []) | ||
]; | ||
|
||
return { | ||
cmd: cmd, | ||
args: args | ||
}; | ||
} | ||
|
||
export function setupVirtualAwareProcessArguments(executable: string, interactive: boolean, args?: ReadonlyArray<string>): IProcessArgs; | ||
export function setupVirtualAwareProcessArguments(executable: RExecutableType, interactive: boolean, args?: ReadonlyArray<string>): IProcessArgs; | ||
export function setupVirtualAwareProcessArguments(executable: RExecutableType | string, interactive: boolean, args?: ReadonlyArray<string>): IProcessArgs { | ||
const rexecutable = typeof executable === 'string' ? rExecutableManager?.getExecutableFromPath(executable) : executable; | ||
if (!rexecutable) { | ||
throw 'Bad R executable path'; | ||
} | ||
if (isVirtual(rexecutable)) { | ||
const virtualArgs = virtualAwareArgs(rexecutable, interactive, args ?? []); | ||
return { cmd: virtualArgs.cmd, args: virtualArgs.args }; | ||
} else { | ||
return { cmd: rexecutable.rBin, args: args?.concat() ?? [] }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RExecutableType } from '../service'; | ||
import { MambaVirtualRExecutable } from '../service/class'; | ||
|
||
export function isMambaExecutable(executable: RExecutableType) { | ||
return executable instanceof MambaVirtualRExecutable; | ||
} | ||
|
||
// TODO | ||
export function isMambaInstallation(executablePath: string): boolean { | ||
return executablePath === 'linter appeasement'; | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters