Skip to content

Commit

Permalink
Merge pull request #97 from snyk/feat/better-error-setup-py
Browse files Browse the repository at this point in the history
feat: setup.py specific install command
  • Loading branch information
lili2311 authored Dec 20, 2019
2 parents b397444 + c76f0df commit 26702d2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/inspect-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ export async function getDependencies(
} catch (error) {
if (typeof error === 'string') {
if (error.indexOf('Required packages missing') !== -1) {
let errMsg = error + '\nPlease run `pip install -r ' + targetFile + '`';
let errMsg = error;
if (path.basename(targetFile) === 'Pipfile') {
errMsg = error + '\nPlease run `pipenv update`';
errMsg += '\nPlease run `pipenv update`.';
} else if (path.basename(targetFile) === 'setup.py') {
errMsg += '\nPlease run `pip install -e .`.';
} else {
errMsg += '\nPlease run `pip install -r ' + targetFile + '`.';
}
errMsg += ' If the issue persists try again with --allow-missing.';
throw new Error(errMsg);
}
}
Expand Down
20 changes: 18 additions & 2 deletions test/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,20 @@ test('inspect setup.py', (t) => {
});
});

test('inspect setup.py with missing deps', (t) => {
return Promise.resolve()
.then(() => {
chdirWorkspaces('setup_py-app');
t.teardown(testUtils.activateVirtualenv('setup_py-app'));
})
.then(() => {
return plugin.inspect('.', 'setup.py');
})
.catch((error) => {
t.match(normalize(error.message), 'pip install -e .');
});
});

test('transitive dep not installed', (t) => {
return Promise.resolve()
.then(() => {
Expand All @@ -386,7 +400,8 @@ test('transitive dep not installed', (t) => {
.catch((error) => {
t.equal(
normalize(error.message),
'Required packages missing: markupsafe\n\nPlease run `pip install -r requirements.txt`'
'Required packages missing: markupsafe\n\nPlease run `pip install -r requirements.txt`. ' +
'If the issue persists try again with --allow-missing.'
);
t.end();
});
Expand Down Expand Up @@ -502,7 +517,8 @@ test('deps not installed', (t) => {
.catch((error) => {
t.equal(
normalize(error.message),
'Required packages missing: awss\n\nPlease run `pip install -r requirements.txt`'
'Required packages missing: awss\n\nPlease run `pip install -r requirements.txt`. ' +
'If the issue persists try again with --allow-missing.'
);
t.end();
});
Expand Down
17 changes: 17 additions & 0 deletions test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
ensureVirtualenv,
pipInstall,
pipUninstall,
pipInstallE,
pipenvInstall,
setWorkonHome,
};
Expand Down Expand Up @@ -140,6 +141,22 @@ function pipInstall() {
}
}

function pipInstallE() {
const proc = subProcess.executeSync('pip', [
'install',
'-e',
'.',
'--disable-pip-version-check',
]);
if (proc.status !== 0) {
throw new Error(
'Failed to install requirements with pip.' +
' venv = ' +
JSON.stringify(getActiveVenvName())
);
}
}

function pipUninstall(pkgName: string) {
const proc = subProcess.executeSync('pip', ['uninstall', '-y', pkgName]);
if (proc.status !== 0) {
Expand Down

0 comments on commit 26702d2

Please sign in to comment.