Skip to content

Commit d091652

Browse files
committed
Add a fix for python 3.12
The python extractor does not yet support 3.12. Check for this and instead make sure we run python 3.11. Only need to check on windows since we are extremely unlikely to be running 3.12 on linux or macos.
1 parent a2dc5ff commit d091652

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

lib/init-action.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python-setup/check_python12.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
#! /usr/bin/pwsh
3+
4+
# If we are running greater than or equal to python 3.12, change py to run version 3.11
5+
Write-Host "Checking python version"
6+
if ((py -3 -c "import sys; print(0 if sys.version_info >= (3, 12) else 1)") -eq "0") {
7+
Write-Host "Python 3.12+ detected, setting PY_PYTHON3=3.11"
8+
# First make sure we have python 3.11 installed
9+
py -3.11 -c "import imp"
10+
if ($LASTEXITCODE -eq 0) {
11+
Write-Host "Python 3.11 detected, using this version instead of 3.12+."
12+
Write-Output "PY_PYTHON3=3.11" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
13+
} else {
14+
Write-Host "FAILURE: Python 3.12+ is not supported. Please install Python 3.11."
15+
exit 1
16+
}
17+
} else {
18+
Write-Host "Python 3.12+ not detected, not making any changes."
19+
}

src/init-action.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import { CodeQL } from "./codeql";
1717
import * as configUtils from "./config-utils";
1818
import { EnvVar } from "./environment";
1919
import { Feature, Features } from "./feature-flags";
20-
import { initCodeQL, initConfig, installPythonDeps, runInit } from "./init";
20+
import {
21+
checkInstallPython311,
22+
initCodeQL,
23+
initConfig,
24+
installPythonDeps,
25+
runInit,
26+
} from "./init";
2127
import { Language } from "./languages";
2228
import { getActionsLogger, Logger } from "./logging";
2329
import { parseRepositoryNwo } from "./repository";
@@ -277,6 +283,8 @@ async function run() {
277283
logger,
278284
);
279285

286+
await checkInstallPython311(config.languages);
287+
280288
if (
281289
config.languages.includes(Language.python) &&
282290
getRequiredInput("setup-python-dependencies") === "true"

src/init.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
FeatureEnablement,
1414
useCodeScanningConfigInCli,
1515
} from "./feature-flags";
16+
import { Language } from "./languages";
1617
import { Logger } from "./logging";
1718
import { RepositoryNwo } from "./repository";
1819
import { ToolsSource } from "./setup-codeql";
@@ -181,6 +182,23 @@ function processError(e: any): Error {
181182
return e;
182183
}
183184

185+
/**
186+
* If we are running python 3.12+ on windows, we need to switch to python 3.11.
187+
* This check happens in a powershell script.
188+
*/
189+
export async function checkInstallPython311(languages: Language[]) {
190+
if (languages.includes(Language.python) && process.platform === "win32") {
191+
const script = path.resolve(
192+
__dirname,
193+
"../python-setup",
194+
"check_python12.ps1",
195+
);
196+
await new toolrunner.ToolRunner(await safeWhich.safeWhich("powershell"), [
197+
script,
198+
]).exec();
199+
}
200+
}
201+
184202
export async function installPythonDeps(codeql: CodeQL, logger: Logger) {
185203
logger.startGroup("Setup Python dependencies");
186204

0 commit comments

Comments
 (0)