-
Notifications
You must be signed in to change notification settings - Fork 86
Support for PDM package manager (Python) #399
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1eb4fe0
Add pdm package manager support
chris-greenpixie ced5e26
File mode on aikido-pdm.js
chris-greenpixie 42102eb
Merge branch 'main' into feat/pdm-support
chris-greenpixie abbe048
Merge branch 'main' into feat/pdm-support
chris-greenpixie 8453012
Merge remote-tracking branch 'aikido/main' into feat/pdm-support
chris-greenpixie 54db058
Use getPackageManagerList in safe-chain setup help text
chris-greenpixie ffe7f8d
Use numpy==2.4.4 as test malware in pdm e2e tests
chris-greenpixie 8ab5ceb
Match actual block output in pdm e2e assertions
chris-greenpixie a1b89a5
Make block-count assertions count-agnostic in bun e2e
chris-greenpixie bf2d37d
Merge branch 'main' into feat/pdm-support
chris-greenpixie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { main } from "../src/main.js"; | ||
| import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js"; | ||
| import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js"; | ||
|
|
||
| setEcoSystem(ECOSYSTEM_PY); | ||
| initializePackageManager("pdm"); | ||
|
|
||
| (async () => { | ||
| var exitCode = await main(process.argv.slice(2)); | ||
| process.exit(exitCode); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/safe-chain/src/packagemanager/pdm/createPdmPackageManager.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { ui } from "../../environment/userInteraction.js"; | ||
| import { safeSpawn } from "../../utils/safeSpawn.js"; | ||
| import { mergeSafeChainProxyEnvironmentVariables } from "../../registryProxy/registryProxy.js"; | ||
| import { getCombinedCaBundlePath } from "../../registryProxy/certBundle.js"; | ||
| import { reportCommandExecutionFailure } from "../_shared/commandErrors.js"; | ||
|
|
||
| /** | ||
| * @returns {import("../currentPackageManager.js").PackageManager} | ||
| */ | ||
| export function createPdmPackageManager() { | ||
| return { | ||
| runCommand: (args) => runPdmCommand(args), | ||
|
|
||
| // MITM only approach for PDM | ||
| isSupportedCommand: () => false, | ||
| getDependencyUpdatesForCommand: () => [], | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Sets CA bundle environment variables used by PDM and Python libraries. | ||
| * PDM uses httpx (via unearth) which respects SSL_CERT_FILE through Python's ssl module. | ||
| * | ||
| * @param {NodeJS.ProcessEnv} env - Environment object to modify | ||
| * @param {string} combinedCaPath - Path to the combined CA bundle | ||
| */ | ||
| function setPdmCaBundleEnvironmentVariables(env, combinedCaPath) { | ||
| // SSL_CERT_FILE: Used by Python SSL libraries and httpx (which PDM uses) | ||
| if (env.SSL_CERT_FILE) { | ||
| ui.writeWarning("Safe-chain: User defined SSL_CERT_FILE found in environment. It will be overwritten."); | ||
| } | ||
| env.SSL_CERT_FILE = combinedCaPath; | ||
|
|
||
| // REQUESTS_CA_BUNDLE: Used by the requests library (PDM plugins may use it) | ||
| if (env.REQUESTS_CA_BUNDLE) { | ||
| ui.writeWarning("Safe-chain: User defined REQUESTS_CA_BUNDLE found in environment. It will be overwritten."); | ||
| } | ||
| env.REQUESTS_CA_BUNDLE = combinedCaPath; | ||
|
|
||
| // PIP_CERT: PDM may use pip internally | ||
| if (env.PIP_CERT) { | ||
| ui.writeWarning("Safe-chain: User defined PIP_CERT found in environment. It will be overwritten."); | ||
| } | ||
| env.PIP_CERT = combinedCaPath; | ||
| } | ||
|
|
||
| /** | ||
| * Runs a pdm command with safe-chain's certificate bundle and proxy configuration. | ||
| * | ||
| * PDM respects standard HTTP_PROXY/HTTPS_PROXY environment variables through | ||
| * httpx which it uses for package downloads. | ||
| * | ||
| * @param {string[]} args - Command line arguments to pass to pdm | ||
| * @returns {Promise<{status: number}>} Exit status of the pdm command | ||
| */ | ||
| async function runPdmCommand(args) { | ||
| try { | ||
| const env = mergeSafeChainProxyEnvironmentVariables(process.env); | ||
|
|
||
| const combinedCaPath = getCombinedCaBundlePath(); | ||
| setPdmCaBundleEnvironmentVariables(env, combinedCaPath); | ||
|
|
||
| const result = await safeSpawn("pdm", args, { | ||
| stdio: "inherit", | ||
| env, | ||
| }); | ||
|
|
||
| return { status: result.status }; | ||
| } catch (/** @type any */ error) { | ||
| return reportCommandExecutionFailure(error, "pdm"); | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
packages/safe-chain/src/packagemanager/pdm/createPdmPackageManager.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert"; | ||
| import { createPdmPackageManager } from "./createPdmPackageManager.js"; | ||
|
|
||
| test("createPdmPackageManager", async (t) => { | ||
| await t.test("should create package manager with required interface", () => { | ||
| const pm = createPdmPackageManager(); | ||
|
|
||
| assert.ok(pm); | ||
| assert.strictEqual(typeof pm.runCommand, "function"); | ||
| assert.strictEqual(typeof pm.isSupportedCommand, "function"); | ||
| assert.strictEqual(typeof pm.getDependencyUpdatesForCommand, "function"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setPdmCaBundleEnvironmentVariables mutates its 'env' parameter by assigning SSL_CERT_FILE / REQUESTS_CA_BUNDLE / PIP_CERT, causing side effects on the caller-provided object; avoid modifying the input argument directly.
Details
✨ AI Reasoning
A function added in this change modifies the passed-in 'env' object by assigning properties on it. Mutating a parameter makes it harder to reason about the original value and can produce surprising side effects for callers. The change alters program state via the argument rather than returning a new modified value, which increases coupling between caller and callee and can hide where environment changes occur.
🔧 How do I fix it?
Create new local variables instead of reassigning parameters. Use different variable names to clearly distinguish between input and modified values.
Reply
@AikidoSec feedback: [FEEDBACK]to get better review comments in the future.Reply
@AikidoSec ignore: [REASON]to ignore this issue.More info