Skip to content

Commit 17aff60

Browse files
committed
Add functionality to handle poetryV2
- Changed utils.js - Created tests for the changes Signed-off-by: ambuj <[email protected]>
1 parent d5f8b55 commit 17aff60

File tree

3 files changed

+109
-5
lines changed

3 files changed

+109
-5
lines changed

lib/helpers/utils.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import {
1717
} from "node:fs";
1818
import { homedir, platform, tmpdir } from "node:os";
1919
import path, {
20-
basename,
2120
delimiter as _delimiter,
21+
sep as _sep,
22+
basename,
2223
dirname,
2324
extname,
2425
join,
25-
resolve,
2626
relative,
27-
sep as _sep,
27+
resolve,
2828
} from "node:path";
2929
import process from "node:process";
3030
import { URL, fileURLToPath } from "node:url";
@@ -4904,6 +4904,7 @@ export function parsePyProjectTomlFile(tomlFile) {
49044904
}
49054905
}
49064906

4907+
let isPoetryV2 = false;
49074908
let poetryMode = false;
49084909
let uvMode = false;
49094910
let hatchMode = false;
@@ -4926,6 +4927,16 @@ export function parsePyProjectTomlFile(tomlFile) {
49264927
) {
49274928
poetryMode = true;
49284929
}
4930+
const requires = tomlData?.["build-system"]?.["requires"];
4931+
if (requires && Array.isArray(requires)) {
4932+
for (const req of requires) {
4933+
if (req.startsWith("poetry-core") && req.includes(">=2.0")) {
4934+
isPoetryV2 = true;
4935+
break;
4936+
}
4937+
}
4938+
}
4939+
49294940
if (tomlData?.tool?.uv) {
49304941
uvMode = true;
49314942
}
@@ -5029,6 +5040,7 @@ export function parsePyProjectTomlFile(tomlFile) {
50295040
return {
50305041
parentComponent: pkg,
50315042
poetryMode,
5043+
isPoetryV2,
50325044
uvMode,
50335045
hatchMode,
50345046
workspacePaths,
@@ -13517,6 +13529,15 @@ export function getPipFrozenTree(
1351713529
});
1351813530
thoughtLog("Performing poetry install");
1351913531
let poetryInstallArgs = ["-m", "poetry", "install", "-n", "--no-root"];
13532+
const isPoetryV2 = parsePyProjectTomlFile(
13533+
join(basePath, "pyproject.toml"),
13534+
).isPoetryV2;
13535+
// checking if poetryV2 is true or not
13536+
if (isPoetryV2) {
13537+
// Include all dependency groups and extras (Poetry v2+)
13538+
poetryInstallArgs.push("--all-groups", "--all-extras");
13539+
}
13540+
1352013541
// Attempt to perform poetry install
1352113542
result = safeSpawnSync(PYTHON_CMD, poetryInstallArgs, {
1352213543
cwd: basePath,
@@ -13530,6 +13551,11 @@ export function getPipFrozenTree(
1353013551
"Hmm, poetry doesn't seem to be available as a module. Perhaps it was installed directly 🤔?",
1353113552
);
1353213553
poetryInstallArgs = ["install", "-n", "--no-root"];
13554+
13555+
if (isPoetryV2) {
13556+
// Also include flags when calling poetry directly
13557+
poetryInstallArgs.push("--all-groups", "--all-extras");
13558+
}
1353313559
// Attempt to perform poetry install
1353413560
result = safeSpawnSync("poetry", poetryInstallArgs, {
1353513561
cwd: basePath,

lib/helpers/utils.test.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import {
1111
findLicenseId,
1212
getCratesMetadata,
1313
getDartMetadata,
14-
getGoPkgLicense,
1514
getLicenses,
1615
getMvnMetadata,
1716
getNugetMetadata,
1817
getPyMetadata,
19-
getRepoLicense,
2018
guessPypiMatchingVersion,
2119
hasAnyProjectType,
2220
isPackageManagerAllowed,
@@ -4975,6 +4973,34 @@ test("parse pyproject.toml", () => {
49754973
});
49764974
});
49774975

4976+
test("parse pyproject.toml with poetryv2 requirement", () => {
4977+
const retMap = parsePyProjectTomlFile("./test/data/pyproject_poetryv2.toml");
4978+
// expect(retMap.parentComponent).toEqual({
4979+
// name: "cpggen",
4980+
// version: "1.9.0",
4981+
// description:
4982+
// "Generate CPG for multiple languages for code and threat analysis",
4983+
// license: "Apache-2.0",
4984+
// author: "Team AppThreat <[email protected]>",
4985+
// homepage: { url: "https://github.com/AppThreat/cpggen" },
4986+
// repository: { url: "https://github.com/AppThreat/cpggen" },
4987+
// tags: [
4988+
// "atom",
4989+
// "code analysis",
4990+
// "code property graph",
4991+
// "cpg",
4992+
// "joern",
4993+
// "static analysis",
4994+
// "threat analysis",
4995+
// ],
4996+
// type: "application",
4997+
// "bom-ref": "pkg:pypi/[email protected]",
4998+
// purl: "pkg:pypi/[email protected]",
4999+
// evidence: { identity: { field: "purl", confidence: 1, methods: [Array] } },
5000+
// });
5001+
expect(retMap.isPoetryV2).toBeTruthy();
5002+
});
5003+
49785004
test("parse pyproject.toml with custom poetry source", () => {
49795005
const retMap = parsePyProjectTomlFile(
49805006
"./test/data/pyproject_with_custom_poetry_source.toml",

test/data/pyproject_poetryv2.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[tool.poetry]
2+
name = "cpggen"
3+
version = "1.9.0" # 1.9.0 is not version 2.0.0
4+
description = "Generate CPG for multiple languages for code and threat analysis"
5+
authors = ["Team AppThreat <[email protected]>"]
6+
license = "Apache-2.0"
7+
readme = "README.md"
8+
packages = [{include = "cpggen"}]
9+
homepage = "https://github.com/AppThreat/cpggen"
10+
repository = "https://github.com/AppThreat/cpggen"
11+
keywords = ["joern", "code analysis", "static analysis", "cpg", "code property graph", "atom", "threat analysis"]
12+
classifiers = [
13+
"Development Status :: 5 - Production/Stable",
14+
"Intended Audience :: Developers",
15+
"Intended Audience :: System Administrators",
16+
"Topic :: Utilities",
17+
"Topic :: Security",
18+
"Programming Language :: Python :: 3.8",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Operating System :: OS Independent",
23+
]
24+
exclude = ["contrib", "tests"]
25+
include = ["cpggen/atom/*"]
26+
27+
[tool.poetry.scripts]
28+
atomgen = 'cpggen.cli:main'
29+
cpggen = 'cpggen.cli:main'
30+
cpg = 'cpggen.cli:main'
31+
32+
[tool.poetry.dependencies]
33+
python = ">=3.8.1,<3.12"
34+
rich = "^13.4.2"
35+
gitpython = "^3.1.31"
36+
quart = "^0.18.4"
37+
psutil = "^5.9.5"
38+
packageurl-python = "^0.11.1"
39+
httpx = "^0.24.1"
40+
41+
[tool.poetry.group.dev.dependencies]
42+
pytest = "^7.4.0"
43+
black = "^23.3.0"
44+
flake8 = "^6.0.0"
45+
pytest-cov = "^4.0.0"
46+
pyinstaller = "^5.12.0"
47+
bandit = "^1.7.5"
48+
pylint = "^2.17.4"
49+
50+
[build-system]
51+
requires = ["poetry-core>=2.0.0"]
52+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)