Skip to content

Commit c7eea24

Browse files
committed
Remove python dependency installation logic
I've left a few warning logging cases, but overall this feature is no longer supported.
1 parent 3bd9c3e commit c7eea24

File tree

4 files changed

+16
-146
lines changed

4 files changed

+16
-146
lines changed

src/analyze.ts

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { EnvVar } from "./environment";
2020
import {
2121
FeatureEnablement,
2222
Feature,
23-
isPythonDependencyInstallationDisabled,
2423
} from "./feature-flags";
2524
import { isScannedLanguage, Language } from "./languages";
2625
import { Logger } from "./logging";
@@ -123,50 +122,18 @@ export interface QueriesStatusReport {
123122

124123
async function setupPythonExtractor(
125124
logger: Logger,
126-
features: FeatureEnablement,
127-
codeql: CodeQL,
128125
) {
129126
const codeqlPython = process.env["CODEQL_PYTHON"];
130127
if (codeqlPython === undefined || codeqlPython.length === 0) {
131128
// If CODEQL_PYTHON is not set, no dependencies were installed, so we don't need to do anything
132129
return;
133130
}
134131

135-
if (await isPythonDependencyInstallationDisabled(codeql, features)) {
136-
logger.warning(
137-
"We recommend that you remove the CODEQL_PYTHON environment variable from your workflow. This environment variable was originally used to specify a Python executable that included the dependencies of your Python code, however Python analysis no longer uses these dependencies." +
138-
"\nIf you used CODEQL_PYTHON to force the version of Python to analyze as, please use CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION instead, such as 'CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=2.7' or 'CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=3.11'.",
139-
);
140-
return;
141-
}
142-
143-
const scriptsFolder = path.resolve(__dirname, "../python-setup");
144-
145-
let output = "";
146-
const options = {
147-
listeners: {
148-
stdout: (data: Buffer) => {
149-
output += data.toString();
150-
},
151-
},
152-
};
153-
154-
await new toolrunner.ToolRunner(
155-
codeqlPython,
156-
[path.join(scriptsFolder, "find_site_packages.py")],
157-
options,
158-
).exec();
159-
logger.info(`Setting LGTM_INDEX_IMPORT_PATH=${output}`);
160-
process.env["LGTM_INDEX_IMPORT_PATH"] = output;
161-
162-
output = "";
163-
await new toolrunner.ToolRunner(
164-
codeqlPython,
165-
["-c", "import sys; print(sys.version_info[0])"],
166-
options,
167-
).exec();
168-
logger.info(`Setting LGTM_PYTHON_SETUP_VERSION=${output}`);
169-
process.env["LGTM_PYTHON_SETUP_VERSION"] = output;
132+
logger.warning(
133+
"CODEQL_PYTHON environment variable is no longer supported. Please remove it from your workflow. This environment variable was originally used to specify a Python executable that included the dependencies of your Python code, however Python analysis no longer uses these dependencies." +
134+
"\nIf you used CODEQL_PYTHON to force the version of Python to analyze as, please use CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION instead, such as 'CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=2.7' or 'CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=3.11'.",
135+
);
136+
return;
170137
}
171138

172139
export async function runExtraction(
@@ -186,7 +153,7 @@ export async function runExtraction(
186153
if (shouldExtractLanguage(config, language)) {
187154
logger.startGroup(`Extracting ${language}`);
188155
if (language === Language.python) {
189-
await setupPythonExtractor(logger, features, codeql);
156+
await setupPythonExtractor(logger);
190157
}
191158
if (
192159
config.buildMode &&

src/feature-flags.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export enum Feature {
4949
CppTrapCachingEnabled = "cpp_trap_caching_enabled",
5050
DisableJavaBuildlessEnabled = "disable_java_buildless_enabled",
5151
DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled",
52-
DisablePythonDependencyInstallationEnabled = "disable_python_dependency_installation_enabled",
53-
PythonDefaultIsToSkipDependencyInstallationEnabled = "python_default_is_to_skip_dependency_installation_enabled",
5452
ExportDiagnosticsEnabled = "export_diagnostics_enabled",
5553
QaTelemetryEnabled = "qa_telemetry_enabled",
5654
}
@@ -95,25 +93,6 @@ export const featureConfig: Record<
9593
minimumVersion: undefined,
9694
defaultValue: false,
9795
},
98-
[Feature.DisablePythonDependencyInstallationEnabled]: {
99-
envVar: "CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION",
100-
// Although the python extractor only started supporting not extracting installed
101-
// dependencies in 2.13.1, the init-action can still benefit from not installing
102-
// dependencies no matter what codeql version we are using, so therefore the
103-
// minimumVersion is set to 'undefined'. This means that with an old CodeQL version,
104-
// packages available with current python3 installation might get extracted.
105-
minimumVersion: undefined,
106-
defaultValue: false,
107-
},
108-
[Feature.PythonDefaultIsToSkipDependencyInstallationEnabled]: {
109-
// we can reuse the same environment variable as above. If someone has set it to
110-
// `true` in their workflow this means dependencies are not installed, setting it to
111-
// `false` means dependencies _will_ be installed. The same semantics are applied
112-
// here!
113-
envVar: "CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION",
114-
minimumVersion: "2.16.0",
115-
defaultValue: true,
116-
},
11796
};
11897

11998
/**
@@ -458,19 +437,3 @@ class GitHubFeatureFlags {
458437
}
459438
}
460439
}
461-
462-
export async function isPythonDependencyInstallationDisabled(
463-
codeql: CodeQL,
464-
features: FeatureEnablement,
465-
): Promise<boolean> {
466-
return (
467-
(await features.getValue(
468-
Feature.DisablePythonDependencyInstallationEnabled,
469-
codeql,
470-
)) ||
471-
(await features.getValue(
472-
Feature.PythonDefaultIsToSkipDependencyInstallationEnabled,
473-
codeql,
474-
))
475-
);
476-
}

src/init-action.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ import { EnvVar } from "./environment";
1919
import {
2020
Feature,
2121
Features,
22-
isPythonDependencyInstallationDisabled,
2322
} from "./feature-flags";
2423
import {
2524
checkInstallPython311,
2625
initCodeQL,
2726
initConfig,
28-
installPythonDeps,
2927
runInit,
3028
} from "./init";
3129
import { Language } from "./languages";
@@ -294,24 +292,6 @@ async function run() {
294292
);
295293

296294
await checkInstallPython311(config.languages, codeql);
297-
298-
if (
299-
config.languages.includes(Language.python) &&
300-
getRequiredInput("setup-python-dependencies") === "true"
301-
) {
302-
if (await isPythonDependencyInstallationDisabled(codeql, features)) {
303-
logger.info("Skipping python dependency installation");
304-
} else {
305-
try {
306-
await installPythonDeps(codeql, logger);
307-
} catch (unwrappedError) {
308-
const error = wrapError(unwrappedError);
309-
logger.warning(
310-
`${error.message} You can call this action with 'setup-python-dependencies: false' to disable this process`,
311-
);
312-
}
313-
}
314-
}
315295
} catch (unwrappedError) {
316296
const error = wrapError(unwrappedError);
317297
core.setFailed(error.message);
@@ -462,18 +442,21 @@ async function run() {
462442
}
463443
}
464444

465-
// Disable Python dependency extraction if feature flag set
466-
if (await isPythonDependencyInstallationDisabled(codeql, features)) {
445+
// Disable Python dependency extraction if feature flag set From 2.16.0 the default
446+
// for the python extractor is to not perform any library extraction. For versions
447+
// before that, you needed to set this flag to enable this behavior (supported since
448+
// 2.13.1). Since dependency installation is no longer supported in the action, we
449+
450+
if (await codeQlVersionAbove(codeql, "2.16.0")) {
451+
// do nothing
452+
} else if (await codeQlVersionAbove(codeql, "2.13.1")) {
467453
core.exportVariable(
468454
"CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION",
469455
"true",
470456
);
471457
} else {
472-
// From 2.16.0 the default for the python extractor is to not perform any library
473-
// extraction, so we need to set this flag to enable it.
474-
core.exportVariable(
475-
"CODEQL_EXTRACTOR_PYTHON_FORCE_ENABLE_LIBRARY_EXTRACTION_UNTIL_2_17_0",
476-
"true",
458+
logger.warning(
459+
"codeql-action no longer installs Python dependencies. We recommend upgrading to at least CodeQL 2.16.0 to avoid any potential problems due to this.",
477460
);
478461
}
479462

src/init.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -138,46 +138,3 @@ export async function checkInstallPython311(
138138
]).exec();
139139
}
140140
}
141-
142-
export async function installPythonDeps(codeql: CodeQL, logger: Logger) {
143-
logger.startGroup("Setup Python dependencies");
144-
145-
const scriptsFolder = path.resolve(__dirname, "../python-setup");
146-
147-
try {
148-
if (process.platform === "win32") {
149-
await new toolrunner.ToolRunner(await safeWhich.safeWhich("powershell"), [
150-
path.join(scriptsFolder, "install_tools.ps1"),
151-
]).exec();
152-
} else {
153-
await new toolrunner.ToolRunner(
154-
path.join(scriptsFolder, "install_tools.sh"),
155-
).exec();
156-
}
157-
const script = "auto_install_packages.py";
158-
if (process.platform === "win32") {
159-
await new toolrunner.ToolRunner(await safeWhich.safeWhich("py"), [
160-
"-3",
161-
"-B",
162-
path.join(scriptsFolder, script),
163-
path.dirname(codeql.getPath()),
164-
]).exec();
165-
} else {
166-
await new toolrunner.ToolRunner(await safeWhich.safeWhich("python3"), [
167-
"-B",
168-
path.join(scriptsFolder, script),
169-
path.dirname(codeql.getPath()),
170-
]).exec();
171-
}
172-
} catch (e) {
173-
logger.endGroup();
174-
logger.warning(
175-
`An error occurred while trying to automatically install Python dependencies: ${e}\n` +
176-
"Please make sure any necessary dependencies are installed before calling the codeql-action/analyze " +
177-
"step, and add a 'setup-python-dependencies: false' argument to this step to disable our automatic " +
178-
"dependency installation and avoid this warning.",
179-
);
180-
return;
181-
}
182-
logger.endGroup();
183-
}

0 commit comments

Comments
 (0)