← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/lpcraft:lpcraft-conda-build-plugin-is-overly-aggressive into lpcraft:main

 

Simone Pelosi has proposed merging ~pelpsi/lpcraft:lpcraft-conda-build-plugin-is-overly-aggressive into lpcraft:main.

Commit message:
Added new new configurable option recipe-folder
    
Added a new configurable option (default value ./info) called recipe-folder,
to be able to specify the recipe itself, or the recipe search path.
Using this approach the search path for variant config files will be scoped
to the recipe_folder and its parents.
Added test case.
    
LP: #1978715

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1978715 in lpcraft: "lpcraft conda build plugin is overly aggressive in detecting variant config files"
  https://bugs.launchpad.net/lpcraft/+bug/1978715

For more details, see:
https://code.launchpad.net/~pelpsi/lpcraft/+git/lpcraft/+merge/440025
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/lpcraft:lpcraft-conda-build-plugin-is-overly-aggressive into lpcraft:main.
diff --git a/lpcraft/plugin/tests/test_plugins.py b/lpcraft/plugin/tests/test_plugins.py
index 1def73b..ccbc7d8 100644
--- a/lpcraft/plugin/tests/test_plugins.py
+++ b/lpcraft/plugin/tests/test_plugins.py
@@ -679,6 +679,43 @@ class TestPlugins(CommandBaseTestCase):
         ]
         self.assertEqual("info/recipe", plugin_match[0].build_target)
 
+    def test_conda_build_plugin_finds_recipe_custom_folder(self):
+        config = dedent(
+            """
+            pipeline:
+                - build
+
+            jobs:
+                build:
+                    series: focal
+                    architectures: amd64
+                    plugin: conda-build
+                    conda-channels:
+                        - conda-forge
+                    conda-packages:
+                        - mamba
+                        - pip
+                    conda-python: 3.8
+                    recipe-folder: custominfo
+                    run: |
+                        pip install --upgrade pytest
+        """
+        )
+        config_path = Path(".launchpad.yaml")
+        config_path.write_text(config)
+        Path("include/fake_subdir").mkdir(parents=True)
+        meta_yaml = Path("custominfo/recipe/meta.yaml")
+        meta_yaml.parent.mkdir(parents=True)
+        meta_yaml.touch()
+        config_obj = lpcraft.config.Config.load(config_path)
+        self.assertEqual(config_obj.jobs["build"][0].plugin, "conda-build")
+        pm = get_plugin_manager(config_obj.jobs["build"][0])
+        plugins = pm.get_plugins()
+        plugin_match = [
+            _ for _ in plugins if _.__class__.__name__ == "CondaBuildPlugin"
+        ]
+        self.assertEqual("custominfo/recipe", plugin_match[0].build_target)
+
     def test_conda_build_plugin_finds_recipe_with_fake_parent(self):
         config = dedent(
             """
diff --git a/lpcraft/plugins/plugins.py b/lpcraft/plugins/plugins.py
index 4dbad96..c32f6f5 100644
--- a/lpcraft/plugins/plugins.py
+++ b/lpcraft/plugins/plugins.py
@@ -264,12 +264,22 @@ class CondaBuildPlugin(MiniCondaPlugin):
         conda_channels: Optional[List[StrictStr]]
         conda_packages: Optional[List[StrictStr]]
         conda_python: Optional[StrictStr]
+        recipe_folder: Optional[StrictStr]
 
     DEFAULT_CONDA_PACKAGES = ("conda-build",)
+    DEFAULT_RECIPE_FOLDER = "./info"
 
     def get_plugin_config(self) -> "CondaBuildPlugin.Config":
         return cast(CondaBuildPlugin.Config, self.config.plugin_config)
 
+    @property
+    def recipe_folder(self) -> str:
+        recipe_folder = self.DEFAULT_RECIPE_FOLDER
+        plugin_config = self.get_plugin_config()
+        if plugin_config.recipe_folder:
+            recipe_folder = plugin_config.recipe_folder
+        return recipe_folder
+
     @staticmethod
     def _has_recipe(dir_: Path) -> bool:
         return dir_.joinpath("meta.yaml").is_file()
@@ -300,7 +310,7 @@ class CondaBuildPlugin(MiniCondaPlugin):
                         continue
             raise FileNotFoundError
 
-        return _find_recipe_dir(Path("."))
+        return _find_recipe_dir(Path(self.recipe_folder))
 
     def find_build_target(self) -> str:
         def find_parents(pth: Path) -> Path:

Follow ups