Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 3/3] Remove support code for Python < 3.4
Date: Fri, 17 Jul 2020 04:48:55
Message-Id: 20200717044817.403211-3-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/3] Remove support code for Python < 3.2 by "Michał Górny"
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 lib/_emerge/AsynchronousLock.py | 12 +-------
4 lib/_emerge/EbuildMetadataPhase.py | 12 +-------
5 lib/_emerge/FifoIpcDaemon.py | 30 +------------------
6 lib/_emerge/PipeReader.py | 12 +-------
7 lib/_emerge/SpawnProcess.py | 16 ----------
8 lib/portage/dbapi/_MergeProcess.py | 10 -------
9 lib/portage/locks.py | 11 -------
10 lib/portage/process.py | 2 +-
11 lib/portage/util/_async/PipeLogger.py | 10 -------
12 lib/portage/util/_eventloop/EventLoop.py | 23 --------------
13 .../util/_eventloop/global_event_loop.py | 15 ++++------
14 lib/portage/util/futures/_asyncio/__init__.py | 26 +++++-----------
15 lib/portage/util/futures/unix_events.py | 4 +--
16 13 files changed, 20 insertions(+), 163 deletions(-)
17
18 diff --git a/lib/_emerge/AsynchronousLock.py b/lib/_emerge/AsynchronousLock.py
19 index aed1bcb15..d2a6773ff 100644
20 --- a/lib/_emerge/AsynchronousLock.py
21 +++ b/lib/_emerge/AsynchronousLock.py
22 @@ -1,4 +1,4 @@
23 -# Copyright 2010-2018 Gentoo Foundation
24 +# Copyright 2010-2020 Gentoo Authors
25 # Distributed under the terms of the GNU General Public License v2
26
27 import fcntl
28 @@ -192,16 +192,6 @@ class _LockProcess(AbstractPollTask):
29 fcntl.fcntl(in_pr, fcntl.F_SETFL,
30 fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
31
32 - # FD_CLOEXEC is enabled by default in Python >=3.4.
33 - if sys.hexversion < 0x3040000:
34 - try:
35 - fcntl.FD_CLOEXEC
36 - except AttributeError:
37 - pass
38 - else:
39 - fcntl.fcntl(in_pr, fcntl.F_SETFD,
40 - fcntl.fcntl(in_pr, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
41 -
42 self.scheduler.add_reader(in_pr, self._output_handler)
43 self._registered = True
44 self._proc = SpawnProcess(
45 diff --git a/lib/_emerge/EbuildMetadataPhase.py b/lib/_emerge/EbuildMetadataPhase.py
46 index efe71892c..d00f194c2 100644
47 --- a/lib/_emerge/EbuildMetadataPhase.py
48 +++ b/lib/_emerge/EbuildMetadataPhase.py
49 @@ -1,4 +1,4 @@
50 -# Copyright 1999-2018 Gentoo Foundation
51 +# Copyright 1999-2020 Gentoo Authors
52 # Distributed under the terms of the GNU General Public License v2
53
54 from _emerge.SubProcess import SubProcess
55 @@ -93,16 +93,6 @@ class EbuildMetadataPhase(SubProcess):
56 fcntl.fcntl(master_fd, fcntl.F_SETFL,
57 fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
58
59 - # FD_CLOEXEC is enabled by default in Python >=3.4.
60 - if sys.hexversion < 0x3040000:
61 - try:
62 - fcntl.FD_CLOEXEC
63 - except AttributeError:
64 - pass
65 - else:
66 - fcntl.fcntl(master_fd, fcntl.F_SETFD,
67 - fcntl.fcntl(master_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
68 -
69 fd_pipes[slave_fd] = slave_fd
70 settings["PORTAGE_PIPE_FD"] = str(slave_fd)
71
72 diff --git a/lib/_emerge/FifoIpcDaemon.py b/lib/_emerge/FifoIpcDaemon.py
73 index 2ec69d1cb..ab1fdb572 100644
74 --- a/lib/_emerge/FifoIpcDaemon.py
75 +++ b/lib/_emerge/FifoIpcDaemon.py
76 @@ -1,14 +1,8 @@
77 -# Copyright 2010-2018 Gentoo Foundation
78 +# Copyright 2010-2020 Gentoo Authors
79 # Distributed under the terms of the GNU General Public License v2
80
81 import sys
82
83 -try:
84 - import fcntl
85 -except ImportError:
86 - # http://bugs.jython.org/issue1074
87 - fcntl = None
88 -
89 from portage import os
90 from _emerge.AbstractPollTask import AbstractPollTask
91 from portage.cache.mappings import slot_dict_class
92 @@ -28,17 +22,6 @@ class FifoIpcDaemon(AbstractPollTask):
93 self._files.pipe_in = \
94 os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
95
96 - # FD_CLOEXEC is enabled by default in Python >=3.4.
97 - if sys.hexversion < 0x3040000 and fcntl is not None:
98 - try:
99 - fcntl.FD_CLOEXEC
100 - except AttributeError:
101 - pass
102 - else:
103 - fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
104 - fcntl.fcntl(self._files.pipe_in,
105 - fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
106 -
107 self.scheduler.add_reader(
108 self._files.pipe_in,
109 self._input_handler)
110 @@ -55,17 +38,6 @@ class FifoIpcDaemon(AbstractPollTask):
111 self._files.pipe_in = \
112 os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
113
114 - # FD_CLOEXEC is enabled by default in Python >=3.4.
115 - if sys.hexversion < 0x3040000 and fcntl is not None:
116 - try:
117 - fcntl.FD_CLOEXEC
118 - except AttributeError:
119 - pass
120 - else:
121 - fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
122 - fcntl.fcntl(self._files.pipe_in,
123 - fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
124 -
125 self.scheduler.add_reader(
126 self._files.pipe_in,
127 self._input_handler)
128 diff --git a/lib/_emerge/PipeReader.py b/lib/_emerge/PipeReader.py
129 index 1aa5ee3bf..90a31679e 100644
130 --- a/lib/_emerge/PipeReader.py
131 +++ b/lib/_emerge/PipeReader.py
132 @@ -1,4 +1,4 @@
133 -# Copyright 1999-2018 Gentoo Foundation
134 +# Copyright 1999-2020 Gentoo Authors
135 # Distributed under the terms of the GNU General Public License v2
136
137 import fcntl
138 @@ -27,16 +27,6 @@ class PipeReader(AbstractPollTask):
139 fcntl.fcntl(fd, fcntl.F_SETFL,
140 fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
141
142 - # FD_CLOEXEC is enabled by default in Python >=3.4.
143 - if sys.hexversion < 0x3040000:
144 - try:
145 - fcntl.FD_CLOEXEC
146 - except AttributeError:
147 - pass
148 - else:
149 - fcntl.fcntl(fd, fcntl.F_SETFD,
150 - fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
151 -
152 if self._use_array:
153 self.scheduler.add_reader(fd, self._array_output_handler, f)
154 else:
155 diff --git a/lib/_emerge/SpawnProcess.py b/lib/_emerge/SpawnProcess.py
156 index 60239a65a..91f5ed1a8 100644
157 --- a/lib/_emerge/SpawnProcess.py
158 +++ b/lib/_emerge/SpawnProcess.py
159 @@ -1,12 +1,6 @@
160 # Copyright 2008-2020 Gentoo Authors
161 # Distributed under the terms of the GNU General Public License v2
162
163 -try:
164 - import fcntl
165 -except ImportError:
166 - # http://bugs.jython.org/issue1074
167 - fcntl = None
168 -
169 import errno
170 import logging
171 import signal
172 @@ -129,16 +123,6 @@ class SpawnProcess(SubProcess):
173 stdout_fd = None
174 if can_log and not self.background:
175 stdout_fd = os.dup(fd_pipes_orig[1])
176 - # FD_CLOEXEC is enabled by default in Python >=3.4.
177 - if sys.hexversion < 0x3040000 and fcntl is not None:
178 - try:
179 - fcntl.FD_CLOEXEC
180 - except AttributeError:
181 - pass
182 - else:
183 - fcntl.fcntl(stdout_fd, fcntl.F_SETFD,
184 - fcntl.fcntl(stdout_fd,
185 - fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
186
187 build_logger = BuildLogger(env=self.env,
188 log_path=log_file_path,
189 diff --git a/lib/portage/dbapi/_MergeProcess.py b/lib/portage/dbapi/_MergeProcess.py
190 index 236d1a255..274ef586f 100644
191 --- a/lib/portage/dbapi/_MergeProcess.py
192 +++ b/lib/portage/dbapi/_MergeProcess.py
193 @@ -112,16 +112,6 @@ class MergeProcess(ForkProcess):
194 fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
195 fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
196
197 - # FD_CLOEXEC is enabled by default in Python >=3.4.
198 - if sys.hexversion < 0x3040000:
199 - try:
200 - fcntl.FD_CLOEXEC
201 - except AttributeError:
202 - pass
203 - else:
204 - fcntl.fcntl(elog_reader_fd, fcntl.F_SETFD,
205 - fcntl.fcntl(elog_reader_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
206 -
207 blockers = None
208 if self.blockers is not None:
209 # Query blockers in the main process, since closing
210 diff --git a/lib/portage/locks.py b/lib/portage/locks.py
211 index 5c7a3f266..9df0089e6 100644
212 --- a/lib/portage/locks.py
213 +++ b/lib/portage/locks.py
214 @@ -330,17 +330,6 @@ def _lockfile_iteration(mypath, wantnewlockfile=False, unlinkfile=False,
215 return None
216
217 if myfd != HARDLINK_FD:
218 -
219 - # FD_CLOEXEC is enabled by default in Python >=3.4.
220 - if sys.hexversion < 0x3040000:
221 - try:
222 - fcntl.FD_CLOEXEC
223 - except AttributeError:
224 - pass
225 - else:
226 - fcntl.fcntl(myfd, fcntl.F_SETFD,
227 - fcntl.fcntl(myfd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
228 -
229 _lock_manager(myfd, os.fstat(myfd) if fstat_result is None else fstat_result, mypath)
230
231 writemsg(str((lockfilename, myfd, unlinkfile)) + "\n", 1)
232 diff --git a/lib/portage/process.py b/lib/portage/process.py
233 index f550bcb30..6af668db4 100644
234 --- a/lib/portage/process.py
235 +++ b/lib/portage/process.py
236 @@ -223,7 +223,7 @@ def cleanup():
237 def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False,
238 uid=None, gid=None, groups=None, umask=None, cwd=None, logfile=None,
239 path_lookup=True, pre_exec=None,
240 - close_fds=(sys.version_info < (3, 4)), unshare_net=False,
241 + close_fds=False, unshare_net=False,
242 unshare_ipc=False, unshare_mount=False, unshare_pid=False,
243 cgroup=None):
244 """
245 diff --git a/lib/portage/util/_async/PipeLogger.py b/lib/portage/util/_async/PipeLogger.py
246 index cc746bf52..aa240806d 100644
247 --- a/lib/portage/util/_async/PipeLogger.py
248 +++ b/lib/portage/util/_async/PipeLogger.py
249 @@ -54,16 +54,6 @@ class PipeLogger(AbstractPollTask):
250 fcntl.fcntl(fd, fcntl.F_SETFL,
251 fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
252
253 - # FD_CLOEXEC is enabled by default in Python >=3.4.
254 - if sys.hexversion < 0x3040000:
255 - try:
256 - fcntl.FD_CLOEXEC
257 - except AttributeError:
258 - pass
259 - else:
260 - fcntl.fcntl(fd, fcntl.F_SETFD,
261 - fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
262 -
263 self._io_loop_task = asyncio.ensure_future(self._io_loop(self.input_fd), loop=self.scheduler)
264 self._io_loop_task.add_done_callback(self._io_loop_done)
265 self._registered = True
266 diff --git a/lib/portage/util/_eventloop/EventLoop.py b/lib/portage/util/_eventloop/EventLoop.py
267 index a3bea97aa..f870190d9 100644
268 --- a/lib/portage/util/_eventloop/EventLoop.py
269 +++ b/lib/portage/util/_eventloop/EventLoop.py
270 @@ -168,18 +168,6 @@ class EventLoop(object):
271 # IOError: [Errno 38] Function not implemented
272 pass
273 else:
274 -
275 - # FD_CLOEXEC is enabled by default in Python >=3.4.
276 - if sys.hexversion < 0x3040000 and fcntl is not None:
277 - try:
278 - fcntl.FD_CLOEXEC
279 - except AttributeError:
280 - pass
281 - else:
282 - fcntl.fcntl(epoll_obj.fileno(), fcntl.F_SETFD,
283 - fcntl.fcntl(epoll_obj.fileno(),
284 - fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
285 -
286 self._poll_obj = _epoll_adapter(epoll_obj)
287 self.IO_ERR = select.EPOLLERR
288 self.IO_HUP = select.EPOLLHUP
289 @@ -432,17 +420,6 @@ class EventLoop(object):
290 fcntl.fcntl(self._sigchld_read,
291 fcntl.F_GETFL) | os.O_NONBLOCK)
292
293 - # FD_CLOEXEC is enabled by default in Python >=3.4.
294 - if sys.hexversion < 0x3040000:
295 - try:
296 - fcntl.FD_CLOEXEC
297 - except AttributeError:
298 - pass
299 - else:
300 - fcntl.fcntl(self._sigchld_read, fcntl.F_SETFD,
301 - fcntl.fcntl(self._sigchld_read,
302 - fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
303 -
304 # The IO watch is dynamically registered and unregistered as
305 # needed, since we don't want to consider it as a valid source
306 # of events when there are no child listeners. It's important
307 diff --git a/lib/portage/util/_eventloop/global_event_loop.py b/lib/portage/util/_eventloop/global_event_loop.py
308 index 2f6371dc1..73b7db0d3 100644
309 --- a/lib/portage/util/_eventloop/global_event_loop.py
310 +++ b/lib/portage/util/_eventloop/global_event_loop.py
311 @@ -1,4 +1,4 @@
312 -# Copyright 2012 Gentoo Foundation
313 +# Copyright 2012-2020 Gentoo Authors
314 # Distributed under the terms of the GNU General Public License v2
315
316 import os
317 @@ -7,16 +7,11 @@ import sys
318 from .EventLoop import EventLoop
319 from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop
320
321 -_asyncio_enabled = sys.version_info >= (3, 4)
322 -_default_constructor = AsyncioEventLoop if _asyncio_enabled else EventLoop
323 -
324 -# If _default_constructor doesn't support multiprocessing,
325 -# then _multiprocessing_constructor is used in subprocesses.
326 -_multiprocessing_constructor = EventLoop
327
328 _MAIN_PID = os.getpid()
329 _instances = {}
330
331 +
332 def global_event_loop():
333 """
334 Get a global EventLoop (or compatible object) instance which
335 @@ -28,9 +23,11 @@ def global_event_loop():
336 if instance is not None:
337 return instance
338
339 - constructor = _default_constructor
340 + constructor = AsyncioEventLoop
341 + # If the default constructor doesn't support multiprocessing,
342 + # then multiprocessing constructor is used in subprocesses.
343 if not constructor.supports_multiprocessing and pid != _MAIN_PID:
344 - constructor = _multiprocessing_constructor
345 + constructor = EventLoop
346
347 # Use the _asyncio_wrapper attribute, so that unit tests can compare
348 # the reference to one retured from _wrap_loop(), since they should
349 diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py
350 index f4b03891f..04034911d 100644
351 --- a/lib/portage/util/futures/_asyncio/__init__.py
352 +++ b/lib/portage/util/futures/_asyncio/__init__.py
353 @@ -41,7 +41,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
354 )
355 from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop
356 from portage.util._eventloop.global_event_loop import (
357 - _asyncio_enabled,
358 global_event_loop as _global_event_loop,
359 )
360 from portage.util.futures.futures import (
361 @@ -111,11 +110,6 @@ def set_child_watcher(watcher):
362 return get_event_loop_policy().set_child_watcher(watcher)
363
364
365 -# Python 3.4 and later implement PEP 446, which makes newly
366 -# created file descriptors non-inheritable by default.
367 -_close_fds_default = sys.version_info < (3, 4)
368 -
369 -
370 def create_subprocess_exec(*args, **kwargs):
371 """
372 Create a subprocess.
373 @@ -138,8 +132,10 @@ def create_subprocess_exec(*args, **kwargs):
374 @return: subset of asyncio.subprocess.Process interface
375 """
376 loop = _wrap_loop(kwargs.pop('loop', None))
377 - kwargs.setdefault('close_fds', _close_fds_default)
378 - if _asyncio_enabled and isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
379 + # Python 3.4 and later implement PEP 446, which makes newly
380 + # created file descriptors non-inheritable by default.
381 + kwargs.setdefault('close_fds', False)
382 + if isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
383 # Use the real asyncio create_subprocess_exec (loop argument
384 # is deprecated since since Python 3.8).
385 return _real_asyncio.create_subprocess_exec(*args, **kwargs)
386 @@ -191,7 +187,7 @@ def ensure_future(coro_or_future, loop=None):
387 @return: an instance of Future
388 """
389 loop = _wrap_loop(loop)
390 - if _asyncio_enabled and isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
391 + if isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
392 # Use the real asyncio loop and ensure_future.
393 return _real_asyncio.ensure_future(
394 coro_or_future, loop=loop._asyncio_wrapper._loop)
395 @@ -240,18 +236,12 @@ def _wrap_loop(loop=None):
396 @rtype: asyncio.AbstractEventLoop (or compatible)
397 @return: event loop
398 """
399 - return loop or _global_event_loop()
400 -
401 -
402 -if _asyncio_enabled:
403 # The default loop returned by _wrap_loop should be consistent
404 # with global_event_loop, in order to avoid accidental registration
405 # of callbacks with a loop that is not intended to run.
406 -
407 - def _wrap_loop(loop=None):
408 - loop = loop or _global_event_loop()
409 - return (loop if hasattr(loop, '_asyncio_wrapper')
410 - else _AsyncioEventLoop(loop=loop))
411 + loop = loop or _global_event_loop()
412 + return (loop if hasattr(loop, '_asyncio_wrapper')
413 + else _AsyncioEventLoop(loop=loop))
414
415
416 def _safe_loop():
417 diff --git a/lib/portage/util/futures/unix_events.py b/lib/portage/util/futures/unix_events.py
418 index 3381eaa7d..4adf021ce 100644
419 --- a/lib/portage/util/futures/unix_events.py
420 +++ b/lib/portage/util/futures/unix_events.py
421 @@ -32,7 +32,6 @@ import subprocess
422 import sys
423
424 from portage.util._eventloop.global_event_loop import (
425 - _asyncio_enabled,
426 global_event_loop as _global_event_loop,
427 )
428 from portage.util.futures import (
429 @@ -701,5 +700,4 @@ class _AsyncioEventLoopPolicy(_PortageEventLoopPolicy):
430 return super(_AsyncioEventLoopPolicy, self).get_child_watcher()
431
432
433 -DefaultEventLoopPolicy = (_AsyncioEventLoopPolicy if _asyncio_enabled
434 - else _PortageEventLoopPolicy)
435 +DefaultEventLoopPolicy = _AsyncioEventLoopPolicy
436 --
437 2.27.0

Replies