Skip to content

Commit b5595b2

Browse files
committed
Re-added preference for specifying path to ActiveState's State Tool.
Use a more descriptive name.
1 parent 97f6740 commit b5595b2

File tree

8 files changed

+53
-10
lines changed

8 files changed

+53
-10
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@
376376
],
377377
"configuration": {
378378
"properties": {
379+
"python.activeStateToolPath": {
380+
"default": "state",
381+
"description": "%python.activeStateToolPath.description%",
382+
"scope": "machine-overridable",
383+
"type": "string"
384+
},
379385
"python.autoComplete.extraPaths": {
380386
"default": [],
381387
"description": "%python.autoComplete.extraPaths.description%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"python.command.python.launchTensorBoard.title": "Launch TensorBoard",
2626
"python.command.python.refreshTensorBoard.title": "Refresh TensorBoard",
2727
"python.menu.createNewFile.title": "Python File",
28+
"python.activeStateToolPath.description": "Path to the State Tool executable for ActiveState runtimes (version 0.36+).",
2829
"python.autoComplete.extraPaths.description": "List of paths to libraries and the like that need to be imported by auto complete engine. E.g. when using Google App SDK, the paths are not in system path, hence need to be added into this list.",
2930
"python.condaPath.description": "Path to the conda executable to use for activation (version 4.4+).",
3031
"python.defaultInterpreterPath.description": "Path to default Python to use when extension loads up for the first time, no longer used once an interpreter is selected for the workspace. See [here](https://aka.ms/AAfekmf) to understand when this is used",

resources/report_issue_user_settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"envFile": "placeholder",
88
"venvPath": "placeholder",
99
"venvFolders": "placeholder",
10+
"activeStateToolPath": "placeholder",
1011
"condaPath": "placeholder",
1112
"pipenvPath": "placeholder",
1213
"poetryPath": "placeholder",

src/client/common/configSettings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export class PythonSettings implements IPythonSettings {
9898

9999
public venvFolders: string[] = [];
100100

101+
public activeStateToolPath = '';
102+
101103
public condaPath = '';
102104

103105
public pipenvPath = '';
@@ -254,6 +256,11 @@ export class PythonSettings implements IPythonSettings {
254256

255257
this.venvPath = systemVariables.resolveAny(pythonSettings.get<string>('venvPath'))!;
256258
this.venvFolders = systemVariables.resolveAny(pythonSettings.get<string[]>('venvFolders'))!;
259+
const activeStateToolPath = systemVariables.resolveAny(pythonSettings.get<string>('activeStateToolPath'))!;
260+
this.activeStateToolPath =
261+
activeStateToolPath && activeStateToolPath.length > 0
262+
? getAbsolutePath(activeStateToolPath, workspaceRoot)
263+
: activeStateToolPath;
257264
const condaPath = systemVariables.resolveAny(pythonSettings.get<string>('condaPath'))!;
258265
this.condaPath = condaPath && condaPath.length > 0 ? getAbsolutePath(condaPath, workspaceRoot) : condaPath;
259266
const pipenvPath = systemVariables.resolveAny(pythonSettings.get<string>('pipenvPath'))!;

src/client/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export interface IPythonSettings {
184184
readonly pythonPath: string;
185185
readonly venvPath: string;
186186
readonly venvFolders: string[];
187+
readonly activeStateToolPath: string;
187188
readonly condaPath: string;
188189
readonly pipenvPath: string;
189190
readonly poetryPath: string;

src/client/pythonEnvironments/common/environmentManagers/activestate.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55

66
import * as path from 'path';
77
import { dirname } from 'path';
8-
import { arePathsSame, pathExists, shellExecute } from '../externalDependencies';
8+
import {
9+
arePathsSame,
10+
getPythonSetting,
11+
onDidChangePythonSetting,
12+
pathExists,
13+
shellExecute,
14+
} from '../externalDependencies';
915
import { cache } from '../../../common/utils/decorators';
1016
import { traceError, traceVerbose } from '../../../logging';
1117
import { getOSType, getUserHomeDir, OSType } from '../../../common/utils/platform';
1218

19+
export const ACTIVESTATETOOLPATH_SETTING_KEY = 'activeStateToolPath';
20+
1321
const STATE_GENERAL_TIMEOUT = 5000;
1422

1523
export type ProjectInfo = {
@@ -35,6 +43,12 @@ export class ActiveState {
3543
return ActiveState.statePromise;
3644
}
3745

46+
constructor() {
47+
onDidChangePythonSetting(ACTIVESTATETOOLPATH_SETTING_KEY, () => {
48+
ActiveState.statePromise = undefined;
49+
});
50+
}
51+
3852
public static getStateToolDir(): string | undefined {
3953
const home = getUserHomeDir();
4054
if (!home) {
@@ -47,7 +61,9 @@ export class ActiveState {
4761

4862
private static async locate(): Promise<ActiveState | undefined> {
4963
const stateToolDir = this.getStateToolDir();
50-
if (stateToolDir && (await pathExists(stateToolDir))) {
64+
const stateCommand =
65+
getPythonSetting<string>(ACTIVESTATETOOLPATH_SETTING_KEY) ?? ActiveState.defaultStateCommand;
66+
if (stateToolDir && ((await pathExists(stateToolDir)) || stateCommand !== this.defaultStateCommand)) {
5167
return new ActiveState();
5268
}
5369
return undefined;
@@ -57,13 +73,15 @@ export class ActiveState {
5773
return this.getProjectsCached();
5874
}
5975

60-
private static readonly stateCommand: string = 'state';
76+
private static readonly defaultStateCommand: string = 'state';
6177

6278
@cache(30_000, true, 10_000)
6379
// eslint-disable-next-line class-methods-use-this
6480
private async getProjectsCached(): Promise<ProjectInfo[] | undefined> {
6581
try {
66-
const result = await shellExecute(`${ActiveState.stateCommand} projects -o editor`, {
82+
const stateCommand =
83+
getPythonSetting<string>(ACTIVESTATETOOLPATH_SETTING_KEY) ?? ActiveState.defaultStateCommand;
84+
const result = await shellExecute(`${stateCommand} projects -o editor`, {
6785
timeout: STATE_GENERAL_TIMEOUT,
6886
});
6987
if (!result) {
@@ -74,7 +92,7 @@ export class ActiveState {
7492
// '\0' is a record separator.
7593
output = output.substring(0, output.length - 1);
7694
}
77-
traceVerbose(`${ActiveState.stateCommand} projects -o editor: ${output}`);
95+
traceVerbose(`${stateCommand} projects -o editor: ${output}`);
7896
const projects = JSON.parse(output);
7997
ActiveState.setCachedProjectInfo(projects);
8098
return projects;

src/test/common/configSettings/configSettings.unit.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ suite('Python Settings', async () => {
8181
for (const name of [
8282
'pythonPath',
8383
'venvPath',
84+
'activeStateToolPath',
8485
'condaPath',
8586
'pipenvPath',
8687
'envFile',
@@ -139,11 +140,17 @@ suite('Python Settings', async () => {
139140
}
140141

141142
suite('String settings', async () => {
142-
['venvPath', 'condaPath', 'pipenvPath', 'envFile', 'poetryPath', 'defaultInterpreterPath'].forEach(
143-
async (settingName) => {
144-
testIfValueIsUpdated(settingName, 'stringValue');
145-
},
146-
);
143+
[
144+
'venvPath',
145+
'activeStateToolPath',
146+
'condaPath',
147+
'pipenvPath',
148+
'envFile',
149+
'poetryPath',
150+
'defaultInterpreterPath',
151+
].forEach(async (settingName) => {
152+
testIfValueIsUpdated(settingName, 'stringValue');
153+
});
147154
});
148155

149156
suite('Boolean settings', async () => {

src/test/pythonEnvironments/base/locators/lowLevel/activestateLocator.unit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ suite('ActiveState Locator', () => {
4040
sinon.stub(fsapi, 'pathExists').callsFake((dir: string) => dir === stateToolDir);
4141
}
4242

43+
sinon.stub(externalDependencies, 'getPythonSetting').returns(undefined);
44+
4345
sinon.stub(externalDependencies, 'shellExecute').callsFake((command: string) => {
4446
if (command === 'state projects -o editor') {
4547
return Promise.resolve<ExecutionResult<string>>({

0 commit comments

Comments
 (0)