Skip to content

Commit 23da360

Browse files
authored
feat(OSM-2442): upgrade parser for poetry v2 support (#260)
* feat(OSM-2442): upgrade parser for poetry v2 support * feat(OSM-2442): add poetry v2 test * feat(OSM-2442): parse optional depenedancies
1 parent 06edfee commit 23da360

File tree

8 files changed

+979
-1
lines changed

8 files changed

+979
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@snyk/cli-interface": "^2.11.2",
2828
"@snyk/dep-graph": "^1.28.1",
2929
"shescape": "1.6.1",
30-
"snyk-poetry-lockfile-parser": "^1.6.1",
30+
"snyk-poetry-lockfile-parser": "^1.8.0",
3131
"tmp": "0.2.3"
3232
},
3333
"devDependencies": {

test/fixtures/poetry-v2-project/poetry.lock

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[project]
2+
name = "out-of-sync"
3+
version = "0.1.0"
4+
description = ""
5+
authors = [
6+
{name = "Your Name",email = "[email protected]"}
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.9"
10+
dependencies = [
11+
"jinja2 (>=3.1.2)",
12+
"isOdd (>=0.1.2)",
13+
]
14+
[build-system]
15+
requires = ["poetry-core>=3.6"]
16+
build-backend = "poetry.core.masonry.api"

test/system/inspect.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,42 @@ describe('inspect', () => {
836836

837837
expect(result.dependencyGraph.equals(expected)).toBeTruthy();
838838
});
839+
it('should return expected dependencies for poetry-v2-app', async () => {
840+
const workspace = 'poetry-v2-app';
841+
testUtils.chdirWorkspaces(workspace);
842+
843+
const result = await inspect('.', FILENAMES.poetry.lockfile);
844+
expect(result).toMatchObject({
845+
plugin: {
846+
name: 'snyk-python-plugin',
847+
runtime: expect.any(String), // any version of Python
848+
targetFile: FILENAMES.poetry.manifest,
849+
},
850+
package: null, // no dep-tree
851+
dependencyGraph: {}, // match any dep-graph (equality checked below)
852+
});
853+
854+
const builder = new DepGraphBuilder(
855+
{ name: 'poetry' },
856+
{ name: 'poetry-fixtures-project', version: '0.1.0' }
857+
);
858+
const expected = builder
859+
.addPkgNode({ name: 'jinja2', version: '3.1.5' }, 'jinja2', {
860+
labels: { scope: 'prod' },
861+
})
862+
.connectDep(builder.rootNodeId, 'jinja2')
863+
.addPkgNode({ name: 'markupsafe', version: '3.0.2' }, 'markupsafe', {
864+
labels: { scope: 'prod', pkgIdProvenance: '[email protected]' },
865+
})
866+
.connectDep('jinja2', 'markupsafe')
867+
.addPkgNode({ name: 'isodd', version: '0.1.2' }, 'isodd', {
868+
labels: { scope: 'prod', pkgIdProvenance: '[email protected]' },
869+
})
870+
.connectDep(builder.rootNodeId, 'isodd')
871+
.build();
872+
873+
expect(result.dependencyGraph.equals(expected)).toBeTruthy();
874+
});
839875

840876
it('should return expected dependencies for poetry-optional-dependencies', async () => {
841877
const workspace = 'poetry-app-optional-dependencies';
@@ -855,6 +891,25 @@ describe('inspect', () => {
855891

856892
compareTransitiveLines(result.dependencyGraph, expected);
857893
});
894+
895+
it('should return expected dependencies for poetry-v2-app-optional-dependencies', async () => {
896+
const workspace = 'poetry-v2-app-optional-dependencies';
897+
testUtils.chdirWorkspaces(workspace);
898+
899+
const result = await inspect('.', FILENAMES.poetry.lockfile);
900+
901+
const expected = [
902+
{
903+
pkg: {
904+
name: 'opentelemetry-distro',
905+
version: '0.35b0',
906+
},
907+
directDeps: ['opentelemetry-distro'],
908+
},
909+
];
910+
911+
compareTransitiveLines(result.dependencyGraph, expected);
912+
});
858913
});
859914

860915
it('should return correct target file for poetry project when relative path to poetry lock file is passed', async () => {
@@ -867,6 +922,16 @@ describe('inspect', () => {
867922
expect(result.plugin.targetFile).toEqual(expectedTargetFile);
868923
});
869924

925+
it('should return correct target file for poetry v2 project when relative path to poetry lock file is passed', async () => {
926+
const dirname = 'test/fixtures/poetry-v2-project';
927+
const manifestFilePath = `${dirname}/poetry.lock`;
928+
929+
const result = await inspect('.', manifestFilePath);
930+
931+
const expectedTargetFile = `${dirname}/pyproject.toml`;
932+
expect(result.plugin.targetFile).toEqual(expectedTargetFile);
933+
});
934+
870935
describe('Pipfile projects', () => {
871936
const mockedExecuteSync = jest.spyOn(subProcess, 'executeSync');
872937
const mockedExecute = jest.spyOn(subProcess, 'execute');

0 commit comments

Comments
 (0)