Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report pip build dependencies in the SBOM #801

Merged
merged 2 commits into from
Feb 5, 2025
Merged
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
9 changes: 9 additions & 0 deletions cachi2/core/models/property_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"cachi2:rpm_summary",
"cachi2:missing_hash:in_file",
"cachi2:pip:package:binary",
"cachi2:pip:package:build-dependency",
"cdx:npm:package:bundled",
"cdx:npm:package:development",
]
Expand All @@ -34,6 +35,7 @@ class PropertySet:
npm_bundled: bool = False
npm_development: bool = False
pip_package_binary: bool = False
pip_build_dependency: bool = False
bundler_package_binary: bool = False
rpm_summary: str = ""

Expand All @@ -45,6 +47,7 @@ def from_properties(cls, props: Iterable[Property]) -> "Self":
npm_bundled = False
npm_development = False
pip_package_binary = False
pip_build_dependency = False
bundler_package_binary = False
rpm_summary = ""

Expand All @@ -59,6 +62,8 @@ def from_properties(cls, props: Iterable[Property]) -> "Self":
npm_development = True
elif prop.name == "cachi2:pip:package:binary":
pip_package_binary = True
elif prop.name == "cachi2:pip:package:build-dependency":
pip_build_dependency = True
elif prop.name == "cachi2:bundler:package:binary":
bundler_package_binary = True
elif prop.name == "cachi2:rpm_summary":
Expand All @@ -72,6 +77,7 @@ def from_properties(cls, props: Iterable[Property]) -> "Self":
npm_bundled,
npm_development,
pip_package_binary,
pip_build_dependency,
bundler_package_binary,
rpm_summary,
)
Expand All @@ -91,6 +97,8 @@ def to_properties(self) -> list[Property]:
props.append(Property(name="cdx:npm:package:development", value="true"))
if self.pip_package_binary:
props.append(Property(name="cachi2:pip:package:binary", value="true"))
if self.pip_build_dependency:
props.append(Property(name="cachi2:pip:package:build-dependency", value="true"))
if self.bundler_package_binary:
props.append(Property(name="cachi2:bundler:package:binary", value="true"))
if self.rpm_summary:
Expand All @@ -107,6 +115,7 @@ def merge(self, other: "Self") -> "Self":
npm_bundled=self.npm_bundled and other.npm_bundled,
npm_development=self.npm_development and other.npm_development,
pip_package_binary=self.pip_package_binary or other.pip_package_binary,
pip_build_dependency=self.pip_build_dependency and other.pip_build_dependency,
bundler_package_binary=self.bundler_package_binary or other.bundler_package_binary,
rpm_summary=self.rpm_summary or other.rpm_summary,
)
11 changes: 8 additions & 3 deletions cachi2/core/package_managers/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def fetch_pip_source(request: Request) -> RequestOutput:
if dependency["package_type"] == "wheel":
pip_package_binary = True

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message nitpick:

s/declared as requirements_build_files/declared via the 'requirements_build_files' input JSON option

pip_build_dependency = False
if dependency["build_dependency"] is True:
pip_build_dependency = True

components.append(
Component(
name=dependency["name"],
Expand All @@ -202,6 +206,7 @@ def fetch_pip_source(request: Request) -> RequestOutput:
properties=PropertySet(
missing_hash_in_file=missing_hash_in_file,
pip_package_binary=pip_package_binary,
pip_build_dependency=pip_build_dependency,
).to_properties(),
)
)
Expand Down Expand Up @@ -2130,9 +2135,9 @@ def resolve_req_files(req_files: Optional[list[Path]], devel: bool) -> list[Root
output_dir, resolved_build_req_files, allow_binary
)

# Mark all build dependencies as Cachi2 dev dependencies
# Mark all build dependencies as such
for dependency in build_requires:
dependency["dev"] = True
dependency["build_dependency"] = True

def _version(dep: dict[str, Any]) -> str:
if dep["kind"] == "pypi":
Expand All @@ -2151,7 +2156,7 @@ def _version(dep: dict[str, Any]) -> str:
"version": _version(dep),
"index_url": dep.get("index_url"),
"type": "pip",
"dev": dep.get("dev", False),
"build_dependency": dep.get("build_dependency", False),
"kind": dep["kind"],
"requirement_file": dep["requirement_file"],
"missing_req_file_checksum": dep["missing_req_file_checksum"],
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_data/pip_e2e_test/bom.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
{
"name": "cachi2:found_by",
"value": "cachi2"
},
{
"name": "cachi2:pip:package:build-dependency",
"value": "true"
}
],
"purl": "pkg:pypi/flit-core@3.8.0",
Expand Down Expand Up @@ -78,6 +82,10 @@
{
"name": "cachi2:found_by",
"value": "cachi2"
},
{
"name": "cachi2:pip:package:build-dependency",
"value": "true"
}
],
"purl": "pkg:pypi/setuptools@67.1.0",
Expand Down Expand Up @@ -114,6 +122,10 @@
{
"name": "cachi2:found_by",
"value": "cachi2"
},
{
"name": "cachi2:pip:package:build-dependency",
"value": "true"
}
],
"purl": "pkg:pypi/wheel@0.38.4",
Expand Down
17 changes: 10 additions & 7 deletions tests/unit/package_managers/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3888,7 +3888,7 @@ def test_resolve_pip(
"name": "bar",
"version": "2.1",
"type": "pip",
"dev": False,
"build_dependency": False,
"kind": "pypi",
"requirement_file": "req.txt" if custom_requirements else "requirements.txt",
"missing_req_file_checksum": False,
Expand All @@ -3899,7 +3899,7 @@ def test_resolve_pip(
"name": "baz",
"version": "0.0.5",
"type": "pip",
"dev": True,
"build_dependency": True,
"kind": "pypi",
"requirement_file": "breq.txt" if custom_requirements else "requirements-build.txt",
"missing_req_file_checksum": False,
Expand Down Expand Up @@ -4097,7 +4097,7 @@ def test_fetch_pip_source(
"name": "bar",
"version": "https://x.org/bar.zip#cachito_hash=sha256:aaaaaaaaaa",
"type": "pip",
"dev": False,
"build_dependency": False,
"kind": "url",
"requirement_file": "requirements.txt",
"missing_req_file_checksum": False,
Expand All @@ -4108,7 +4108,7 @@ def test_fetch_pip_source(
"version": "0.0.5",
"index_url": pypi_simple.PYPI_SIMPLE_ENDPOINT,
"type": "pip",
"dev": True,
"build_dependency": True,
"kind": "pypi",
"requirement_file": "requirements.txt",
"missing_req_file_checksum": False,
Expand All @@ -4125,7 +4125,7 @@ def test_fetch_pip_source(
"version": "3.2",
"index_url": CUSTOM_PYPI_ENDPOINT,
"type": "pip",
"dev": False,
"build_dependency": False,
"kind": "pypi",
"requirement_file": "requirements.txt",
"missing_req_file_checksum": True,
Expand All @@ -4135,7 +4135,7 @@ def test_fetch_pip_source(
"name": "eggs",
"version": "https://x.org/eggs.zip#cachito_hash=sha256:aaaaaaaaaa",
"type": "pip",
"dev": False,
"build_dependency": False,
"kind": "url",
"requirement_file": "requirements.txt",
"missing_req_file_checksum": True,
Expand Down Expand Up @@ -4178,7 +4178,10 @@ def test_fetch_pip_source(
name="baz",
version="0.0.5",
purl="pkg:pypi/baz@0.0.5",
properties=[Property(name="cachi2:pip:package:binary", value="true")],
properties=[
Property(name="cachi2:pip:package:binary", value="true"),
Property(name="cachi2:pip:package:build-dependency", value="true"),
],
),
]

Expand Down
Loading