Skip to content

Commit 21ce344

Browse files
authored
fix: correct cmd to get python version for pipenv projects (#244)
1 parent 9153154 commit 21ce344

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

lib/dependencies/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export async function getDependencies(
2727
options = {};
2828
}
2929
let command = options.command || 'python';
30+
const pythonCmd = command;
3031
const includeDevDeps = !!(options.dev || false);
3132

3233
// handle poetry projects by parsing manifest & lockfile and return a dep-graph
@@ -51,6 +52,7 @@ export async function getDependencies(
5152
getMetaData(command, baseargs, root, targetFile),
5253
inspectInstalledDeps(
5354
command,
55+
pythonCmd,
5456
baseargs,
5557
root,
5658
targetFile,

lib/dependencies/inspect-implementation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ async function updateSetuptools(
240240

241241
export async function inspectInstalledDeps(
242242
command: string,
243+
pythonCmd: string,
243244
baseargs: string[],
244245
root: string,
245246
targetFile: string,
@@ -261,7 +262,7 @@ export async function inspectInstalledDeps(
261262
UPDATED_SETUPTOOLS_VERSION,
262263
root,
263264
pythonEnv,
264-
command
265+
pythonCmd
265266
);
266267

267268
// See ../../pysrc/README.md

test/system/inspect.spec.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('inspect', () => {
100100
{
101101
pkg: {
102102
name: 'jaraco.collections',
103-
version: '5.0.0',
103+
version: '5.0.1',
104104
},
105105
directDeps: ['irc'],
106106
},
@@ -163,7 +163,7 @@ describe('inspect', () => {
163163
{
164164
pkg: {
165165
name: 's3transfer',
166-
version: '0.10.0',
166+
version: '0.10.2',
167167
},
168168
directDeps: ['awss'],
169169
},
@@ -205,7 +205,7 @@ describe('inspect', () => {
205205
{
206206
pkg: {
207207
name: 'jsonschema',
208-
version: '4.21.1',
208+
version: '4.23.0',
209209
},
210210
directDeps: ['openapi-spec-validator'],
211211
},
@@ -451,6 +451,49 @@ describe('inspect', () => {
451451
});
452452
});
453453

454+
describe('when testing pipenv projects simulating pipenv install', () => {
455+
let tearDown;
456+
457+
afterAll(() => {
458+
tearDown();
459+
});
460+
461+
it.each([
462+
{
463+
workspace: 'pipfile-pipapp-pinned',
464+
targetFile: undefined,
465+
},
466+
{
467+
workspace: 'pipenv-app',
468+
targetFile: undefined,
469+
},
470+
])(
471+
'should get a valid dependency graph for workspace = $workspace',
472+
async ({ workspace, targetFile }) => {
473+
testUtils.chdirWorkspaces(workspace);
474+
testUtils.ensureVirtualenv(workspace);
475+
tearDown = testUtils.activateVirtualenv(workspace);
476+
testUtils.pipenvInstall();
477+
testUtils.chdirWorkspaces(workspace);
478+
const result = await inspect(
479+
'.',
480+
targetFile ? targetFile : FILENAMES.pipenv.manifest
481+
);
482+
483+
const expected = [
484+
{
485+
pkg: {
486+
name: 'markupsafe',
487+
version: '2.1.5',
488+
},
489+
directDeps: ['jinja2'],
490+
},
491+
];
492+
compareTransitiveLines(result.dependencyGraph, expected);
493+
}
494+
);
495+
});
496+
454497
describe('when generating Pipfile depGraphs ', () => {
455498
let tearDown;
456499
beforeAll(() => {

test/test-utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
deactivateVirtualenv,
1111
ensureVirtualenv,
1212
pipInstall,
13+
pipenvInstall,
1314
pipUninstall,
1415
setupPyInstall,
1516
};
@@ -141,6 +142,19 @@ function pipInstall() {
141142
}
142143
}
143144

145+
function pipenvInstall() {
146+
const proc = subProcess.executeSync('pipenv', ['install']);
147+
148+
if (proc.status !== 0) {
149+
console.log('' + proc.stderr);
150+
throw new Error(
151+
'Failed to install requirements with pipenv.' +
152+
' venv = ' +
153+
JSON.stringify(getActiveVenvName())
154+
);
155+
}
156+
}
157+
144158
function setupPyInstall() {
145159
const proc = subProcess.executeSync('python3', ['setup.py', 'install']);
146160
if (proc.status !== 0) {

0 commit comments

Comments
 (0)