forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Show a prompt asking users if they want to create environment #22071
Merged
Merged
Changes from all commits
Commits
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 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 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
113 changes: 113 additions & 0 deletions
113
src/client/pythonEnvironments/creation/common/createEnvTriggerUtils.ts
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,113 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as path from 'path'; | ||
import * as fsapi from 'fs-extra'; | ||
import { ConfigurationTarget, Uri, WorkspaceFolder } from 'vscode'; | ||
import { getPipRequirementsFiles } from '../provider/venvUtils'; | ||
import { getExtension } from '../../../common/vscodeApis/extensionsApi'; | ||
import { PVSC_EXTENSION_ID } from '../../../common/constants'; | ||
import { PythonExtension } from '../../../api/types'; | ||
import { traceVerbose } from '../../../logging'; | ||
import { getConfiguration } from '../../../common/vscodeApis/workspaceApis'; | ||
import { getWorkspaceStateValue, updateWorkspaceStateValue } from '../../../common/persistentState'; | ||
|
||
export const CREATE_ENV_TRIGGER_SETTING_PART = 'createEnvironment.trigger'; | ||
export const CREATE_ENV_TRIGGER_SETTING = `python.${CREATE_ENV_TRIGGER_SETTING_PART}`; | ||
|
||
export async function fileContainsInlineDependencies(_uri: Uri): Promise<boolean> { | ||
// This is a placeholder for the real implementation of inline dependencies support | ||
// For now we don't detect anything. Once PEP-722/PEP-723 are accepted we can implement | ||
// this properly. | ||
return false; | ||
} | ||
|
||
export async function hasRequirementFiles(workspace: WorkspaceFolder): Promise<boolean> { | ||
const files = await getPipRequirementsFiles(workspace); | ||
const found = (files?.length ?? 0) > 0; | ||
if (found) { | ||
traceVerbose(`Found requirement files: ${workspace.uri.fsPath}`); | ||
} | ||
return found; | ||
} | ||
|
||
export async function hasKnownFiles(workspace: WorkspaceFolder): Promise<boolean> { | ||
const filePaths: string[] = [ | ||
'poetry.lock', | ||
'conda.yaml', | ||
'environment.yaml', | ||
'conda.yml', | ||
'environment.yml', | ||
'Pipfile', | ||
'Pipfile.lock', | ||
].map((fileName) => path.join(workspace.uri.fsPath, fileName)); | ||
const result = await Promise.all(filePaths.map((f) => fsapi.pathExists(f))); | ||
const found = result.some((r) => r); | ||
if (found) { | ||
traceVerbose(`Found known files: ${workspace.uri.fsPath}`); | ||
} | ||
return found; | ||
} | ||
|
||
export async function isGlobalPythonSelected(workspace: WorkspaceFolder): Promise<boolean> { | ||
const extension = getExtension<PythonExtension>(PVSC_EXTENSION_ID); | ||
if (!extension) { | ||
return false; | ||
} | ||
const extensionApi: PythonExtension = extension.exports as PythonExtension; | ||
const interpreter = extensionApi.environments.getActiveEnvironmentPath(workspace.uri); | ||
const details = await extensionApi.environments.resolveEnvironment(interpreter); | ||
const isGlobal = details?.environment === undefined; | ||
if (isGlobal) { | ||
traceVerbose(`Selected python for [${workspace.uri.fsPath}] is [global] type: ${interpreter.path}`); | ||
} | ||
return isGlobal; | ||
} | ||
|
||
/** | ||
* Checks the setting `python.createEnvironment.trigger` to see if we should perform the checks | ||
* to prompt to create an environment. | ||
* @export | ||
* @returns : True if we should prompt to create an environment. | ||
*/ | ||
export function shouldPromptToCreateEnv(): boolean { | ||
const config = getConfiguration('python'); | ||
if (config) { | ||
const value = config.get<string>(CREATE_ENV_TRIGGER_SETTING_PART, 'off'); | ||
return value !== 'off'; | ||
} | ||
|
||
return getWorkspaceStateValue<string>(CREATE_ENV_TRIGGER_SETTING, 'off') !== 'off'; | ||
} | ||
|
||
/** | ||
* Sets `python.createEnvironment.trigger` to 'off' in the user settings. | ||
*/ | ||
export function disableCreateEnvironmentTrigger(): void { | ||
const config = getConfiguration('python'); | ||
if (config) { | ||
config.update('createEnvironment.trigger', 'off', ConfigurationTarget.Global); | ||
} | ||
} | ||
|
||
/** | ||
* Sets trigger to 'off' in workspace persistent state. This disables trigger check | ||
* for the current workspace only. In multi root case, it is disabled for all folders | ||
* in the multi root workspace. | ||
*/ | ||
export async function disableWorkspaceCreateEnvironmentTrigger(): Promise<void> { | ||
await updateWorkspaceStateValue(CREATE_ENV_TRIGGER_SETTING, 'off'); | ||
} | ||
|
||
let _alreadyCreateEnvCriteriaCheck = false; | ||
/** | ||
* Run-once wrapper function for the workspace check to prompt to create an environment. | ||
* @returns : True if we should prompt to c environment. | ||
*/ | ||
export function isCreateEnvWorkspaceCheckNotRun(): boolean { | ||
if (_alreadyCreateEnvCriteriaCheck) { | ||
return false; | ||
} | ||
_alreadyCreateEnvCriteriaCheck = true; | ||
return true; | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for you to use
PersistentState
class itself? That way logic isn't replicated, and it also has the "expiry" feature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a task to do this as a part of the Testing week. #22077