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

Add SPDX format support for SBOM #608

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cachi2/core/package_managers/metayarn.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from cachi2.core.config import get_config
from cachi2.core.models.input import Request
from cachi2.core.models.output import RequestOutput
from cachi2.core.package_managers.utils import merge_outputs
from cachi2.core.package_managers.yarn.main import fetch_yarn_source as fetch_yarnberry_source
from cachi2.core.package_managers.yarn_classic.main import MissingLockfile, NotV1Lockfile
from cachi2.core.package_managers.yarn_classic.main import (
fetch_yarn_source as fetch_yarn_classic_source,
)
from cachi2.core.utils import merge_outputs


def fetch_yarn_source(request: Request) -> RequestOutput:
Expand Down
22 changes: 22 additions & 0 deletions cachi2/core/package_managers/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Iterable

from cachi2.core.models.output import RequestOutput


def merge_outputs(outputs: Iterable[RequestOutput]) -> RequestOutput:
"""Merge RequestOutput instances."""
components = []
env_vars = []
project_files = []

for output in outputs:
components.extend(output.components)
env_vars.extend(output.build_config.environment_variables)
project_files.extend(output.build_config.project_files)

return RequestOutput.from_obj_list(
components=components,
environment_variables=env_vars,
project_files=project_files,
options=output.build_config.options if output.build_config.options else None,
)
3 changes: 2 additions & 1 deletion cachi2/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from cachi2.core.models.input import PackageManagerType, Request
from cachi2.core.models.output import RequestOutput
from cachi2.core.package_managers import bundler, generic, gomod, metayarn, npm, pip, rpm
from cachi2.core.package_managers.utils import merge_outputs
from cachi2.core.rooted_path import RootedPath
from cachi2.core.utils import copy_directory, merge_outputs
from cachi2.core.utils import copy_directory

Handler = Callable[[Request], RequestOutput]

Expand Down
20 changes: 0 additions & 20 deletions cachi2/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from cachi2.core.config import get_config
from cachi2.core.errors import Cachi2Error
from cachi2.core.models.output import RequestOutput

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -196,22 +195,3 @@ def get_cache_dir() -> Path:
except KeyError:
cache_dir = Path.home().joinpath(".cache")
return cache_dir.joinpath("cachi2")


def merge_outputs(outputs: Iterable[RequestOutput]) -> RequestOutput:
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a cleanup of a pre-existing behaviour not strictly related to the PR, so it could be the first commit, couldn't it?

"""Merge RequestOutput instances."""
components = []
env_vars = []
project_files = []

for output in outputs:
components.extend(output.components)
env_vars.extend(output.build_config.environment_variables)
project_files.extend(output.build_config.project_files)

return RequestOutput.from_obj_list(
components=components,
environment_variables=env_vars,
project_files=project_files,
options=output.build_config.options if output.build_config.options else None,
)