From cfb59efd301fbb82ae8187eebc8575fac492fd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0oltis?= Date: Thu, 25 Jul 2024 11:04:06 +0200 Subject: [PATCH] pkg managers: add bundler to dev pkg managers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the first commit that starts implementation of bundler package manager introduced in: https://github.com/containerbuildsystem/cachi2/pull/565 By adding a package manager to dev section, we expose it from the user for a period of time until the package manager is fully supported. Signed-off-by: Michal Ĺ oltis --- README.md | 2 +- cachi2/core/models/input.py | 22 +++++++++++++++++-- .../core/package_managers/bundler/__init__.py | 3 +++ cachi2/core/package_managers/bundler/main.py | 16 ++++++++++++++ cachi2/core/resolver.py | 3 ++- tests/unit/models/test_input.py | 2 +- tests/unit/test_cli.py | 6 ++--- 7 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 cachi2/core/package_managers/bundler/__init__.py create mode 100644 cachi2/core/package_managers/bundler/main.py diff --git a/README.md b/README.md index 274962f0d..a405547eb 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ Planned: * dnf * cargo -* rubygems +* bundler *Based on the [supported package managers](https://github.com/containerbuildsystem/cachito#package-managers) in the original Cachito.* diff --git a/cachi2/core/models/input.py b/cachi2/core/models/input.py index 709671c83..9a2294b89 100644 --- a/cachi2/core/models/input.py +++ b/cachi2/core/models/input.py @@ -59,7 +59,7 @@ def show_error(error: "ErrorDict") -> str: # Supported package managers -PackageManagerType = Literal["gomod", "npm", "pip", "rpm", "yarn"] +PackageManagerType = Literal["bundler", "gomod", "npm", "pip", "rpm", "yarn"] Flag = Literal[ "cgo-disable", "dev-package-managers", "force-gomod-tidy", "gomod-vendor", "gomod-vendor-check" @@ -131,6 +131,12 @@ def _raise_unexpected_type(repr_: str, *prefixes: str) -> None: return data +class BundlerPackageInput(_PackageInputBase): + """Accepted input for a bundler package.""" + + type: Literal["bundler"] + + class GomodPackageInput(_PackageInputBase): """Accepted input for a gomod package.""" @@ -180,7 +186,14 @@ class YarnPackageInput(_PackageInputBase): PackageInput = Annotated[ - Union[GomodPackageInput, NpmPackageInput, PipPackageInput, RpmPackageInput, YarnPackageInput], + Union[ + BundlerPackageInput, + GomodPackageInput, + NpmPackageInput, + PipPackageInput, + RpmPackageInput, + YarnPackageInput, + ], # https://pydantic-docs.helpmanual.io/usage/types/#discriminated-unions-aka-tagged-unions pydantic.Field(discriminator="type"), ] @@ -226,6 +239,11 @@ def _packages_not_empty(cls, packages: list[PackageInput]) -> list[PackageInput] raise ValueError("at least one package must be defined, got an empty list") return packages + @property + def bundler_packages(self) -> list[BundlerPackageInput]: + """Get the rubygems packages specified for this request.""" + return self._packages_by_type(BundlerPackageInput) + @property def gomod_packages(self) -> list[GomodPackageInput]: """Get the gomod packages specified for this request.""" diff --git a/cachi2/core/package_managers/bundler/__init__.py b/cachi2/core/package_managers/bundler/__init__.py new file mode 100644 index 000000000..4eaba7d9a --- /dev/null +++ b/cachi2/core/package_managers/bundler/__init__.py @@ -0,0 +1,3 @@ +from cachi2.core.package_managers.bundler.main import fetch_bundler_source + +__all__ = ["fetch_bundler_source"] diff --git a/cachi2/core/package_managers/bundler/main.py b/cachi2/core/package_managers/bundler/main.py new file mode 100644 index 000000000..5c5fda414 --- /dev/null +++ b/cachi2/core/package_managers/bundler/main.py @@ -0,0 +1,16 @@ +from cachi2.core.models.input import Request +from cachi2.core.models.output import EnvironmentVariable, ProjectFile, RequestOutput +from cachi2.core.models.sbom import Component + + +def fetch_bundler_source(request: Request) -> RequestOutput: + """Resolve and process all bundler packages.""" + components: list[Component] = [] + environment_variables: list[EnvironmentVariable] = [] + project_files: list[ProjectFile] = [] + + return RequestOutput.from_obj_list( + components=components, + environment_variables=environment_variables, + project_files=project_files, + ) diff --git a/cachi2/core/resolver.py b/cachi2/core/resolver.py index 2f18d8147..52c7734f3 100644 --- a/cachi2/core/resolver.py +++ b/cachi2/core/resolver.py @@ -6,7 +6,7 @@ from cachi2.core.errors import UnsupportedFeature from cachi2.core.models.input import PackageManagerType, Request from cachi2.core.models.output import RequestOutput -from cachi2.core.package_managers import gomod, npm, pip, rpm, yarn +from cachi2.core.package_managers import bundler, gomod, npm, pip, rpm, yarn from cachi2.core.rooted_path import RootedPath from cachi2.core.utils import copy_directory @@ -22,6 +22,7 @@ # This is where we put package managers currently under development in order to # invoke them via CLI _dev_package_managers: dict[PackageManagerType, Handler] = { + "bundler": bundler.fetch_bundler_source, "rpm": rpm.fetch_rpm_source, } diff --git a/tests/unit/models/test_input.py b/tests/unit/models/test_input.py index 4d9917156..ae942fc9f 100644 --- a/tests/unit/models/test_input.py +++ b/tests/unit/models/test_input.py @@ -105,7 +105,7 @@ def test_valid_packages(self, input_data: dict[str, Any], expect_data: dict[str, ), pytest.param( {"type": "go-package"}, - r"Input tag 'go-package' found using 'type' does not match any of the expected tags: 'gomod', 'npm', 'pip', 'rpm', 'yarn'", + r"Input tag 'go-package' found using 'type' does not match any of the expected tags: 'bundler', 'gomod', 'npm', 'pip', 'rpm', 'yarn'", id="incorrect_type_tag", ), pytest.param( diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 7ee2bc66b..8f3a31d7b 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -358,7 +358,7 @@ def test_specify_packages( [ "Error: InvalidInput: 1 validation error for user input", "packages -> 0", - "Input tag 'idk' found using 'type' does not match any of the expected tags: 'gomod', 'npm', 'pip', 'rpm', 'yarn'", + "Input tag 'idk' found using 'type' does not match any of the expected tags: 'bundler', 'gomod', 'npm', 'pip', 'rpm', 'yarn'", ], ), ( @@ -366,7 +366,7 @@ def test_specify_packages( [ "Error: InvalidInput: 1 validation error for user input", "packages -> 0", - "Input tag 'idk' found using 'type' does not match any of the expected tags: 'gomod', 'npm', 'pip', 'rpm', 'yarn'", + "Input tag 'idk' found using 'type' does not match any of the expected tags: 'bundler', 'gomod', 'npm', 'pip', 'rpm', 'yarn'", ], ), ( @@ -374,7 +374,7 @@ def test_specify_packages( [ "Error: InvalidInput: 1 validation error for user input", "packages -> 0", - "Input tag 'idk' found using 'type' does not match any of the expected tags: 'gomod', 'npm', 'pip', 'rpm', 'yarn'", + "Input tag 'idk' found using 'type' does not match any of the expected tags: 'bundler', 'gomod', 'npm', 'pip', 'rpm', 'yarn'", ], ), # Missing package type