-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic fetcher: Init package manager
Introduces new package manager that will be able to pre-fetch generic dependencies from the internet. This change contains only the general structure without any functionality yet. Signed-off-by: Jan Koscielniak <[email protected]>
- Loading branch information
1 parent
b289c91
commit 9508fbb
Showing
6 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from cachi2.core.errors import PackageRejected | ||
from cachi2.core.models.input import Request | ||
from cachi2.core.models.output import RequestOutput | ||
from cachi2.core.models.sbom import Component | ||
from cachi2.core.rooted_path import RootedPath | ||
|
||
DEFAULT_LOCKFILE_NAME = "cachi2_generic.yaml" | ||
DEFAULT_DEPS_DIR = "deps/generic" | ||
|
||
|
||
def fetch_generic_source(request: Request) -> RequestOutput: | ||
""" | ||
Resolve and fetch generic dependencies for a given request. | ||
:param request: the request to process | ||
""" | ||
components = [] | ||
for package in request.generic_packages: | ||
path = request.source_dir.join_within_root(package.path) | ||
components.extend(_resolve_generic_lockfile(path, request.output_dir)) | ||
return RequestOutput.from_obj_list(components=components) | ||
|
||
|
||
def _resolve_generic_lockfile(source_dir: RootedPath, output_dir: RootedPath) -> list[Component]: | ||
if not source_dir.join_within_root(DEFAULT_LOCKFILE_NAME).path.exists(): | ||
raise PackageRejected( | ||
f"Cachi2 generic lockfile '{DEFAULT_LOCKFILE_NAME}' missing, refusing to continue.", | ||
solution=( | ||
f"Make sure your repository has cachi2 generic lockfile '{DEFAULT_LOCKFILE_NAME}' checked in " | ||
"to the repository." | ||
), | ||
) | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from cachi2.core.errors import PackageRejected | ||
from cachi2.core.models.input import GenericPackageInput | ||
from cachi2.core.models.sbom import Component | ||
from cachi2.core.package_managers.generic import ( | ||
DEFAULT_LOCKFILE_NAME, | ||
_resolve_generic_lockfile, | ||
fetch_generic_source, | ||
) | ||
from cachi2.core.rooted_path import RootedPath | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["model_input", "components"], | ||
[ | ||
pytest.param(GenericPackageInput.model_construct(type="generic"), [], id="single_input"), | ||
], | ||
) | ||
@mock.patch("cachi2.core.package_managers.rpm.main.RequestOutput.from_obj_list") | ||
@mock.patch("cachi2.core.package_managers.generic._resolve_generic_lockfile") | ||
def test_fetch_generic_source( | ||
mock_resolve_generic_lockfile: mock.Mock, | ||
mock_from_obj_list: mock.Mock, | ||
model_input: GenericPackageInput, | ||
components: list[Component], | ||
) -> None: | ||
|
||
mock_resolve_generic_lockfile.return_value = components | ||
|
||
mock_request = mock.Mock() | ||
mock_request.generic_packages = [model_input] | ||
|
||
fetch_generic_source(mock_request) | ||
|
||
mock_resolve_generic_lockfile.assert_called() | ||
mock_from_obj_list.assert_called_with(components=components) | ||
|
||
|
||
def test_resolve_generic_no_lockfile(rooted_tmp_path: RootedPath) -> None: | ||
with pytest.raises(PackageRejected) as exc_info: | ||
_resolve_generic_lockfile(rooted_tmp_path, rooted_tmp_path) | ||
assert ( | ||
f"Cachi2 generic lockfile '{DEFAULT_LOCKFILE_NAME}' missing, refusing to continue" | ||
in str(exc_info.value) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters