Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions src/providers/python_poetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ export default class Python_poetry extends Base_pyproject {
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
* @param {string|null} lockDir
* @param {object} parsed - parsed pyproject.toml
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}}
*/
_extractMarkerData(lockDir, parsed) {
let directMarkers = new Map()
let transitiveMarkers = new Map()
let hashMap = new Map()

// Extract markers from PEP 621 dependency strings: "name[extras]>=ver ; marker"
let deps = parsed.project?.dependencies || []
Expand Down Expand Up @@ -154,20 +155,42 @@ export default class Python_poetry extends Base_pyproject {
transitiveMarkers.get(pkgKey).set(this._canonicalize(depName), markers)
}
}

let sha256Hex = this._extractSha256FromFiles(pkg.files)
if (sha256Hex) {
hashMap.set(pkgKey, [{alg: "SHA-256", content: sha256Hex}])
}
}
}
}

return { directMarkers, transitiveMarkers }
return { directMarkers, transitiveMarkers, hashMap }
}

/**
* Extract a SHA-256 hex digest from poetry.lock files array.
* Prefers the sdist (.tar.gz) hash; falls back to the first wheel hash.
* @param {Array<{file: string, hash: string}>} [files]
* @returns {string|null}
*/
_extractSha256FromFiles(files) {
if (!Array.isArray(files) || files.length === 0) { return null }
let sdist = files.find(f => f.file.endsWith('.tar.gz'))
let entry = sdist || files[0]
let hash = entry.hash
if (hash && hash.startsWith('sha256:')) {
return hash.slice(7)
}
return null
}

