Skip to content
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

fix: python versions < 3.4 broken by previous addition #1141

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ let terminal: Terminal | undefined;

const framework = workspace.getConfiguration('pyright').get<TestingFramework>('testing.provider', 'unittest');

function validPythonModule(pythonPath: string, moduleName: string) {
function pythonSupportsPathFinder(pythonPath: string) {
try {
const pythonProcess = child_process.spawnSync(
pythonPath,
['-c', `from importlib.machinery import PathFinder; assert PathFinder.find_spec("${moduleName}") is not None`],
['-c', 'from sys import version_info; exit(0) if (version_info[0] >= 3 and version_info[1] >= 4) else exit(1)'],
{ encoding: 'utf8' },
);
if (pythonProcess.error) return false;
Expand All @@ -23,6 +23,19 @@ function validPythonModule(pythonPath: string, moduleName: string) {
}
}

function validPythonModule(pythonPath: string, moduleName: string) {
const pythonArgs = pythonSupportsPathFinder(pythonPath)
? ['-c', `from importlib.machinery import PathFinder; assert PathFinder.find_spec("${moduleName}") is not None`]
: ['-m', moduleName, '--help'];
try {
const pythonProcess = child_process.spawnSync(pythonPath, pythonArgs, { encoding: 'utf8' });
if (pythonProcess.error) return false;
return pythonProcess.status === 0;
} catch (ex) {
return false;
}
}

async function runTest(uri: string, testFunction?: string) {
const workspaceUri = Uri.parse(workspace.root).toString();
const relativeFileUri = uri.replace(`${workspaceUri}/`, '');
Expand Down
Loading