Skip to content

Commit

Permalink
pkg managers: add bundler to dev pkg managers
Browse files Browse the repository at this point in the history
This is the first commit that starts implementation
of bundler package manager introduced in:
containerbuildsystem#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 <[email protected]>
  • Loading branch information
slimreaper35 committed Aug 26, 2024
1 parent 76541f3 commit cfb59ef
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
22 changes: 20 additions & 2 deletions cachi2/core/models/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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"),
]
Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 3 additions & 0 deletions cachi2/core/package_managers/bundler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cachi2.core.package_managers.bundler.main import fetch_bundler_source

__all__ = ["fetch_bundler_source"]
16 changes: 16 additions & 0 deletions cachi2/core/package_managers/bundler/main.py
Original file line number Diff line number Diff line change
@@ -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,
)
3 changes: 2 additions & 1 deletion cachi2/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/models/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,23 @@ 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'",
],
),
(
'[{"type": "idk"}]',
[
"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'",
],
),
(
'{"packages": [{"type": "idk"}]}',
[
"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
Expand Down

0 comments on commit cfb59ef

Please sign in to comment.