Skip to content

Added Pyenv file system watcher#14792

Merged
karrtikr merged 20 commits into
microsoft:mainfrom
karrtikr:pyenvwatcher
Nov 24, 2020
Merged

Added Pyenv file system watcher#14792
karrtikr merged 20 commits into
microsoft:mainfrom
karrtikr:pyenvwatcher

Conversation

@karrtikr

@karrtikr karrtikr commented Nov 20, 2020

Copy link
Copy Markdown

This is very similar to workspace virtualenv watcher #14780, and global virtual env as well. I have consolidated all of them in this PR.

@karrtikr karrtikr added the no-changelog No news entry required label Nov 20, 2020
const kind = await getVirtualEnvKind(env);

const timeData = await getFileInfo(env);
if (virtualEnvKinds.includes(kind)) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We shouldn't discard environments of Unknown type, hence this change. It was causing the watcher test to fail where we created a dummy environment (type Unknown).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can separate out the PR where I consolidate all this + this fix if that would be easier.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What's the effect of the change outside of test? I'm assuming that the check was there for some purpose - if so, the dummy test environment should probably not be Unknown.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the check was there for some purpose

I talked with Karthik about the original purpose, but it was something which just wasn't thought through. He agrees that it should be removed.

The effect of this change is that even if we're unable to detect environment type, we would now still report it.

@karthiknadig karthiknadig requested a review from int19h November 23, 2020 00:43
assert.deepEqual(actualEvent!.type, FileChangeType.Created, 'Wrong event emitted');
testLocatorWatcher(testWorkOnHomePath, createGlobalVirtualEnvironmentLocator);
suiteTeardown(() => {
process.env.WORKON_HOME = workonHomeOldValue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure what the preferred approach is, but in some other tests, we stub getEnvironmentVariable from common/utils/platform.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is a system test, so no stubbing here. The other tests were unit tests.

async function setupLocator(onChanged: (e: PythonEnvsChangedEvent) => Promise<void>) {
locator = options?.arg ? await createLocatorFactoryFunc(options.arg) : await createLocatorFactoryFunc();
// Wait for watchers to get ready
await sleep(1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a fairly long wait, given that it happens at the beginning of a bunch of tests. Can we expose something in the API so that the test can detect it instead? E.g. a promise indicating that the watchers are ready.

@karrtikr karrtikr Nov 23, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Unfortunately there's no way, underlying VSCode API doesn't let us know when the watchers are ready. And other than the purpose of the test, we don't care.

Btw this is old code which was just moved, so most of this has already been reviewed.

await run(argv, { cwd: this.root });
} catch (err) {
throw new Error(`Failed to create Env ${path.basename(envName)} Error: ${err}`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since all the catch blocks here immediately rethrow with some context, perhaps it would be better for the class to log what it does, such that when exception happens, the requisite information would be immediately preceding in the log?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For such a small class, all the context is already available in the error, and I don't think logging is useful unless the error happens. So I will like to keep it as it is.

Comment thread src/test/pythonEnvironments/discovery/locators/watcherTestUtils.ts Outdated
Comment thread src/test/pythonEnvironments/discovery/locators/watcherTestUtils.ts Outdated
Comment thread src/test/pythonEnvironments/discovery/locators/watcherTestUtils.ts

suiteSetup(() => venvs.cleanUp());

async function setupLocator(onChanged: (e: PythonEnvsChangedEvent) => Promise<void>) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Will there be a follow-up PR or work item to replace all existing waitForChangeToBeDetected/isLocated/setupLocator declarations with this utility class?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's what this PR does: for all the venv locators, use this Venvs class instead.

@karrtikr

Copy link
Copy Markdown
Author

@int19h @kimadeline I'm merging this now. If there're other concerns you can still comment here, and I'll address them separately.

@karrtikr karrtikr merged commit 06c9b9e into microsoft:main Nov 24, 2020
@karrtikr karrtikr deleted the pyenvwatcher branch November 24, 2020 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog No news entry required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants