Merge ~pelpsi/lpci:conda-build-outside-env into lpci:main

Proposed by Simone Pelosi
Status: Merged
Approved by: Simone Pelosi
Approved revision: de3704f1f6f4893930f9d1fe5862f4560824cec4
Merged at revision: de3704f1f6f4893930f9d1fe5862f4560824cec4
Proposed branch: ~pelpsi/lpci:conda-build-outside-env
Merge into: lpci:main
Diff against target: 134 lines (+12/-34)
4 files modified
NEWS.rst (+3/-0)
lpci/plugin/tests/test_plugins.py (+5/-19)
lpci/plugins/plugins.py (+3/-14)
setup.cfg (+1/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+442492@code.launchpad.net

Commit message

Fixed conda-build plugin

lpci conda build plugin should install and run conda-build outside of a conda environment

LP: #1978717

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Do make sure to explicitly test this with one or two of the Conda packages being maintained by the security team, if you haven't already - I don't know Conda well enough to be confident in what will work.

review: Approve

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 21b7957..5a0b3c7 100644
3--- a/NEWS.rst
4+++ b/NEWS.rst
5@@ -7,6 +7,9 @@ Version history
6
7 - Fix default value for the `root` flag in documentation.
8
9+- Fix conda-build plugin to install and run outside
10+ of a conda environment.
11+
12 0.2.1 (2023-06-06)
13 ==================
14
15diff --git a/lpci/plugin/tests/test_plugins.py b/lpci/plugin/tests/test_plugins.py
16index b0c5844..144286d 100644
17--- a/lpci/plugin/tests/test_plugins.py
18+++ b/lpci/plugin/tests/test_plugins.py
19@@ -364,22 +364,13 @@ class TestPlugins(CommandBaseTestCase):
20 /tmp/miniconda.sh -b
21 fi
22 export PATH=$HOME/miniconda3/bin:$PATH
23- conda remove --all -q -y -n $CONDA_ENV
24- conda create -n $CONDA_ENV -q -y -c conda-forge -c defaults PYTHON=3.8 mamba pip
25- source activate $CONDA_ENV
26+ conda install -q -y -c conda-forge -c defaults PYTHON=3.8 mamba pip
27 """ # noqa:E501
28 )
29
30- run_command = dedent(
31- """
32- export PATH=$HOME/miniconda3/bin:$PATH
33- source activate $CONDA_ENV
34- pip install --upgrade pytest
35- """
36- )
37+ run_command = dedent("""pip install --upgrade pytest\n""")
38 post_run_command = (
39- "export PATH=$HOME/miniconda3/bin:$PATH; "
40- "source activate $CONDA_ENV; conda env export"
41+ "export PATH=$HOME/miniconda3/bin:$PATH; conda env export"
42 )
43
44 self.run_command("run")
45@@ -563,22 +554,18 @@ class TestPlugins(CommandBaseTestCase):
46 /tmp/miniconda.sh -b
47 fi
48 export PATH=$HOME/miniconda3/bin:$PATH
49- conda remove --all -q -y -n $CONDA_ENV
50- conda create -n $CONDA_ENV -q -y -c conda-forge -c defaults -c https://user:pass@canonical.example.com/artifactory/soss-conda-stable-local/ PYTHON=3.8 conda-build mamba pip
51- source activate $CONDA_ENV
52+ conda install -q -y -c conda-forge -c defaults -c https://user:pass@canonical.example.com/artifactory/soss-conda-stable-local/ PYTHON=3.8 conda-build mamba pip
53 """ # noqa:E501
54 )
55 run_command = dedent(
56 """
57 export PATH=$HOME/miniconda3/bin:$PATH
58- source activate $CONDA_ENV
59 conda-build --no-anaconda-upload --output-folder dist -c conda-forge -c defaults -c https://user:pass@canonical.example.com/artifactory/soss-conda-stable-local/ info/recipe/parent
60 pip install --upgrade pytest
61 """ # noqa: E501
62 )
63 post_run_command = (
64- "export PATH=$HOME/miniconda3/bin:$PATH; "
65- "source activate $CONDA_ENV; conda env export"
66+ "export PATH=$HOME/miniconda3/bin:$PATH; conda env export"
67 )
68
69 self.run_command(
70@@ -866,7 +853,6 @@ class TestPlugins(CommandBaseTestCase):
71 run_command = dedent(
72 """
73 export PATH=$HOME/miniconda3/bin:$PATH
74- source activate $CONDA_ENV
75 conda-build --no-anaconda-upload --output-folder dist -c conda-forge -c defaults -m info/recipe/parent/conda_build_config.yaml -m info/recipe/conda_build_config.yaml info/recipe/parent
76 pip install --upgrade pytest
77 """ # noqa: E501
78diff --git a/lpci/plugins/plugins.py b/lpci/plugins/plugins.py
79index 6fe88a2..bf1c3ed 100644
80--- a/lpci/plugins/plugins.py
81+++ b/lpci/plugins/plugins.py
82@@ -206,29 +206,19 @@ class MiniCondaPlugin(BasePlugin):
83 /tmp/miniconda.sh -b
84 fi
85 export PATH=$HOME/miniconda3/bin:$PATH
86- conda remove --all -q -y -n $CONDA_ENV
87- conda create -n $CONDA_ENV -q -y {conda_channels} {' '.join(self.conda_packages)}
88- source activate $CONDA_ENV
89+ conda install -q -y {conda_channels} {' '.join(self.conda_packages)}
90 {run}""" # noqa:E501
91 )
92
93 @hookimpl # type: ignore
94 def lpci_execute_run(self) -> str:
95 run = self.config.run or ""
96- return textwrap.dedent(
97- f"""
98- export PATH=$HOME/miniconda3/bin:$PATH
99- source activate $CONDA_ENV
100- {run}"""
101- )
102+ return textwrap.dedent(f"{run}")
103
104 @hookimpl # type: ignore
105 def lpci_execute_after_run(self) -> str:
106 run = f"; {self.config.run_after}" if self.config.run_after else ""
107- return (
108- "export PATH=$HOME/miniconda3/bin:$PATH; "
109- f"source activate $CONDA_ENV; conda env export{run}"
110- )
111+ return f"export PATH=$HOME/miniconda3/bin:$PATH; conda env export{run}"
112
113
114 @register(name="conda-build")
115@@ -406,7 +396,6 @@ class CondaBuildPlugin(MiniCondaPlugin):
116 return textwrap.dedent(
117 f"""
118 export PATH=$HOME/miniconda3/bin:$PATH
119- source activate $CONDA_ENV
120 {build_command}{conda_channels}{configs} {self.build_target}
121 {run_command}"""
122 )
123diff --git a/setup.cfg b/setup.cfg
124index df6892d..1e3172c 100644
125--- a/setup.cfg
126+++ b/setup.cfg
127@@ -1,6 +1,6 @@
128 [metadata]
129 name = lpci
130-version = 0.2.1
131+version = 0.2.2.dev0
132 description = Runner for Launchpad CI jobs
133 long_description = file: README.rst
134 long_description_content_type = text/x-rst

Subscribers

People subscribed via source and target branches