Skip to content

Commit

Permalink
Add logging which could help indicate why `Discovering Python Interpr…
Browse files Browse the repository at this point in the history
…eters...` never finishes (#20792)

For #20250
  • Loading branch information
Kartik Raj authored Mar 3, 2023
1 parent e8303bb commit 2442dfb
Show file tree
Hide file tree
Showing 19 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function checkIfFinishedAndNotify(
if (state.done && state.pending === 0) {
didUpdate.fire({ stage: ProgressReportStage.discoveryFinished });
didUpdate.dispose();
traceVerbose(`Finished with environment reducer`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function checkIfFinishedAndNotify(
if (state.done && state.pending === 0) {
didUpdate.fire({ stage: ProgressReportStage.discoveryFinished });
didUpdate.dispose();
traceVerbose(`Finished with environment resolver`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ export class ActiveStateLocator extends LazyResourceBasedLocator {
}
}
}
traceVerbose(`Finished searching for active state environments`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
traceError(`Failed to process conda env: ${JSON.stringify(env)}`, ex);
}
}
traceVerbose(`Finished searching for conda environments`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class CustomVirtualEnvironmentLocator extends FSWatchingLocator {
});

yield* iterable(chain(envGenerators));
traceVerbose(`Finished searching for custom virtual envs`);
}

return iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class GlobalVirtualEnvironmentLocator extends FSWatchingLocator {
});

yield* iterable(chain(envGenerators));
traceVerbose(`Finished searching for global virtual envs`);
}

return iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isStorePythonInstalled,
getMicrosoftStoreAppsRoot,
} from '../../../common/environmentManagers/microsoftStoreEnv';
import { traceVerbose } from '../../../../logging';

