Skip to content

Commit

Permalink
Merged PR posit-dev/positron-python#297: Merge vscode-python 2023.22.…
Browse files Browse the repository at this point in the history
…1 from upstream

Merge pull request #297 from posit-dev/merge/upstream-aug-2023.22.1

Merge vscode-python 2023.22.1 from upstream
--------------------
Commit message for posit-dev/positron-python@e0d7a6a:

Merge commit 'c26d5e79cfeea424a077f8703455de7e9ac7437e'

--------------------
Commit message for posit-dev/positron-python@c26d5e7:

update version for point release 2023.22.1

--------------------
Commit message for posit-dev/positron-python@c3364b5:

More fixes to pre-release (posit-dev/positron-python#22641)

Further followup to
microsoft/vscode-python#22640
--------------------
Commit message for posit-dev/positron-python@0a570b5:

More fixes to pre-release (posit-dev/positron-python#22640)

Following up to microsoft/vscode-python#22638
--------------------
Commit message for posit-dev/positron-python@a712e12:

Fix localization failure for pre-release (posit-dev/positron-python#22639)

Fixes pre-release, dynamic strings are not supported by localization.
--------------------
Commit message for posit-dev/positron-python@d31b870:

Revert "Remove old code for folder support in interpreter path setting" (posit-dev/positron-python#22638)

Reverts microsoft/vscode-python#22413
microsoft/vscode-python#22618

Turns out we still need this code for old deprecated APIs that we
expose, one of which is used in testing.
--------------------
Commit message for posit-dev/positron-python@780870a:

finalized-release-2023.22 (posit-dev/positron-python#22608)

update to final release number for 2023.22

Lead-authored-by: Kartik Raj <karraj@microsoft.com>
Co-authored-by: eleanorjboyd <eleanorboyd@microsoft.com>
Co-authored-by: Wasim Lorgat <mwlorgat@gmail.com>
Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
3 people committed Dec 26, 2023
1 parent 13c005c commit bbe9ae5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
65 changes: 64 additions & 1 deletion extensions/positron-python/src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// eslint-disable-next-line camelcase
import * as path from 'path';
import * as fs from 'fs';
import {
ConfigurationChangeEvent,
ConfigurationTarget,
Expand Down Expand Up @@ -35,6 +36,8 @@ import {
} from './types';
import { debounceSync } from './utils/decorators';
import { SystemVariables } from './variables/systemVariables';
import { getOSType, OSType } from './utils/platform';
import { isWindows } from './platform/platformService';

const untildify = require('untildify');

Expand Down Expand Up @@ -412,7 +415,7 @@ export class PythonSettings implements IPythonSettings {

// eslint-disable-next-line class-methods-use-this
protected getPythonExecutable(pythonPath: string): string {
return untildify(pythonPath);
return getPythonExecutable(pythonPath);
}

protected onWorkspaceFoldersChanged(): void {
Expand Down Expand Up @@ -511,3 +514,63 @@ function getAbsolutePath(pathToCheck: string, rootDir: string | undefined): stri
}
return path.isAbsolute(pathToCheck) ? pathToCheck : path.resolve(rootDir, pathToCheck);
}

function getPythonExecutable(pythonPath: string): string {
pythonPath = untildify(pythonPath) as string;

// If only 'python'.
if (
pythonPath === 'python' ||
pythonPath.indexOf(path.sep) === -1 ||
path.basename(pythonPath) === path.dirname(pythonPath)
) {
return pythonPath;
}

if (isValidPythonPath(pythonPath)) {
return pythonPath;
}
// Keep python right on top, for backwards compatibility.

const KnownPythonExecutables = [
'python',
'python4',
'python3.6',
'python3.5',
'python3',
'python2.7',
'python2',
'python3.7',
'python3.8',
'python3.9',
];

for (let executableName of KnownPythonExecutables) {
// Suffix with 'python' for linux and 'osx', and 'python.exe' for 'windows'.
if (isWindows()) {
executableName = `${executableName}.exe`;
if (isValidPythonPath(path.join(pythonPath, executableName))) {
return path.join(pythonPath, executableName);
}
if (isValidPythonPath(path.join(pythonPath, 'Scripts', executableName))) {
return path.join(pythonPath, 'Scripts', executableName);
}
} else {
if (isValidPythonPath(path.join(pythonPath, executableName))) {
return path.join(pythonPath, executableName);
}
if (isValidPythonPath(path.join(pythonPath, 'bin', executableName))) {
return path.join(pythonPath, 'bin', executableName);
}
}
}

return pythonPath;
}

function isValidPythonPath(pythonPath: string): boolean {
return (
fs.existsSync(pythonPath) &&
path.basename(getOSType() === OSType.Windows ? pythonPath.toLowerCase() : pythonPath).startsWith('python')
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export namespace Diagnostics {
export const pylanceDefaultMessage = l10n.t(
"The Python extension now includes Pylance to improve completions, code navigation, overall performance and much more! You can learn more about the update and learn how to change your language server [here](https://aka.ms/new-python-bundle).\n\nRead Pylance's license [here](https://marketplace.visualstudio.com/items/ms-python.vscode-pylance/license).",
);
export const invalidSmartSendMessage = l10n.t(`Python is unable to parse the code provided. Please
export const invalidSmartSendMessage = l10n.t(
`Python is unable to parse the code provided. Please
turn off Smart Send if you wish to always run line by line or explicitly select code
to force run. See [logs](command:${Commands.ViewOutput}) for more details`);
to force run. See [logs](command:{0}) for more details`,
Commands.ViewOutput,
);
}

export namespace Common {
Expand Down
3 changes: 2 additions & 1 deletion extensions/positron-python/src/client/logging/settingLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ async function notifyLegacySettings(): Promise<void> {
_isShown = true;
const response = await showWarningMessage(
l10n.t(
`You have deprecated linting or formatting settings for Python. Please see the [logs](command:${Commands.ViewOutput}) for more details.`,
'You have deprecated linting or formatting settings for Python. Please see the [logs](command:{0}) for more details.',
Commands.ViewOutput,
),
Common.learnMore,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function parseDiagnostics(data: string): Diagnostic[] {
diagnostics = raw.map((item) => {
const d = new Diagnostic(
new Range(item.line, item.character, item.endLine, item.endCharacter),
l10n.t(`Package \`${item.package}\` is not installed in the selected environment.`),
l10n.t('Package `{0}` is not installed in the selected environment.', item.package),
item.severity,
);
d.code = { value: item.code, target: Uri.parse(`https://pypi.org/p/${item.package}`) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,8 @@ suite('REPL - Smart Send', () => {
.setup((a) =>
a.showWarningMessage(
l10n.t(
`Python is unable to parse the code provided. Please
turn off Smart Send if you wish to always run line by line or explicitly select code
to force run. [logs](command:${Commands.ViewOutput}) for more details.`,
'Python is unable to parse the code provided. Please turn off Smart Send if you wish to always run line by line or explicitly select code to force run. [logs](command:{0}) for more details.',
Commands.ViewOutput,
),
'Switch to line-by-line',
),
Expand Down

0 comments on commit bbe9ae5

Please sign in to comment.