Skip to content

Commit bbe9ae5

Browse files
Kartik RajeleanorjboydseeM
committed
Merged PR posit-dev/positron-python#297: Merge vscode-python 2023.22.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 <[email protected]> Co-authored-by: eleanorjboyd <[email protected]> Co-authored-by: Wasim Lorgat <[email protected]> Signed-off-by: GitHub <[email protected]>
1 parent 13c005c commit bbe9ae5

File tree

5 files changed

+74
-8
lines changed

5 files changed

+74
-8
lines changed

extensions/positron-python/src/client/common/configSettings.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// eslint-disable-next-line camelcase
44
import * as path from 'path';
5+
import * as fs from 'fs';
56
import {
67
ConfigurationChangeEvent,
78
ConfigurationTarget,
@@ -35,6 +36,8 @@ import {
3536
} from './types';
3637
import { debounceSync } from './utils/decorators';
3738
import { SystemVariables } from './variables/systemVariables';
39+
import { getOSType, OSType } from './utils/platform';
40+
import { isWindows } from './platform/platformService';
3841

3942
const untildify = require('untildify');
4043

@@ -412,7 +415,7 @@ export class PythonSettings implements IPythonSettings {
412415

413416
// eslint-disable-next-line class-methods-use-this
414417
protected getPythonExecutable(pythonPath: string): string {
415-
return untildify(pythonPath);
418+
return getPythonExecutable(pythonPath);
416419
}
417420

418421
protected onWorkspaceFoldersChanged(): void {
@@ -511,3 +514,63 @@ function getAbsolutePath(pathToCheck: string, rootDir: string | undefined): stri
511514
}
512515
return path.isAbsolute(pathToCheck) ? pathToCheck : path.resolve(rootDir, pathToCheck);
513516
}
517+
518+
function getPythonExecutable(pythonPath: string): string {
519+
pythonPath = untildify(pythonPath) as string;
520+
521+
// If only 'python'.
522+
if (
523+
pythonPath === 'python' ||
524+
pythonPath.indexOf(path.sep) === -1 ||
525+
path.basename(pythonPath) === path.dirname(pythonPath)
526+
) {
527+
return pythonPath;
528+
}
529+
530+
if (isValidPythonPath(pythonPath)) {
531+
return pythonPath;
532+
}
533+
// Keep python right on top, for backwards compatibility.
534+
535+
const KnownPythonExecutables = [
536+
'python',
537+
'python4',
538+
'python3.6',
539+
'python3.5',
540+
'python3',
541+
'python2.7',
542+
'python2',
543+
'python3.7',
544+
'python3.8',
545+
'python3.9',
546+
];
547+
548+
for (let executableName of KnownPythonExecutables) {
549+
// Suffix with 'python' for linux and 'osx', and 'python.exe' for 'windows'.
550+
if (isWindows()) {
551+
executableName = `${executableName}.exe`;
552+
if (isValidPythonPath(path.join(pythonPath, executableName))) {
553+
return path.join(pythonPath, executableName);
554+
}
555+
if (isValidPythonPath(path.join(pythonPath, 'Scripts', executableName))) {
556+
return path.join(pythonPath, 'Scripts', executableName);
557+
}
558+
} else {
559+
if (isValidPythonPath(path.join(pythonPath, executableName))) {
560+
return path.join(pythonPath, executableName);
561+
}
562+
if (isValidPythonPath(path.join(pythonPath, 'bin', executableName))) {
563+
return path.join(pythonPath, 'bin', executableName);
564+
}
565+
}
566+
}
567+
568+
return pythonPath;
569+
}
570+
571+
function isValidPythonPath(pythonPath: string): boolean {
572+
return (
573+
fs.existsSync(pythonPath) &&
574+
path.basename(getOSType() === OSType.Windows ? pythonPath.toLowerCase() : pythonPath).startsWith('python')
575+
);
576+
}

extensions/positron-python/src/client/common/utils/localize.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ export namespace Diagnostics {
4343
export const pylanceDefaultMessage = l10n.t(
4444
"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).",
4545
);
46-
export const invalidSmartSendMessage = l10n.t(`Python is unable to parse the code provided. Please
46+
export const invalidSmartSendMessage = l10n.t(
47+
`Python is unable to parse the code provided. Please
4748
turn off Smart Send if you wish to always run line by line or explicitly select code
48-
to force run. See [logs](command:${Commands.ViewOutput}) for more details`);
49+
to force run. See [logs](command:{0}) for more details`,
50+
Commands.ViewOutput,
51+
);
4952
}
5053

5154
export namespace Common {

extensions/positron-python/src/client/logging/settingLogs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ async function notifyLegacySettings(): Promise<void> {
9999
_isShown = true;
100100
const response = await showWarningMessage(
101101
l10n.t(
102-
`You have deprecated linting or formatting settings for Python. Please see the [logs](command:${Commands.ViewOutput}) for more details.`,
102+
'You have deprecated linting or formatting settings for Python. Please see the [logs](command:{0}) for more details.',
103+
Commands.ViewOutput,
103104
),
104105
Common.learnMore,
105106
);

extensions/positron-python/src/client/pythonEnvironments/creation/common/installCheckUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function parseDiagnostics(data: string): Diagnostic[] {
2727
diagnostics = raw.map((item) => {
2828
const d = new Diagnostic(
2929
new Range(item.line, item.character, item.endLine, item.endCharacter),
30-
l10n.t(`Package \`${item.package}\` is not installed in the selected environment.`),
30+
l10n.t('Package `{0}` is not installed in the selected environment.', item.package),
3131
item.severity,
3232
);
3333
d.code = { value: item.code, target: Uri.parse(`https://pypi.org/p/${item.package}`) };

extensions/positron-python/src/test/terminals/codeExecution/smartSend.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,8 @@ suite('REPL - Smart Send', () => {
300300
.setup((a) =>
301301
a.showWarningMessage(
302302
l10n.t(
303-
`Python is unable to parse the code provided. Please
304-
turn off Smart Send if you wish to always run line by line or explicitly select code
305-
to force run. [logs](command:${Commands.ViewOutput}) for more details.`,
303+
'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.',
304+
Commands.ViewOutput,
306305
),
307306
'Switch to line-by-line',
308307
),

0 commit comments

Comments
 (0)