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

Proposed by Simone Pelosi
Status: Merged
Approved by: Simone Pelosi
Approved revision: 1131bd2f4ea64c319d49020f9566c218e10d7a5b
Merge reported by: Simone Pelosi
Merged at revision: 1131bd2f4ea64c319d49020f9566c218e10d7a5b
Proposed branch: ~pelpsi/lpci:lpcraft-conda-build-plugin-is-overly-aggressive
Merge into: lpci:main
Diff against target: 163 lines (+102/-1)
3 files modified
NEWS.rst (+4/-0)
lpci/plugin/tests/test_plugins.py (+87/-0)
lpci/plugins/plugins.py (+11/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Dan Ryan (community) Approve
Review via email: mp+440025@code.launchpad.net

Commit message

Added 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

To post a comment you must log in.
Revision history for this message
Dan Ryan (techalchemy) wrote :

this looks like an elegant solution to the problem, thanks for tackling it!

review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

Please rebase on current lpci to deal with the various renamings, and add a `NEWS.rst` entry; but otherwise this looks fine, thanks.

review: Approve
Revision history for this message
Simone Pelosi (pelpsi) wrote :

> Please rebase on current lpci to deal with the various renamings, and add a
> `NEWS.rst` entry; but otherwise this looks fine, thanks.

Thank you Colin, I will also add a new entry in the documentation for this new parameter.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/NEWS.rst b/NEWS.rst
2index 857ac8a..50dd108 100644
3--- a/NEWS.rst
4+++ b/NEWS.rst
5@@ -11,6 +11,10 @@ Version history
6
7 - Add a ``--debug-shell`` flag.
8
9+- Add a ``recipe_folder`` parameter to specify
10+ the recipe itself, or the recipe search path
11+ using conda-build-plugin.
12+
13 0.0.52 (2023-04-06)
14 ===================
15 - Fix regression from adding support to snap keys
16diff --git a/lpci/plugin/tests/test_plugins.py b/lpci/plugin/tests/test_plugins.py
17index cddc68a..b0c5844 100644
18--- a/lpci/plugin/tests/test_plugins.py
19+++ b/lpci/plugin/tests/test_plugins.py
20@@ -484,6 +484,42 @@ class TestPlugins(CommandBaseTestCase):
21 )
22 self.assertEqual(["PYTHON=3.8", "pip"], plugin_match[0].conda_packages)
23
24+ def test_conda_build_plugin_settings(self):
25+ config = dedent(
26+ """
27+ pipeline:
28+ - build
29+
30+ jobs:
31+ build:
32+ build-target: info/recipe/parent
33+ series: focal
34+ architectures: amd64
35+ plugin: conda-build
36+ run: |
37+ pip install --upgrade pytest
38+ """
39+ )
40+ config_path = Path(".launchpad.yaml")
41+ config_path.write_text(config)
42+ config_obj = lpci.config.Config.load(config_path)
43+ self.assertEqual(config_obj.jobs["build"][0].plugin, "conda-build")
44+ pm = get_plugin_manager(config_obj.jobs["build"][0])
45+ plugins = pm.get_plugins()
46+ plugin_match = [
47+ _ for _ in plugins if _.__class__.__name__ == "CondaBuildPlugin"
48+ ]
49+ self.assertEqual(
50+ [
51+ "defaults",
52+ ],
53+ plugin_match[0].conda_channels,
54+ )
55+ self.assertEqual(
56+ ["PYTHON=3.8", "conda-build"], plugin_match[0].conda_packages
57+ )
58+ self.assertEqual("./info", plugin_match[0].recipe_folder)
59+
60 @patch("lpci.commands.run.get_provider")
61 @patch("lpci.commands.run.get_host_architecture", return_value="amd64")
62 def test_conda_build_plugin(
63@@ -561,6 +597,7 @@ class TestPlugins(CommandBaseTestCase):
64 ),
65 execute_run.call_args_list[0],
66 )
67+
68 self.assertEqual(
69 call(
70 [
71@@ -679,6 +716,56 @@ class TestPlugins(CommandBaseTestCase):
72 ]
73 self.assertEqual("info/recipe", plugin_match[0].build_target)
74
75+ def test_conda_build_plugin_finds_recipe_custom_folder(self):
76+ config = dedent(
77+ """
78+ pipeline:
79+ - build
80+
81+ jobs:
82+ build:
83+ series: focal
84+ architectures: amd64
85+ plugin: conda-build
86+ conda-channels:
87+ - conda-forge
88+ conda-packages:
89+ - mamba
90+ - pip
91+ conda-python: 3.8
92+ recipe-folder: custominfo
93+ run: |
94+ pip install --upgrade pytest
95+ """
96+ )
97+ config_path = Path(".launchpad.yaml")
98+ config_path.write_text(config)
99+ Path("include/fake_subdir").mkdir(parents=True)
100+ Path("custominfo").mkdir(parents=True)
101+ Path("custominfo/a.txt").touch()
102+ Path("custominfo/b.txt").touch()
103+
104+ config_obj = lpci.config.Config.load(config_path)
105+
106+ self.assertRaisesRegex(
107+ RuntimeError,
108+ "No build target found",
109+ get_plugin_manager,
110+ config_obj.jobs["build"][0],
111+ )
112+
113+ meta_yaml = Path("custominfo/recipe/meta.yaml")
114+ meta_yaml.parent.mkdir(parents=True)
115+ meta_yaml.touch()
116+
117+ self.assertEqual(config_obj.jobs["build"][0].plugin, "conda-build")
118+ pm = get_plugin_manager(config_obj.jobs["build"][0])
119+ plugins = pm.get_plugins()
120+ plugin_match = [
121+ _ for _ in plugins if _.__class__.__name__ == "CondaBuildPlugin"
122+ ]
123+ self.assertEqual("custominfo/recipe", plugin_match[0].build_target)
124+
125 def test_conda_build_plugin_finds_recipe_with_fake_parent(self):
126 config = dedent(
127 """
128diff --git a/lpci/plugins/plugins.py b/lpci/plugins/plugins.py
129index 07745d5..6fe88a2 100644
130--- a/lpci/plugins/plugins.py
131+++ b/lpci/plugins/plugins.py
132@@ -264,12 +264,22 @@ class CondaBuildPlugin(MiniCondaPlugin):
133 conda_channels: Optional[List[StrictStr]]
134 conda_packages: Optional[List[StrictStr]]
135 conda_python: Optional[StrictStr]
136+ recipe_folder: Optional[StrictStr]
137
138 DEFAULT_CONDA_PACKAGES = ("conda-build",)
139+ DEFAULT_RECIPE_FOLDER = "./info"
140
141 def get_plugin_config(self) -> "CondaBuildPlugin.Config":
142 return cast(CondaBuildPlugin.Config, self.config.plugin_config)
143
144+ @property
145+ def recipe_folder(self) -> str:
146+ recipe_folder = self.DEFAULT_RECIPE_FOLDER
147+ plugin_config = self.get_plugin_config()
148+ if plugin_config.recipe_folder:
149+ recipe_folder = plugin_config.recipe_folder
150+ return recipe_folder
151+
152 @staticmethod
153 def _has_recipe(dir_: Path) -> bool:
154 return dir_.joinpath("meta.yaml").is_file()
155@@ -300,7 +310,7 @@ class CondaBuildPlugin(MiniCondaPlugin):
156 continue
157 raise FileNotFoundError
158
159- return _find_recipe_dir(Path("."))
160+ return _find_recipe_dir(Path(self.recipe_folder))
161
162 def find_build_target(self) -> str:
163 def find_parents(pth: Path) -> Path:

Subscribers

People subscribed via source and target branches