Some cleanup

This commit is contained in:
Reinier Criel 2025-11-06 11:02:03 -08:00
parent a6956db8dc
commit 9bd29056c6
4 changed files with 10 additions and 70 deletions

View file

@ -8,12 +8,12 @@ import { main } from "../src/main.js";
// Set eco system
setEcoSystem(ECOSYSTEM_PY);
// Strip '-m pip' or '-m pip3' from args if present
// Strip nodejs and wrapper script from args
let argv = process.argv.slice(2);
if (argv[0] === '-m' && argv[1] === 'pip') {
// If no args are passed, argv[0] and argv[1] are undefined, so this condition just evaluates to false and does not throw.
if (argv[0] === '-m' && (argv[1] === 'pip' || argv[1] === 'pip3')) {
setEcoSystem(ECOSYSTEM_PY);
setCurrentPipInvocation(PIP_INVOCATIONS.PY_PIP);
setCurrentPipInvocation(argv[1] === 'pip3' ? PIP_INVOCATIONS.PY3_PIP : PIP_INVOCATIONS.PY_PIP);
initializePackageManager(PIP_PACKAGE_MANAGER);
argv = argv.slice(2);
var exitCode = await main(argv);

View file

@ -10,12 +10,12 @@ setEcoSystem(ECOSYSTEM_PY);
// Strip nodejs and wrapper script from args
let argv = process.argv.slice(2);
if (argv[0] === '-m' && argv[1] === 'pip') {
// If no args are passed, argv[0] and argv[1] are undefined, so this condition just evaluates to false and does not throw.
if (argv[0] === '-m' && (argv[1] === 'pip' || argv[1] === 'pip3')) {
setEcoSystem(ECOSYSTEM_PY);
setCurrentPipInvocation(PIP_INVOCATIONS.PY3_PIP);
setCurrentPipInvocation(argv[1] === 'pip3' ? PIP_INVOCATIONS.PY3_PIP : PIP_INVOCATIONS.PY_PIP);
initializePackageManager(PIP_PACKAGE_MANAGER);
// Strip '-m pip' or '-m pip3' from args if present
argv = argv.slice(2);
argv = argv.slice(2);
var exitCode = await main(argv);
process.exit(exitCode);
} else {

View file

@ -146,66 +146,5 @@ describe("Setup CI shell integration", () => {
const unixNpmShim = path.join(mockShimsDir, "npm");
assert.ok(!fs.existsSync(unixNpmShim), "Unix npm shim should not exist on Windows");
});
it("should create python and python3 shims from unix-python wrapper template", async () => {
// Add unix-python wrapper template to mock templates
const unixPythonTemplatePath = path.join(
mockTemplateDir,
"path-wrappers",
"templates",
"unix-python-wrapper.template.sh"
);
fs.writeFileSync(
unixPythonTemplatePath,
"#!/bin/bash\n# Python wrapper\nexec aikido-pip \"$@\"\n",
"utf-8"
);
await setupCi();
// Check if python shim was created
const pythonShimPath = path.join(mockShimsDir, "python");
assert.ok(fs.existsSync(pythonShimPath), "python shim should exist");
// Check if python3 shim was created
const python3ShimPath = path.join(mockShimsDir, "python3");
assert.ok(fs.existsSync(python3ShimPath), "python3 shim should exist");
// Check content of python shim
const pythonShimContent = fs.readFileSync(pythonShimPath, "utf-8");
assert.ok(pythonShimContent.includes("Python wrapper"), "python shim should use unix-python wrapper template");
// Check content of python3 shim
const python3ShimContent = fs.readFileSync(python3ShimPath, "utf-8");
assert.ok(python3ShimContent.includes("Python wrapper"), "python3 shim should use unix-python wrapper template");
});
it("should create python.cmd and python3.cmd shims from windows-python wrapper template on win32 platform", async () => {
mockPlatform = "win32";
// Add windows-python wrapper template to mock templates
const windowsPythonTemplatePath = path.join(
mockTemplateDir,
"path-wrappers",
"templates",
"windows-python-wrapper.template.cmd"
);
fs.writeFileSync(
windowsPythonTemplatePath,
"@echo off\nREM Python wrapper\n{{AIKIDO_COMMAND}} %*\n",
"utf-8"
);
await setupCi();
// Check if python.cmd shim was created
const pythonCmdShimPath = path.join(mockShimsDir, "python.cmd");
assert.ok(fs.existsSync(pythonCmdShimPath), "python.cmd shim should exist");
// Check if python3.cmd shim was created
const python3CmdShimPath = path.join(mockShimsDir, "python3.cmd");
assert.ok(fs.existsSync(python3CmdShimPath), "python3.cmd shim should exist");
// Check content of python.cmd shim
const pythonCmdShimContent = fs.readFileSync(pythonCmdShimPath, "utf-8");
assert.ok(pythonCmdShimContent.includes("Python wrapper"), "python.cmd should use windows-python wrapper template");
// Check content of python3.cmd shim
const python3CmdShimContent = fs.readFileSync(python3CmdShimPath, "utf-8");
assert.ok(python3CmdShimContent.includes("Python wrapper"), "python3.cmd should use windows-python wrapper template");
});
});
});
});