/**
* This is a glob pattern which matches following file names:
Expand Down Expand Up @@ -91,6 +92,7 @@ export class MicrosoftStoreLocator extends FSWatchingLocator {
kind,
executablePath,
}));
traceVerbose(`Finished searching for windows store envs`);
};
return iterator(this.kind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class PoetryLocator extends LazyResourceBasedLocator {
});

yield* iterable(chain(envGenerators));
traceVerbose(`Finished searching for poetry envs`);
}

return iterator(this.root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { BasicEnvInfo, IPythonEnvsIterator, Locator } from '../../locator';
import { commonPosixBinPaths, getPythonBinFromPosixPaths } from '../../../common/posixUtils';
import { isPyenvShimDir } from '../../../common/environmentManagers/pyenv';
import { getOSType, OSType } from '../../../../common/utils/platform';
import { isMacDefaultPythonPath } from './macDefaultLocator';
import { traceError } from '../../../../logging';
import { isMacDefaultPythonPath } from '../../../common/environmentManagers/macDefault';
import { traceError, traceVerbose } from '../../../../logging';

export class PosixKnownPathsLocator extends Locator<BasicEnvInfo> {
public readonly providerId = 'posixKnownPaths';
Expand Down Expand Up @@ -44,6 +44,7 @@ export class PosixKnownPathsLocator extends Locator<BasicEnvInfo> {
traceError(`Failed to process environment: ${bin}`, ex);
}
}
traceVerbose('Finished searching for interpreters in posix paths locator');
};
return iterator(this.kind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FSWatchingLocator } from './fsWatchingLocator';
import { getInterpreterPathFromDir } from '../../../common/commonUtils';
import { getSubDirs } from '../../../common/externalDependencies';
import { getPyenvVersionsDir } from '../../../common/environmentManagers/pyenv';
import { traceError } from '../../../../logging';
import { traceError, traceVerbose } from '../../../../logging';

/**
* Gets all the pyenv environments.
Expand All @@ -33,6 +33,7 @@ async function* getPyenvEnvironments(): AsyncIterableIterator<BasicEnvInfo> {
}
}
}
traceVerbose('Finished searching for pyenv environments');
}

export class PyenvLocator extends FSWatchingLocator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Locators } from '../../locators';
import { getEnvs } from '../../locatorUtils';
import { PythonEnvsChangedEvent } from '../../watcher';
import { DirFilesLocator } from './filesLocator';
import { traceVerbose } from '../../../../logging';

/**
* A locator for Windows locators found under the $PATH env var.
Expand Down Expand Up @@ -93,6 +94,7 @@ function getDirFilesLocator(
// take a naive approach.
async function* iterEnvs(query: PythonLocatorQuery): IPythonEnvsIterator<BasicEnvInfo> {
yield* await getEnvs(locator.iterEnvs(query));
traceVerbose('Finished searching for windows path interpreters');
}
return {
providerId: locator.providerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { PythonEnvKind, PythonEnvSource } from '../../info';
import { BasicEnvInfo, IPythonEnvsIterator, Locator } from '../../locator';
import { getRegistryInterpreters } from '../../../common/windowsUtils';
import { traceError } from '../../../../logging';
import { traceError, traceVerbose } from '../../../../logging';
import { isMicrosoftStoreDir } from '../../../common/environmentManagers/microsoftStoreEnv';

export class WindowsRegistryLocator extends Locator<BasicEnvInfo> {
Expand Down Expand Up @@ -33,6 +33,7 @@ export class WindowsRegistryLocator extends Locator<BasicEnvInfo> {
traceError(`Failed to process environment: ${interpreter}`, ex);
}
}
traceVerbose('Finished searching for windows registry interpreters');
};
return iterator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class WorkspaceVirtualEnvironmentLocator extends FSWatchingLocator {
});

yield* iterable(chain(envGenerators));
traceVerbose(`Finished searching for workspace virtual envs`);
}

return iterator(this.root);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { getOSType, OSType } from '../../../../common/utils/platform';

// TODO: Add tests for 'isMacDefaultPythonPath' when working on the locator
import { getOSType, OSType } from '../../../common/utils/platform';

/**
* Decide if the given Python executable looks like the MacOS default Python.
Expand Down
2 changes: 1 addition & 1 deletion src/client/pythonEnvironments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import { EnvsCollectionService } from './base/locators/composite/envsCollectionService';
import { IDisposable } from '../common/types';
import { traceError } from '../logging';
import { ActiveStateLocator } from './base/locators/lowLevel/activestateLocator';
import { ActiveStateLocator } from './base/locators/lowLevel/activeStateLocator';

/**
* Set up the Python environments component (during extension activation).'
Expand Down
2 changes: 1 addition & 1 deletion src/client/pythonEnvironments/legacyIOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IComponentAdapter, ICondaService, PythonEnvironmentsChangedEvent } from
import { IServiceManager } from '../ioc/types';
import { PythonEnvInfo, PythonEnvKind, PythonEnvSource } from './base/info';
import { IDiscoveryAPI, PythonLocatorQuery, TriggerRefreshOptions } from './base/locator';
import { isMacDefaultPythonPath } from './base/locators/lowLevel/macDefaultLocator';
import { isMacDefaultPythonPath } from './common/environmentManagers/macDefault';
import { isParentPath } from './common/externalDependencies';
import { EnvironmentType, PythonEnvironment } from './info';
import { toSemverLikeVersion } from './base/info/pythonVersion';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fsapi from 'fs-extra';
import { PythonEnvKind } from '../../../../../client/pythonEnvironments/base/info';
import * as externalDependencies from '../../../../../client/pythonEnvironments/common/externalDependencies';
import { getEnvs } from '../../../../../client/pythonEnvironments/base/locatorUtils';
import { ActiveStateLocator } from '../../../../../client/pythonEnvironments/base/locators/lowLevel/activestateLocator';
import { ActiveStateLocator } from '../../../../../client/pythonEnvironments/base/locators/lowLevel/activeStateLocator';
import { TEST_LAYOUT_ROOT } from '../../../common/commonTestConstants';
import { assertBasicEnvsEqual } from '../envTestUtils';
import { ExecutionResult } from '../../../../../client/common/process/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as osUtils from '../../../../../client/common/utils/platform';
import { isMacDefaultPythonPath } from '../../../../../client/pythonEnvironments/base/locators/lowLevel/macDefaultLocator';
import { isMacDefaultPythonPath } from '../../../../../client/pythonEnvironments/common/environmentManagers/macDefault';

suite('isMacDefaultPythonPath', () => {
let getOSTypeStub: sinon.SinonStub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PosixKnownPathsLocator } from '../../../../../client/pythonEnvironments
import { createBasicEnv } from '../../common';
import { TEST_LAYOUT_ROOT } from '../../../common/commonTestConstants';
import { assertBasicEnvsEqual } from '../envTestUtils';
import { isMacDefaultPythonPath } from '../../../../../client/pythonEnvironments/base/locators/lowLevel/macDefaultLocator';
import { isMacDefaultPythonPath } from '../../../../../client/pythonEnvironments/common/environmentManagers/macDefault';

suite('Posix Known Path Locator', () => {
let getPathEnvVar: sinon.SinonStub;
Expand Down

1 comment on commit 2442dfb

@Yobb17
Copy link

@Yobb17 Yobb17 commented on 2442dfb Aug 28, 2023

Choose a reason for hiding this comment

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

src/client/pythonEnvironments/base/locators/composite/envsReducer.ts

Please sign in to comment.