/**
* Parse poetry show --tree output into a dependency graph structure.
*
* @param {string} treeOutput
* @param {Map<string, string>} versionMap - canonical name -> resolved version
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}} markerData
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}>}}
*/
_parsePoetryTree(treeOutput, versionMap, markerData) {
let lines = treeOutput.split(/\r?\n/)
Expand Down Expand Up @@ -196,7 +219,10 @@ export default class Python_poetry extends Base_pyproject {

directDeps.push(key)
if (!graph.has(key)) {
graph.set(key, { name, version, children: [] })
let entry = { name, version, children: [] }
let hashes = markerData.hashMap.get(key)
if (hashes) { entry.hashes = hashes }
graph.set(key, entry)
}
currentDirectDep = key
stack = [{ key, depth: -1 }]
Expand Down Expand Up @@ -243,7 +269,10 @@ export default class Python_poetry extends Base_pyproject {
}

if (!graph.has(depKey)) {
graph.set(depKey, { name: depName, version, children: [] })
let entry = { name: depName, version, children: [] }
let hashes = markerData.hashMap.get(depKey)
if (hashes) { entry.hashes = hashes }
graph.set(depKey, entry)
}

if (parentKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"metadata": {
"timestamp": "2023-10-01T00:00:00.000Z",
"component": {
"name": "dev-deps-project",
"version": "1.0.0",
"purl": "pkg:pypi/dev-deps-project@1.0.0",
"type": "application",
"bom-ref": "pkg:pypi/dev-deps-project@1.0.0"
}
},
"components": [
{
"name": "requests",
"version": "2.33.1",
"purl": "pkg:pypi/requests@2.33.1",
"type": "library",
"bom-ref": "pkg:pypi/requests@2.33.1"
}
],
"dependencies": [
{
"ref": "pkg:pypi/dev-deps-project@1.0.0",
"dependsOn": [
"pkg:pypi/requests@2.33.1"
]
},
{
"ref": "pkg:pypi/requests@2.33.1",
"dependsOn": []
}
]
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"metadata": {
"timestamp": "2023-10-01T00:00:00.000Z",
"component": {
"name": "dev-deps-project",
"version": "1.0.0",
"purl": "pkg:pypi/dev-deps-project@1.0.0",
"type": "application",
"bom-ref": "pkg:pypi/dev-deps-project@1.0.0"
}
},
"components": [
{
"name": "requests",
"version": "2.33.1",
"purl": "pkg:pypi/requests@2.33.1",
"type": "library",
"bom-ref": "pkg:pypi/requests@2.33.1",
"hashes": [
{
"alg": "SHA-256",
"content": "18817f8c57c6263968bc123d237e3b8b08ac046f5456bd1e307ee8f4250d3517"
}
]
}
],
"dependencies": [
{
"ref": "pkg:pypi/dev-deps-project@1.0.0",
"dependsOn": [
"pkg:pypi/requests@2.33.1"
]
},
{
"ref": "pkg:pypi/requests@2.33.1",
"dependsOn": []
}
]
}
Original file line number Diff line number Diff line change
@@ -1,85 +1,115 @@
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"metadata": {
"timestamp": "2023-10-01T00:00:00.000Z",
"component": {
"name": "dev-deps-project",
"version": "1.0.0",
"purl": "pkg:pypi/dev-deps-project@1.0.0",
"type": "application",
"bom-ref": "pkg:pypi/dev-deps-project@1.0.0"
}
},
"components": [
{
"name": "requests",
"version": "2.33.1",
"purl": "pkg:pypi/requests@2.33.1",
"type": "library",
"bom-ref": "pkg:pypi/requests@2.33.1"
},
{
"name": "certifi",
"version": "2026.2.25",
"purl": "pkg:pypi/certifi@2026.2.25",
"type": "library",
"bom-ref": "pkg:pypi/certifi@2026.2.25"
},
{
"name": "charset-normalizer",
"version": "3.4.7",
"purl": "pkg:pypi/charset-normalizer@3.4.7",
"type": "library",
"bom-ref": "pkg:pypi/charset-normalizer@3.4.7"
},
{
"name": "idna",
"version": "3.11",
"purl": "pkg:pypi/idna@3.11",
"type": "library",
"bom-ref": "pkg:pypi/idna@3.11"
},
{
"name": "urllib3",
"version": "2.6.3",
"purl": "pkg:pypi/urllib3@2.6.3",
"type": "library",
"bom-ref": "pkg:pypi/urllib3@2.6.3"
}
],
"dependencies": [
{
"ref": "pkg:pypi/dev-deps-project@1.0.0",
"dependsOn": [
"pkg:pypi/requests@2.33.1"
]
},
{
"ref": "pkg:pypi/requests@2.33.1",
"dependsOn": [
"pkg:pypi/certifi@2026.2.25",
"pkg:pypi/charset-normalizer@3.4.7",
"pkg:pypi/idna@3.11",
"pkg:pypi/urllib3@2.6.3"
]
},
{
"ref": "pkg:pypi/certifi@2026.2.25",
"dependsOn": []
},
{
"ref": "pkg:pypi/charset-normalizer@3.4.7",
"dependsOn": []
},
{
"ref": "pkg:pypi/idna@3.11",
"dependsOn": []
},
{
"ref": "pkg:pypi/urllib3@2.6.3",
"dependsOn": []
}
]
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"metadata": {
"timestamp": "2023-10-01T00:00:00.000Z",
"component": {
"name": "dev-deps-project",
"version": "1.0.0",
"purl": "pkg:pypi/dev-deps-project@1.0.0",
"type": "application",
"bom-ref": "pkg:pypi/dev-deps-project@1.0.0"
}
},
"components": [
{
"name": "requests",
"version": "2.33.1",
"purl": "pkg:pypi/requests@2.33.1",
"type": "library",
"bom-ref": "pkg:pypi/requests@2.33.1",
"hashes": [
{
"alg": "SHA-256",
"content": "18817f8c57c6263968bc123d237e3b8b08ac046f5456bd1e307ee8f4250d3517"
}
]
},
{
"name": "certifi",
"version": "2026.2.25",
"purl": "pkg:pypi/certifi@2026.2.25",
"type": "library",
"bom-ref": "pkg:pypi/certifi@2026.2.25",
"hashes": [
{
"alg": "SHA-256",
"content": "e887ab5cee78ea814d3472169153c2d12cd43b14bd03329a39a9c6e2e80bfba7"
}
]
},
{
"name": "charset-normalizer",
"version": "3.4.7",
"purl": "pkg:pypi/charset-normalizer@3.4.7",
"type": "library",
"bom-ref": "pkg:pypi/charset-normalizer@3.4.7",
"hashes": [
{
"alg": "SHA-256",
"content": "ae89db9e5f98a11a4bf50407d4363e7b09b31e55bc117b4f7d80aab97ba009e5"
}
]
},
{
"name": "idna",
"version": "3.11",
"purl": "pkg:pypi/idna@3.11",
"type": "library",
"bom-ref": "pkg:pypi/idna@3.11",
"hashes": [
{
"alg": "SHA-256",
"content": "795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902"
}
]
},
{
"name": "urllib3",
"version": "2.6.3",
"purl": "pkg:pypi/urllib3@2.6.3",
"type": "library",
"bom-ref": "pkg:pypi/urllib3@2.6.3",
"hashes": [
{
"alg": "SHA-256",
"content": "1b62b6884944a57dbe321509ab94fd4d3b307075e0c2eae991ac71ee15ad38ed"
}
]
}
],
"dependencies": [
{
"ref": "pkg:pypi/dev-deps-project@1.0.0",
"dependsOn": [
"pkg:pypi/requests@2.33.1"
]
},
{
"ref": "pkg:pypi/requests@2.33.1",
"dependsOn": [
"pkg:pypi/certifi@2026.2.25",
"pkg:pypi/charset-normalizer@3.4.7",
"pkg:pypi/idna@3.11",
"pkg:pypi/urllib3@2.6.3"
]
},
{
"ref": "pkg:pypi/certifi@2026.2.25",
"dependsOn": []
},
{
"ref": "pkg:pypi/charset-normalizer@3.4.7",
"dependsOn": []
},
{
"ref": "pkg:pypi/idna@3.11",
"dependsOn": []
},
{
"ref": "pkg:pypi/urllib3@2.6.3",
"dependsOn": []
}
]
}
Loading
Loading