Skip to content

Commit

Permalink
Merge pull request #143 from snyk/fix/parse-poetry-dependencies-based…
Browse files Browse the repository at this point in the history
…-on-poetry-lock

fix: use poetry-lock file as a target file for poetry project
  • Loading branch information
jan-stehlik authored May 6, 2021
2 parents b9842df + 105accd commit 0f466d0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/dependencies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function getDependencies(
const includeDevDeps = !!(options.dev || false);

// handle poetry projects by parsing manifest & lockfile and return a dep-graph
if (path.basename(targetFile) === FILENAMES.poetry.manifest) {
if (path.basename(targetFile) === FILENAMES.poetry.lockfile) {
return getPoetryDependencies(command, root, targetFile, includeDevDeps);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dependencies/inspect-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function getMetaData(
// specify targetFile only in case of Pipfile or setup.py
targetFile: path
.basename(targetFile)
.match(/^(Pipfile|setup\.py|pyproject\.toml)$/)
.match(/^(Pipfile|setup\.py|poetry\.lock)$/)
? targetFile
: undefined,
};
Expand Down
7 changes: 4 additions & 3 deletions lib/dependencies/poetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export async function getPoetryDependencies(
targetFile: string,
includeDevDeps = false
): Promise<SinglePackageResult> {
const manifestPath = path.join(root, targetFile);
const baseDir = path.dirname(manifestPath);
const lockfilePath = path.join(baseDir, FILENAMES.poetry.lockfile);
const lockfilePath = path.join(root, targetFile);
const baseDir = path.dirname(lockfilePath);
const manifestPath = path.join(baseDir, FILENAMES.poetry.manifest);
const manifestExists = fs.existsSync(manifestPath);

if (!manifestExists) {
throw new Error('Cannot find manifest file ' + manifestPath);
}
Expand Down
5 changes: 3 additions & 2 deletions test/system/inspect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { inspect } from '../../lib';
import { chdirWorkspaces } from '../test-utils';
import { DepGraphBuilder } from '@snyk/dep-graph';
import { FILENAMES } from '../../lib/types';

// TODO: jestify tap tests in ./inspect.test.js here
describe('inspect', () => {
it('should return expected dependencies for poetry-app', async () => {
const workspace = 'poetry-app';
chdirWorkspaces(workspace);

const result = await inspect('.', 'pyproject.toml');
const result = await inspect('.', FILENAMES.poetry.lockfile);
expect(result).toMatchObject({
plugin: {
name: 'snyk-python-plugin',
runtime: expect.any(String), // any version of Python
targetFile: 'pyproject.toml',
targetFile: FILENAMES.poetry.lockfile,
},
package: null, // no dep-tree
dependencyGraph: {}, // match any dep-graph (equality checked below)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/poetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('getPoetryDepencies', () => {
try {
await getPoetryDependencies('python', root, targetFile);
} catch (e) {
const expectedPath = path.join(root, targetFile);
const expectedPath = path.join(root, FILENAMES.poetry.manifest);
const expected = new Error(`Cannot find manifest file ${expectedPath}`);
expect(e).toEqual(expected);
}
Expand All @@ -25,7 +25,7 @@ describe('getPoetryDepencies', () => {
'workspaces',
'poetry-app-without-lockfile'
);
const targetFile = 'pyproject.toml';
const targetFile = FILENAMES.poetry.lockfile;
try {
await getPoetryDependencies('python', root, targetFile);
} catch (e) {
Expand Down

0 comments on commit 0f466d0

Please sign in to comment.