Merge ~jugmac00/lpci:add-pyproject-build-plugin into lpci:main

Proposed by Jürgen Gmach
Status: Merged
Merged at revision: 1035ab1dde99600ff3faa96ef13934eaa66df504
Proposed branch: ~jugmac00/lpci:add-pyproject-build-plugin
Merge into: lpci:main
Diff against target: 166 lines (+97/-5)
5 files modified
.gitignore (+1/-0)
.launchpad.yaml (+5/-0)
docs/conf.py (+1/-1)
lpcraft/plugin/tests/test_plugins.py (+59/-3)
lpcraft/plugins/plugins.py (+31/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+414393@code.launchpad.net

Commit message

Create `pyproject-build` plugin

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Currently `pyproject-build` gets installed via pip. We have agreed upon that we should create a PPA for `pyproject-build`.

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

I completely expect this to need more fine-tuning, but it's fine to start with.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index 903613f..abb3ac0 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -6,4 +6,5 @@ __pycache__
6 .coverage
7 htmlcov
8 build/
9+dist/
10 docs/_build/
11diff --git a/.launchpad.yaml b/.launchpad.yaml
12index f9993cd..290429c 100644
13--- a/.launchpad.yaml
14+++ b/.launchpad.yaml
15@@ -1,5 +1,6 @@
16 pipeline:
17 - test
18+ - build
19
20 jobs:
21 test:
22@@ -7,3 +8,7 @@ jobs:
23 architectures: amd64
24 packages: [git]
25 plugin: tox
26+ build:
27+ series: focal
28+ architectures: amd64
29+ plugin: pyproject-build
30diff --git a/docs/conf.py b/docs/conf.py
31index 0b5ba94..678f3f9 100644
32--- a/docs/conf.py
33+++ b/docs/conf.py
34@@ -19,7 +19,7 @@ sys.path.insert(0, os.path.abspath(".."))
35 # -- Project information -----------------------------------------------------
36
37 project = "lpcraft"
38-copyright = "2021, Canonical Ltd"
39+copyright = "2021-2022, Canonical Ltd"
40
41
42 # -- General configuration ---------------------------------------------------
43diff --git a/lpcraft/plugin/tests/test_plugins.py b/lpcraft/plugin/tests/test_plugins.py
44index 276e963..6e89d1e 100644
45--- a/lpcraft/plugin/tests/test_plugins.py
46+++ b/lpcraft/plugin/tests/test_plugins.py
47@@ -40,9 +40,7 @@ class TestPlugins(CommandBaseTestCase):
48
49 @patch("lpcraft.commands.run.get_provider")
50 @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
51- def test_builtin_plugin(
52- self, mock_get_host_architecture, mock_get_provider
53- ):
54+ def test_tox_plugin(self, mock_get_host_architecture, mock_get_provider):
55 launcher = Mock(spec=launch)
56 provider = self.makeLXDProvider(lxd_launcher=launcher)
57 mock_get_provider.return_value = provider
58@@ -183,3 +181,61 @@ class TestPlugins(CommandBaseTestCase):
59 ],
60 execute_run.call_args_list,
61 )
62+
63+ @patch("lpcraft.commands.run.get_provider")
64+ @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
65+ def test_pyproject_build_plugin(
66+ self, mock_get_host_architecture, mock_get_provider
67+ ):
68+ launcher = Mock(spec=launch)
69+ provider = self.makeLXDProvider(lxd_launcher=launcher)
70+ mock_get_provider.return_value = provider
71+ execute_run = launcher.return_value.execute_run
72+ execute_run.return_value = subprocess.CompletedProcess([], 0)
73+ config = dedent(
74+ """
75+ pipeline:
76+ - build
77+
78+ jobs:
79+ build:
80+ series: focal
81+ architectures: amd64
82+ plugin: pyproject-build
83+ """
84+ )
85+ Path(".launchpad.yaml").write_text(config)
86+
87+ self.run_command("run")
88+
89+ self.assertEqual(
90+ [
91+ call(
92+ [
93+ "apt",
94+ "install",
95+ "-y",
96+ "python3-pip",
97+ "python3-venv",
98+ ],
99+ cwd=PosixPath("/root/project"),
100+ env={},
101+ stdout=ANY,
102+ stderr=ANY,
103+ ),
104+ call(
105+ [
106+ "bash",
107+ "--noprofile",
108+ "--norc",
109+ "-ec",
110+ "python3 -m pip install build==0.7.0; python3 -m build", # noqa: E501
111+ ],
112+ cwd=PosixPath("/root/project"),
113+ env={},
114+ stdout=ANY,
115+ stderr=ANY,
116+ ),
117+ ],
118+ execute_run.call_args_list,
119+ )
120diff --git a/lpcraft/plugins/plugins.py b/lpcraft/plugins/plugins.py
121index cf5862b..7708e35 100644
122--- a/lpcraft/plugins/plugins.py
123+++ b/lpcraft/plugins/plugins.py
124@@ -3,7 +3,7 @@
125
126 from __future__ import annotations
127
128-__all__ = ["ToxPlugin"]
129+__all__ = ["ToxPlugin", "PyProjectBuildPlugin"]
130
131 from lpcraft.config import Job
132 from lpcraft.plugin import hookimpl
133@@ -38,3 +38,33 @@ class ToxPlugin:
134 # necessary. Let's remove this once we have a plugin which actually
135 # needs to set environment variables.
136 return {"PLUGIN": "tox"}
137+
138+
139+@register(name="pyproject-build")
140+class PyProjectBuildPlugin:
141+ """Installs `build` and builds a Python package according to PEP 517.
142+
143+ Usage:
144+ In `.launchpad.yaml` create a key/value pair with `plugin` and
145+ `pyproject-build` within the job definition.
146+ """
147+
148+ def __init__(self, config: Job) -> None:
149+ self.config = config
150+
151+ @hookimpl # type: ignore
152+ def lpcraft_install_packages(self) -> list[str]:
153+ # Ubuntu 20.04 does not provide a packaged version of build,
154+ # so we need pip to install it
155+ #
156+ # `build` needs `python3-venv` to create an isolated build
157+ # environment
158+ return [
159+ "python3-pip",
160+ "python3-venv",
161+ ]
162+
163+ @hookimpl # type: ignore
164+ def lpcraft_execute_run(self) -> str:
165+ # XXX jugmac00 2022-01-20: we should consider using a PPA
166+ return "python3 -m pip install build==0.7.0; python3 -m build"

Subscribers

People subscribed via source and target branches