Skip to content

Commit 0ccdbf8

Browse files
committedMay 11, 2023
Feature flag to disable python dependency installation
1 parent 95cfca7 commit 0ccdbf8

9 files changed

+91
-15
lines changed
 

Diff for: ‎lib/analyze.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎lib/analyze.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎lib/feature-flags.js

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎lib/feature-flags.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎lib/init-action.js

+14-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎lib/init-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎src/analyze.ts

+14
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ async function setupPythonExtractor(logger: Logger) {
8787
return;
8888
}
8989

90+
// CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION is the internal environment
91+
// variable used by the python extractor. This is set in init-action.ts only if the
92+
// feature-flag is enabled.
93+
if (
94+
(process.env["CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION"] || "")
95+
.length > 0
96+
) {
97+
logger.warning(
98+
"Library extraction is disabled now. Please remove your logic that sets the CODEQL_PYTHON environment variable." +
99+
"\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."
100+
);
101+
return;
102+
}
103+
90104
const scriptsFolder = path.resolve(__dirname, "../python-setup");
91105

92106
let output = "";

Diff for: ‎src/feature-flags.ts

+11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export enum Feature {
4343
ExportDiagnosticsEnabled = "export_diagnostics_enabled",
4444
MlPoweredQueriesEnabled = "ml_powered_queries_enabled",
4545
UploadFailedSarifEnabled = "upload_failed_sarif_enabled",
46+
DisablePythonDependencyInstallation = "disable_python_dependency_installation",
4647
}
4748

4849
export const featureConfig: Record<
@@ -80,6 +81,16 @@ export const featureConfig: Record<
8081
minimumVersion: "2.11.3",
8182
defaultValue: true,
8283
},
84+
[Feature.DisablePythonDependencyInstallation]: {
85+
envVar: "CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION",
86+
// Although the python extractor only started supporting not extracting installed
87+
// dependencies in 2.13.1, the init-action can still benefit from not installing
88+
// dependencies no matter what codeql version we are using, so therefore the
89+
// minimumVersion is set to 'undefined'. This means that with an old CodeQL version,
90+
// packages available with current python3 installation might get extracted.
91+
minimumVersion: undefined,
92+
defaultValue: false,
93+
},
8394
};
8495

8596
/**

Diff for: ‎src/init-action.ts

+29-7
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,22 @@ async function run() {
277277
config.languages.includes(Language.python) &&
278278
getRequiredInput("setup-python-dependencies") === "true"
279279
) {
280-
try {
281-
await installPythonDeps(codeql, logger);
282-
} catch (unwrappedError) {
283-
const error = wrapError(unwrappedError);
284-
logger.warning(
285-
`${error.message} You can call this action with 'setup-python-dependencies: false' to disable this process`
286-
);
280+
if (
281+
await features.getValue(
282+
Feature.DisablePythonDependencyInstallation,
283+
codeql
284+
)
285+
) {
286+
logger.info("Skipping python dependency installation");
287+
} else {
288+
try {
289+
await installPythonDeps(codeql, logger);
290+
} catch (unwrappedError) {
291+
const error = wrapError(unwrappedError);
292+
logger.warning(
293+
`${error.message} You can call this action with 'setup-python-dependencies: false' to disable this process`
294+
);
295+
}
287296
}
288297
}
289298
} catch (unwrappedError) {
@@ -331,6 +340,19 @@ async function run() {
331340
core.exportVariable("CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN", "true");
332341
}
333342

343+
// Disable Python dependency extraction if feature flag set
344+
if (
345+
await features.getValue(
346+
Feature.DisablePythonDependencyInstallation,
347+
codeql
348+
)
349+
) {
350+
core.exportVariable(
351+
"CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION",
352+
"true"
353+
);
354+
}
355+
334356
const sourceRoot = path.resolve(
335357
getRequiredEnvParam("GITHUB_WORKSPACE"),
336358
getOptionalInput("source-root") || ""

0 commit comments

Comments
 (0)
Please sign in to comment.