Repository navigation
Add a windows "known-paths" locator. #14675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eric Snow (ericsnowcurrently)
merged 37 commits into
microsoft:main
from
ericsnowcurrently:pyenvs-component-windows-known-paths-locator
Dec 10, 2020
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5b5205e
Add FS-related testing helpers.
ericsnowcurrently bbd0f72
Add WindowsKnownPathsLocator.
ericsnowcurrently 1e46276
Drop WindowsKnownPathsLocator.triggerRefresh().
ericsnowcurrently 9d1d4dd
Make sure the files are actually executable.
ericsnowcurrently be48b07
Deal with missing directories on $PATH.
ericsnowcurrently 6fa898f
Register the locator.
ericsnowcurrently fd0a29c
Add tests.
ericsnowcurrently 719a06c
Drop unneeded tests.
ericsnowcurrently cae16bc
Mark the PyenvLocator tests as functional.
ericsnowcurrently 1f56574
Mark the GlobalVirtualEnvironmentLocator tests as functional.
ericsnowcurrently f44a558
Fix findInterpretersInDir().
ericsnowcurrently df16786
Stub out normalizeFilename() during unit tests.
ericsnowcurrently 2ec727e
Do not assume "python.exe" is 2.7 on Windows.
ericsnowcurrently 03cd240
Make sure the cache mapping uses normalized filenames.
ericsnowcurrently 04c6482
Fix tests for KnownSearchPathsForInterpreters.
ericsnowcurrently 30422a5
Deal with the fact that fs.access() is useless on Windows.
ericsnowcurrently 2359b06
initialize() -> activate()
ericsnowcurrently e025ffe
Process search path entries in parallel.
ericsnowcurrently 666f41a
Fold the unit tests into the functional tests.
ericsnowcurrently 8a33257
Add a better doc comment for the `parseTree()` helper.
ericsnowcurrently dced4ef
Add better doc comments for `parseFSTree()`.
ericsnowcurrently 39332be
Move the text-oriented helpers to the appropriate module.
ericsnowcurrently 06e7d2e
Fix the tests.
ericsnowcurrently 8b4a4eb
Drop errant line.
ericsnowcurrently db71c64
Fix the tests.
ericsnowcurrently 8b1180c
lint
ericsnowcurrently 917cbc0
Do not check if files are executable.
ericsnowcurrently 0021f3a
Drop an outdated comment.
ericsnowcurrently b6c350a
Do not fail if directory not found.
ericsnowcurrently ed31414
Add DirFilesLocator.
ericsnowcurrently 45689da
Fix WindowsKnownPathsLocator.
ericsnowcurrently 12a3688
WindowsKnownPathsLocator -> WindowsPathEnvVarLocator.
ericsnowcurrently 13b997d
Drop an outdated comment.
ericsnowcurrently a5ac756
Drop the "opts" param from findInterpretersInDir().
ericsnowcurrently e19a429
Factor out getDirFilesLocator().
ericsnowcurrently f5d1284
Wrap DirFilesLocator.
ericsnowcurrently 68151a3
Filter out "non-standard" executables.
ericsnowcurrently File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
90 changes: 90 additions & 0 deletions
90
src/client/pythonEnvironments/base/locators/lowLevel/windowsKnownPathsLocator.ts
This file contains hidden or 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,90 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // tslint:disable-next-line:no-single-line-block-comment | ||
| /* eslint-disable max-classes-per-file */ | ||
|
|
||
| import { Event } from 'vscode'; | ||
| import { getSearchPathEntries } from '../../../../common/utils/exec'; | ||
| import { Disposables, IDisposable } from '../../../../common/utils/resourceLifecycle'; | ||
| import { isStandardPythonBinary } from '../../../common/commonUtils'; | ||
| import { PythonEnvInfo, PythonEnvKind } from '../../info'; | ||
| import { | ||
| ILocator, | ||
| IPythonEnvsIterator, | ||
| PythonLocatorQuery, | ||
| } from '../../locator'; | ||
| import { Locators } from '../../locators'; | ||
| import { getEnvs } from '../../locatorUtils'; | ||
| import { PythonEnvsChangedEvent } from '../../watcher'; | ||
| import { DirFilesLocator } from './filesLocator'; | ||
|
|
||
| /** | ||
| * A locator for Windows locators found under the $PATH env var. | ||
| * | ||
| * Note that we assume $PATH won't change, so we don't need to watch | ||
| * it for changes. | ||
| */ | ||
| export class WindowsPathEnvVarLocator implements ILocator, IDisposable { | ||
| public readonly onChanged: Event<PythonEnvsChangedEvent>; | ||
|
|
||
| private readonly locators: Locators; | ||
|
|
||
| private readonly disposables = new Disposables(); | ||
|
|
||
| constructor() { | ||
| const dirLocators: (ILocator & IDisposable)[] = getSearchPathEntries() | ||
| .map((dirname) => getDirFilesLocator(dirname, PythonEnvKind.Unknown)); | ||
| this.disposables.push(...dirLocators); | ||
| this.locators = new Locators(dirLocators); | ||
| this.onChanged = this.locators.onChanged; | ||
| } | ||
|
|
||
| public async dispose(): Promise<void> { | ||
| this.locators.dispose(); | ||
| await this.disposables.dispose(); | ||
| } | ||
|
|
||
| public iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator { | ||
| // Note that we do no filtering here, including to check if files | ||
| // are valid executables. That is left to callers (e.g. composite | ||
| // locators). | ||
| return this.locators.iterEnvs(query); | ||
| } | ||
|
|
||
| public async resolveEnv(env: string | PythonEnvInfo): Promise<PythonEnvInfo | undefined> { | ||
| return this.locators.resolveEnv(env); | ||
| } | ||
| } | ||
|
|
||
| function getDirFilesLocator( | ||
| dirname: string, | ||
| kind: PythonEnvKind, | ||
| ): ILocator & IDisposable { | ||
| const locator = new DirFilesLocator(dirname, kind); | ||
| // Really we should be checking for symlinks or something more | ||
| // sophisticated. Also, this should be done in ReducingLocator | ||
| // rather than in each low-level locator. In the meantime we | ||
| // take a naive approach. | ||
| async function* iterEnvs(query: PythonLocatorQuery): IPythonEnvsIterator { | ||
| const envs = await getEnvs(locator.iterEnvs(query)); | ||
| for (const env of envs) { | ||
| if (isStandardPythonBinary(env.executable?.filename || '')) { | ||
| yield env; | ||
| } | ||
| } | ||
| } | ||
| async function resolveEnv(env: string | PythonEnvInfo): Promise<PythonEnvInfo | undefined> { | ||
| const executable = typeof env === 'string' ? env : env.executable?.filename || ''; | ||
| if (!isStandardPythonBinary(executable)) { | ||
| return undefined; | ||
| } | ||
| return locator.resolveEnv(env); | ||
| } | ||
| return { | ||
| iterEnvs, | ||
| resolveEnv, | ||
| onChanged: locator.onChanged, | ||
| dispose: () => locator.dispose(), | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.