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
Adding PYTHONSTARTUP with shell integration to environment variable collection #24111
Merged
anthonykim1
merged 18 commits into
microsoft:main
from
anthonykim1:pythonStartupSetting
Sep 19, 2024
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e8dc28c
enable SI when typing Python in terminal
anthonykim1 a19d77c
dont limit to clearing only PS1 and PATH
anthonykim1 4412586
add setting to toggle exporting of pythonstartup
anthonykim1 4c663c3
comment
anthonykim1 02f4dc4
always clean up
anthonykim1 677b620
ShellIntegrationDetectionService not IShellIntegrationDetectionServic…
anthonykim1 d85a4c0
unused
anthonykim1 3b9f82d
IPythonStartupEnvVarService to serviceRegistry test
anthonykim1 99fc20c
remove comment
anthonykim1 8e8dd18
better name better description
anthonykim1 7b7183c
Update package.nls.json
anthonykim1 327662e
rename to python repl enableShellIntegration
anthonykim1 6f544bf
renaming legacy shellIntegrationService to shellIntegrationDetectionS…
anthonykim1 44b156e
fix test to add enableShellIntegration field to make test happy
anthonykim1 7bdc4b5
remove unused comment
anthonykim1 a50490f
clean up
anthonykim1 76a6a48
rename nls description properly to repl.enableShellIntegration
anthonykim1 1cd461a
separate out pythonStartup as a function not class
anthonykim1 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
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,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as path from 'path'; | ||
import { injectable, inject } from 'inversify'; | ||
import { Uri, workspace } from 'vscode'; | ||
import { IPythonStartupEnvVarService } from '../types'; | ||
import { IConfigurationService, IExtensionContext } from '../../common/types'; | ||
import { EXTENSION_ROOT_DIR } from '../../constants'; | ||
|
||
@injectable() | ||
export class PythonStartupEnvVarService implements IPythonStartupEnvVarService { | ||
constructor( | ||
@inject(IExtensionContext) private context: IExtensionContext, | ||
@inject(IConfigurationService) private configurationService: IConfigurationService, | ||
) {} | ||
|
||
public async register(): Promise<void> { | ||
const storageUri = this.context.storageUri || this.context.globalStorageUri; | ||
try { | ||
await workspace.fs.createDirectory(storageUri); | ||
} catch { | ||
// already exists, most likely | ||
} | ||
const destPath = Uri.joinPath(storageUri, 'pythonrc.py'); | ||
|
||
// TODO: Only do this when we have a setting | ||
// Rollout strategy: | ||
// Stage 1. Opt-in setting in stable/insiders | ||
// Stage 2. Out-out setting in insiders | ||
// Stage 3. Out-out setting in stable (or experiment?) | ||
const sourcePath = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py'); | ||
|
||
await workspace.fs.copy(Uri.file(sourcePath), destPath, { overwrite: true }); | ||
const pythonrcSetting = this.configurationService.getSettings().terminal.pythonrcStartup; | ||
// TODO: Is there better place to set this? | ||
if (pythonrcSetting) { | ||
this.context.environmentVariableCollection.replace('PYTHONSTARTUP', destPath.fsPath); | ||
} else { | ||
this.context.environmentVariableCollection.delete('PYTHONSTARTUP'); | ||
} | ||
} | ||
} |
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
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.
Can I get feedback on the setting name and description? @cwebster-99
This is for allowing user to opt out of using shell integration for REPL when they launch the terminal REPL via typing out "python" in terminal.
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.
I think this looks good. My one suggestion for the description is to be a bit more descriptive on what shell integration might enable or disable from the user perspective so users may better understand what might change in their experience.
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.
Thanks for the feedback! Made some changes here: 8e8dd18
So it would look like:
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.
debating between
vs
vs
vs
for the title
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.
I think I like the one that is there currently (option 1)!