Skip to content

Commit

Permalink
Adds occurrence evidence for poetry projects (#1303)
Browse files Browse the repository at this point in the history
* Adds occurrence evidence for poetry projects

Signed-off-by: Prabhu Subramanian <[email protected]>

* Fix tests

Signed-off-by: Prabhu Subramanian <[email protected]>

---------

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Aug 9, 2024
1 parent 0f03d02 commit f9a42d7
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 49 deletions.
15 changes: 4 additions & 11 deletions contrib/rebuild-sqlite3.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#!/usr/bin/env bash

npm install --ignore-scripts
cd node_modules/sqlite3
CFLAGS="${CFLAGS:-} -include ../src/gcc-preinclude.h"
CXXFLAGS="${CXXFLAGS:-} -include ../src/gcc-preinclude.h"
npx node-pre-gyp configure
npx node-pre-gyp build

if case $VARIANT in "alpine"*) false;; *) true;; esac; then ldd lib/binding/*/node_sqlite3.node; nm lib/binding/*/node_sqlite3.node | grep \"GLIBC_\" | c++filt || true ; fi

npx node-pre-gyp package
cd ../../
pnpm install --ignore-scripts
cd node_modules/.pnpm/[email protected]/node_modules/sqlite3
pnpm install
cd ../../../../../
node -e 'require("sqlite3")'
2 changes: 1 addition & 1 deletion evinser.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ export const parseSliceUsages = async (
if (purlImportsMap && Object.keys(purlImportsMap).length) {
for (const apurl of Object.keys(purlImportsMap)) {
const apurlImports = purlImportsMap[apurl];
if (language === "php") {
if (["php", "python"].includes(language)) {
for (const aimp of apurlImports) {
if (atype.startsWith(aimp)) {
if (!purlLocationMap[apurl]) {
Expand Down
64 changes: 31 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import {
parseSwiftResolved,
parseYarnLock,
readZipEntry,
recomputeScope,
splitOutputByGradleProjects,
} from "./utils.js";
let url = import.meta.url;
Expand Down Expand Up @@ -2835,13 +2836,6 @@ export async function createPythonBom(path, options) {
dependencies.splice(0, 0, pdependencies);
}
options.parentComponent = parentComponent;
return buildBomNSData(options, pkgList, "pypi", {
src: path,
filename: poetryFiles.join(", "),
dependencies,
parentComponent,
formulationList,
});
} // poetryMode
if (metadataFiles?.length) {
// dist-info directories
Expand Down Expand Up @@ -2956,13 +2950,13 @@ export async function createPythonBom(path, options) {
}
}
// Use atom in requirements, setup.py and pyproject.toml mode
if (requirementsMode || setupPyMode || pyProjectMode) {
if (requirementsMode || setupPyMode || pyProjectMode || options.deep) {
/**
* The order of preference is pyproject.toml (newer) and then setup.py
*/
if (options.installDeps) {
let pkgMap = undefined;
if (pyProjectMode) {
if (pyProjectMode && !poetryMode) {
pkgMap = getPipFrozenTree(
path,
pyProjectFile,
Expand All @@ -2971,7 +2965,7 @@ export async function createPythonBom(path, options) {
);
} else if (setupPyMode) {
pkgMap = getPipFrozenTree(path, setupPy, tempDir, parentComponent);
} else {
} else if (!poetryMode) {
pkgMap = getPipFrozenTree(path, undefined, tempDir, parentComponent);
}

Expand All @@ -2993,6 +2987,7 @@ export async function createPythonBom(path, options) {
});
for (const apkg of pkgList) {
if (iSymbolsMap[apkg.name]) {
apkg.scope = "required";
apkg.properties = apkg.properties || [];
apkg.properties.push({
name: "ImportedModules",
Expand Down Expand Up @@ -3030,30 +3025,31 @@ export async function createPythonBom(path, options) {
}
}
// ATOM parsedeps block

// Complete the dependency tree by making parent component depend on the first level
for (const p of pkgMap.rootList) {
if (
parentComponent &&
p.name === parentComponent.name &&
(p.version === parentComponent.version || p.version === "latest")
) {
continue;
if (pkgMap) {
// Complete the dependency tree by making parent component depend on the first level
for (const p of pkgMap.rootList) {
if (
parentComponent &&
p.name === parentComponent.name &&
(p.version === parentComponent.version || p.version === "latest")
) {
continue;
}
parentDependsOn.add(`pkg:pypi/${p.name.toLowerCase()}@${p.version}`);
}
if (pkgMap?.pkgList?.length) {
pkgList = pkgList.concat(pkgMap.pkgList);
}
if (pkgMap?.formulationList?.length) {
formulationList = formulationList.concat(pkgMap.formulationList);
}
if (pkgMap?.dependenciesList) {
dependencies = mergeDependencies(
dependencies,
pkgMap.dependenciesList,
parentComponent,
);
}
parentDependsOn.add(`pkg:pypi/${p.name.toLowerCase()}@${p.version}`);
}
if (pkgMap.pkgList?.length) {
pkgList = pkgList.concat(pkgMap.pkgList);
}
if (pkgMap.formulationList?.length) {
formulationList = formulationList.concat(pkgMap.formulationList);
}
if (pkgMap.dependenciesList) {
dependencies = mergeDependencies(
dependencies,
pkgMap.dependenciesList,
parentComponent,
);
}
let parentPresent = false;
for (const d of dependencies) {
Expand Down Expand Up @@ -3125,6 +3121,8 @@ export async function createPythonBom(path, options) {
if (tempDir?.startsWith(tmpdir()) && rmSync) {
rmSync(tempDir, { recursive: true, force: true });
}
// Re-compute the component scope
pkgList = recomputeScope(pkgList, dependencies);
if (FETCH_LICENSE) {
pkgList = await getPyMetadata(pkgList, false);
}
Expand Down
1 change: 1 addition & 0 deletions postgen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import process from "node:process";
import { PackageURL } from "packageurl-js";
import { dirNameStr } from "./utils.js";

Expand Down
2 changes: 1 addition & 1 deletion types/evinser.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/postgen.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,15 @@ export function isValidIriReference(iri: string): boolean;
* @returns {Boolean} True if the dependency tree lacks any non-root parents without children. False otherwise.
*/
export function isPartialTree(dependencies: any[]): boolean;
/**
* Re-compute and set the scope based on the dependency tree
*
* @param {Array} pkgList List of components
* @param {Array} dependencies List of dependencies
*
* @returns {Array} Updated list
*/
export function recomputeScope(pkgList: any[], dependencies: any[]): any[];
export const dirNameStr: string;
export const isWin: boolean;
export const isMac: boolean;
Expand Down
Loading

0 comments on commit f9a42d7

Please sign in to comment.