Skip to content

Commit

Permalink
feat: support --command for Poetry fix
Browse files Browse the repository at this point in the history
Snyk users can provide a Python interpreter to be used for all
Python opetations via --command parameter to `snyk test` and `snyk fix`

Latest @snyk/fix-poetry package version nos supports it and expects it to be passed through as `python` parameter.
  • Loading branch information
lili2311 committed Jun 16, 2021
1 parent 462e0ad commit 0210956
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/snyk-fix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@snyk/dep-graph": "^1.21.0",
"@snyk/fix-pipenv-pipfile": "0.5.3",
"@snyk/fix-poetry": "0.6.0",
"@snyk/fix-poetry": "0.7.0",
"chalk": "4.1.1",
"debug": "^4.3.1",
"lodash.groupby": "4.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export async function updateDependencies(

// update prod dependencies first
if (!options.dryRun && upgrades.length) {
const res = await poetryFix.poetryAdd(dir, upgrades, {});
const res = await poetryFix.poetryAdd(dir, upgrades, {
python: entity.options.command ?? undefined,
});
if (res.exitCode !== 0) {
poetryCommand = res.command;
throwPoetryError(res.stderr ? res.stderr : res.stdout, res.command);
Expand All @@ -63,6 +65,7 @@ export async function updateDependencies(
if (!options.dryRun && devUpgrades.length) {
const res = await poetryFix.poetryAdd(dir, devUpgrades, {
dev: true,
python: entity.options.command ?? undefined,
});
if (res.exitCode !== 0) {
poetryCommand = res.command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ describe('fix Poetry Python projects', () => {
expect(poetryFixStub.mock.calls[0]).toEqual([
pathLib.resolve(workspacesPath, 'simple'),
['six==2.0.1', 'transitive==1.1.1'],
{},
{
python: 'python3',
},
]);
});

Expand Down Expand Up @@ -276,7 +278,7 @@ describe('fix Poetry Python projects', () => {
},
]);
});
it('pins a transitive dep', async () => {
it('pins a transitive dep with custom python interpreter via --command', async () => {
jest.spyOn(poetryFix, 'poetryAdd').mockResolvedValue({
exitCode: 0,
stdout: '',
Expand Down Expand Up @@ -308,7 +310,9 @@ describe('fix Poetry Python projects', () => {
workspacesPath,
targetFile,
testResult,
{},
{
command: 'python2',
},
);

// Act
Expand Down Expand Up @@ -341,10 +345,11 @@ describe('fix Poetry Python projects', () => {
expect(poetryFixStub.mock.calls[0]).toEqual([
pathLib.resolve(workspacesPath, 'simple'),
['markupsafe==2.1.0'],
{},
{
python: 'python2',
},
]);
});
it.todo('--command support');
it('shows expected changes when updating a dev dep', async () => {
jest.spyOn(poetryFix, 'poetryAdd').mockResolvedValue({
exitCode: 0,
Expand Down

0 comments on commit 0210956

Please sign in to comment.