From 598c3384a3861a5e7e4901f256749007982d9c7d Mon Sep 17 00:00:00 2001 From: oshanYelena Date: Fri, 11 Sep 2026 00:12:44 +0530 Subject: [PATCH 1/2] fix(packages): add PackageRecipe serialization --- ebuild/packages/recipe.py | 17 +++++++++++++++++ tests/unit/test_recipe.py | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/unit/test_recipe.py diff --git a/ebuild/packages/recipe.py b/ebuild/packages/recipe.py index 6cbdb38..c75aaeb 100644 --- a/ebuild/packages/recipe.py +++ b/ebuild/packages/recipe.py @@ -89,6 +89,23 @@ def validate(self) -> None: f"Must be one of {self.VALID_BUILD_SYSTEMS}." ) + def to_dict(self) -> Dict[str, Any]: + """Serialize the recipe using the canonical YAML recipe schema.""" + return { + "package": self.name, + "version": self.version, + "description": self.description, + "license": self.license, + "url": self.url, + "checksum": self.checksum, + "build": self.build_system, + "dependencies": list(self.dependencies), + "patches": list(self.patches), + "configure_args": list(self.configure_args), + "build_args": list(self.build_args), + "install_args": list(self.install_args), + } + def _parse_string_list( raw: Dict[str, Any], diff --git a/tests/unit/test_recipe.py b/tests/unit/test_recipe.py new file mode 100644 index 0000000..e7b1f3b --- /dev/null +++ b/tests/unit/test_recipe.py @@ -0,0 +1,21 @@ +from ebuild.packages.recipe import PackageRecipe + + +def test_package_recipe_to_dict_uses_canonical_schema(): + recipe = PackageRecipe( + name="demo", + version="1.0.0", + url="https://example.com/demo.tar.gz", + build_system="cmake", + dependencies=["dep"], + ) + + data = recipe.to_dict() + + assert data["package"] == "demo" + assert data["version"] == "1.0.0" + assert data["url"] == "https://example.com/demo.tar.gz" + assert data["build"] == "cmake" + assert data["dependencies"] == ["dep"] + assert "name" not in data + assert "build_system" not in data \ No newline at end of file From 8bbca7392d905b5e0cffb2fdc16ce226cc0bdf4e Mon Sep 17 00:00:00 2001 From: oshanYelena Date: Mon, 14 Sep 2026 11:51:26 +0530 Subject: [PATCH 2/2] test(packages): add recipe serialization round-trip coverage --- tests/unit/test_recipe.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_recipe.py b/tests/unit/test_recipe.py index e7b1f3b..404aa2e 100644 --- a/tests/unit/test_recipe.py +++ b/tests/unit/test_recipe.py @@ -1,4 +1,6 @@ -from ebuild.packages.recipe import PackageRecipe +# SPDX-License-Identifier: MIT + +from ebuild.packages.recipe import PackageRecipe, parse_recipe def test_package_recipe_to_dict_uses_canonical_schema(): @@ -18,4 +20,20 @@ def test_package_recipe_to_dict_uses_canonical_schema(): assert data["build"] == "cmake" assert data["dependencies"] == ["dep"] assert "name" not in data - assert "build_system" not in data \ No newline at end of file + assert "build_system" not in data + + +def test_package_recipe_to_dict_round_trips(): + recipe = PackageRecipe( + name="demo", + version="1.0.0", + url="https://example.com/demo.tar.gz", + build_system="cmake", + dependencies=["dep"], + install_args=["--prefix=/opt"], + patches=["fix.patch"], + ) + + restored = parse_recipe(recipe.to_dict()) + + assert restored == recipe