Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/5] dev-python/sip: Backport PEP517 argument passing support
Date: Tue, 10 May 2022 21:12:47
Message-Id: 20220510211211.2091-2-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/5] distutils-r1.eclass: sipbuild PEP517 support by "Michał Górny"
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 .../sip/files/sip-6.5.0-pep517-args.patch | 190 ++++++++++++++++++
4 dev-python/sip/sip-6.5.0-r1.ebuild | 36 ++++
5 2 files changed, 226 insertions(+)
6 create mode 100644 dev-python/sip/files/sip-6.5.0-pep517-args.patch
7 create mode 100644 dev-python/sip/sip-6.5.0-r1.ebuild
8
9 diff --git a/dev-python/sip/files/sip-6.5.0-pep517-args.patch b/dev-python/sip/files/sip-6.5.0-pep517-args.patch
10 new file mode 100644
11 index 000000000000..c4d39dcf6156
12 --- /dev/null
13 +++ b/dev-python/sip/files/sip-6.5.0-pep517-args.patch
14 @@ -0,0 +1,190 @@
15 +Backport from https://www.riverbankcomputing.com/hg/sip/
16 +
17 +changeset: 2771:8543f04b374f
18 +branch: 6.6-maint
19 +tag: tip
20 +user: Phil Thompson <phil@××××××××××××××××××.com>
21 +date: Tue May 10 13:58:28 2022 +0100
22 +summary: Fixed the PEP571 backend to handle multiple instances of the same config
23 +
24 +changeset: 2769:c02af095a016
25 +branch: 6.6-maint
26 +user: Phil Thompson <phil@××××××××××××××××××.com>
27 +date: Sat May 07 15:18:14 2022 +0100
28 +summary: Fix an API backward incompatibility.
29 +
30 +changeset: 2768:98dbce3e62f1
31 +branch: 6.6-maint
32 +user: Phil Thompson <phil@××××××××××××××××××.com>
33 +date: Sat May 07 15:03:49 2022 +0100
34 +summary: Any config settings passed by a PEP 571 frontend are now used.
35 +
36 +diff -r 8583e2bb1b32 sipbuild/abstract_project.py
37 +--- a/sipbuild/abstract_project.py Thu Nov 25 18:15:32 2021 +0000
38 ++++ b/sipbuild/abstract_project.py Tue May 10 16:15:30 2022 +0200
39 +@@ -1,4 +1,4 @@
40 +-# Copyright (c) 2020, Riverbank Computing Limited
41 ++# Copyright (c) 2022, Riverbank Computing Limited
42 + # All rights reserved.
43 + #
44 + # This copy of SIP is licensed for use under the terms of the SIP License
45 +@@ -34,7 +34,7 @@
46 + """ This specifies the API of a project. """
47 +
48 + @classmethod
49 +- def bootstrap(cls, tool, tool_description=''):
50 ++ def bootstrap(cls, tool, tool_description='', arguments=None):
51 + """ Return an AbstractProject instance fully configured for a
52 + particular command line tool.
53 + """
54 +@@ -79,6 +79,10 @@
55 + "The project factory did not return an AbstractProject "
56 + "object")
57 +
58 ++ # We set this as an attribute rather than change the API of the ctor or
59 ++ # setup().
60 ++ project.arguments = arguments
61 ++
62 + # Complete the configuration of the project.
63 + project.setup(pyproject, tool, tool_description)
64 +
65 +diff -r 8583e2bb1b32 sipbuild/api.py
66 +--- a/sipbuild/api.py Thu Nov 25 18:15:32 2021 +0000
67 ++++ b/sipbuild/api.py Tue May 10 16:15:30 2022 +0200
68 +@@ -1,4 +1,4 @@
69 +-# Copyright (c) 2019, Riverbank Computing Limited
70 ++# Copyright (c) 2022, Riverbank Computing Limited
71 + # All rights reserved.
72 + #
73 + # This copy of SIP is licensed for use under the terms of the SIP License
74 +@@ -28,10 +28,8 @@
75 + def build_sdist(sdist_directory, config_settings=None):
76 + """ The PEP 517 hook for building an sdist from pyproject.toml. """
77 +
78 +- # Note that we ignore config_settings until we have a frontend that we can
79 +- # fully test with. (pip seems lacking at the moment.)
80 +-
81 +- project = AbstractProject.bootstrap('pep517')
82 ++ project = AbstractProject.bootstrap('sdist',
83 ++ arguments=_convert_config_settings(config_settings))
84 +
85 + # pip executes this in a separate process and doesn't handle exceptions
86 + # very well. However it does capture stdout and (eventually) show it to
87 +@@ -45,10 +43,8 @@
88 + def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
89 + """ The PEP 517 hook for building a wheel from pyproject.toml. """
90 +
91 +- # Note that we ignore config_settings until we have a frontend that we can
92 +- # fully test with. (pip seems lacking at the moment.)
93 +-
94 +- project = AbstractProject.bootstrap('pep517')
95 ++ project = AbstractProject.bootstrap('wheel',
96 ++ arguments=_convert_config_settings(config_settings))
97 +
98 + # pip executes this in a separate process and doesn't handle exceptions
99 + # very well. However it does capture stdout and (eventually) show it to
100 +@@ -57,3 +53,26 @@
101 + return project.build_wheel(wheel_directory)
102 + except Exception as e:
103 + handle_exception(e)
104 ++
105 ++
106 ++def _convert_config_settings(config_settings):
107 ++ """ Return any configuration settings from the frontend to a pseudo-command
108 ++ line.
109 ++ """
110 ++
111 ++ if config_settings is None:
112 ++ config_settings = {}
113 ++
114 ++ args = []
115 ++
116 ++ for name, value in config_settings.items():
117 ++ if value:
118 ++ if not isinstance(value, list):
119 ++ value = [value]
120 ++
121 ++ for m_value in value:
122 ++ args.append(name + '=' + m_value)
123 ++ else:
124 ++ args.append(name)
125 ++
126 ++ return args
127 +diff -r 8583e2bb1b32 sipbuild/configurable.py
128 +--- a/sipbuild/configurable.py Thu Nov 25 18:15:32 2021 +0000
129 ++++ b/sipbuild/configurable.py Tue May 10 16:15:30 2022 +0200
130 +@@ -1,4 +1,4 @@
131 +-# Copyright (c) 2021, Riverbank Computing Limited
132 ++# Copyright (c) 2022, Riverbank Computing Limited
133 + # All rights reserved.
134 + #
135 + # This copy of SIP is licensed for use under the terms of the SIP License
136 +@@ -244,7 +244,7 @@
137 + """
138 +
139 + # The tools that will build a set of bindings.
140 +- BUILD_TOOLS = ('build', 'install', 'pep517', 'wheel')
141 ++ BUILD_TOOLS = ('build', 'install', 'wheel')
142 +
143 + # All the valid tools.
144 + _ALL_TOOLS = BUILD_TOOLS + ('sdist', )
145 +diff -r 8583e2bb1b32 sipbuild/project.py
146 +--- a/sipbuild/project.py Thu Nov 25 18:15:32 2021 +0000
147 ++++ b/sipbuild/project.py Tue May 10 16:15:30 2022 +0200
148 +@@ -155,6 +155,7 @@
149 +
150 + # The current directory should contain the .toml file.
151 + self.root_dir = os.getcwd()
152 ++ self.arguments = None
153 + self.bindings = collections.OrderedDict()
154 + self.bindings_factories = []
155 + self.builder = None
156 +@@ -204,11 +205,6 @@
157 + def apply_user_defaults(self, tool):
158 + """ Set default values for user options that haven't been set yet. """
159 +
160 +- # If we are the backend to a 3rd-party frontend (most probably pip)
161 +- # then let it handle the verbosity of messages.
162 +- if self.verbose is None and tool == '':
163 +- self.verbose = True
164 +-
165 + # This is only used when creating sdist and wheel files.
166 + if self.name is None:
167 + self.name = self.metadata['name']
168 +@@ -569,14 +565,9 @@
169 + # Set the initial configuration from the pyproject.toml file.
170 + self._set_initial_configuration(pyproject, tool)
171 +
172 +- # Add any tool-specific command line options for (so far unspecified)
173 ++ # Add any tool-specific command line arguments for (so far unspecified)
174 + # parts of the configuration.
175 +- if tool != 'pep517':
176 +- self._configure_from_command_line(tool, tool_description)
177 +- else:
178 +- # Until pip improves it's error reporting we give the user all the
179 +- # help we can.
180 +- self.verbose = True
181 ++ self._configure_from_arguments(tool, tool_description)
182 +
183 + # Now that any help has been given we can report a problematic
184 + # pyproject.toml file.
185 +@@ -712,8 +703,8 @@
186 + for bindings in self.bindings.values():
187 + bindings.verify_configuration(tool)
188 +
189 +- def _configure_from_command_line(self, tool, tool_description):
190 +- """ Update the configuration from the user supplied command line. """
191 ++ def _configure_from_arguments(self, tool, tool_description):
192 ++ """ Update the configuration from any user supplied arguments. """
193 +
194 + from argparse import SUPPRESS
195 + from .argument_parser import ArgumentParser
196 +@@ -739,7 +730,7 @@
197 + bindings.add_command_line_options(parser, tool, all_options)
198 +
199 + # Parse the arguments and update the corresponding configurables.
200 +- args = parser.parse_args()
201 ++ args = parser.parse_args(self.arguments)
202 +
203 + for option, configurables in all_options.items():
204 + for configurable in configurables:
205 diff --git a/dev-python/sip/sip-6.5.0-r1.ebuild b/dev-python/sip/sip-6.5.0-r1.ebuild
206 new file mode 100644
207 index 000000000000..6b5db83860f0
208 --- /dev/null
209 +++ b/dev-python/sip/sip-6.5.0-r1.ebuild
210 @@ -0,0 +1,36 @@
211 +# Copyright 1999-2021 Gentoo Authors
212 +# Distributed under the terms of the GNU General Public License v2
213 +
214 +EAPI=8
215 +
216 +PYTHON_COMPAT=( python3_{8..10} )
217 +DISTUTILS_USE_SETUPTOOLS=rdepend
218 +inherit distutils-r1
219 +
220 +DESCRIPTION="Python bindings generator for C/C++ libraries"
221 +HOMEPAGE="https://www.riverbankcomputing.com/software/sip/ https://pypi.org/project/sip/"
222 +
223 +MY_P=${PN}-${PV/_pre/.dev}
224 +if [[ ${PV} == *_pre* ]]; then
225 + SRC_URI="https://dev.gentoo.org/~pesa/distfiles/${MY_P}.tar.gz"
226 +else
227 + SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${MY_P}.tar.gz"
228 +fi
229 +S=${WORKDIR}/${MY_P}
230 +
231 +LICENSE="|| ( GPL-2 GPL-3 SIP )"
232 +SLOT="5"
233 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~riscv ~sparc ~x86"
234 +
235 +RDEPEND="
236 + !<dev-python/sip-4.19.25-r1[${PYTHON_USEDEP}]
237 + !=dev-python/sip-5.5.0-r0[${PYTHON_USEDEP}]
238 + dev-python/packaging[${PYTHON_USEDEP}]
239 + dev-python/toml[${PYTHON_USEDEP}]
240 +"
241 +
242 +distutils_enable_sphinx doc --no-autodoc
243 +
244 +PATCHES=(
245 + "${FILESDIR}"/${P}-pep517-args.patch
246 +)
247 --
248 2.35.1