aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2020-07-17 06:38:42 +0200
committerMichał Górny <mgorny@gentoo.org>2020-07-17 08:36:19 +0200
commit070b5268486d5a1443a0dc6c1317c704c1298218 (patch)
treedc137dfd25342bd8985a31e6c57cbbbacca13f19
parentRemove support code for Python < 3.3 (diff)
downloadportage-070b5268486d5a1443a0dc6c1317c704c1298218.tar.gz
portage-070b5268486d5a1443a0dc6c1317c704c1298218.tar.bz2
portage-070b5268486d5a1443a0dc6c1317c704c1298218.zip
Remove support code for Python < 3.4
Reviewed-by: Zac Medico <zmedico@gentoo.org> Closes: https://github.com/gentoo/portage/pull/576 Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--lib/_emerge/AsynchronousLock.py12
-rw-r--r--lib/_emerge/EbuildMetadataPhase.py12
-rw-r--r--lib/_emerge/FifoIpcDaemon.py30
-rw-r--r--lib/_emerge/PipeReader.py12
-rw-r--r--lib/_emerge/SpawnProcess.py16
-rw-r--r--lib/portage/dbapi/_MergeProcess.py10
-rw-r--r--lib/portage/locks.py11
-rw-r--r--lib/portage/process.py2
-rw-r--r--lib/portage/util/_async/PipeLogger.py10
-rw-r--r--lib/portage/util/_eventloop/EventLoop.py23
-rw-r--r--lib/portage/util/_eventloop/global_event_loop.py15
-rw-r--r--lib/portage/util/futures/_asyncio/__init__.py26
-rw-r--r--lib/portage/util/futures/unix_events.py4
13 files changed, 20 insertions, 163 deletions
diff --git a/lib/_emerge/AsynchronousLock.py b/lib/_emerge/AsynchronousLock.py
index aed1bcb15..d2a6773ff 100644
--- a/lib/_emerge/AsynchronousLock.py
+++ b/lib/_emerge/AsynchronousLock.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2018 Gentoo Foundation
+# Copyright 2010-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import fcntl
@@ -192,16 +192,6 @@ class _LockProcess(AbstractPollTask):
fcntl.fcntl(in_pr, fcntl.F_SETFL,
fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(in_pr, fcntl.F_SETFD,
- fcntl.fcntl(in_pr, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
self.scheduler.add_reader(in_pr, self._output_handler)
self._registered = True
self._proc = SpawnProcess(
diff --git a/lib/_emerge/EbuildMetadataPhase.py b/lib/_emerge/EbuildMetadataPhase.py
index efe71892c..d00f194c2 100644
--- a/lib/_emerge/EbuildMetadataPhase.py
+++ b/lib/_emerge/EbuildMetadataPhase.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from _emerge.SubProcess import SubProcess
@@ -93,16 +93,6 @@ class EbuildMetadataPhase(SubProcess):
fcntl.fcntl(master_fd, fcntl.F_SETFL,
fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(master_fd, fcntl.F_SETFD,
- fcntl.fcntl(master_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
fd_pipes[slave_fd] = slave_fd
settings["PORTAGE_PIPE_FD"] = str(slave_fd)
diff --git a/lib/_emerge/FifoIpcDaemon.py b/lib/_emerge/FifoIpcDaemon.py
index 2ec69d1cb..ab1fdb572 100644
--- a/lib/_emerge/FifoIpcDaemon.py
+++ b/lib/_emerge/FifoIpcDaemon.py
@@ -1,14 +1,8 @@
-# Copyright 2010-2018 Gentoo Foundation
+# Copyright 2010-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import sys
-try:
- import fcntl
-except ImportError:
- # http://bugs.jython.org/issue1074
- fcntl = None
-
from portage import os
from _emerge.AbstractPollTask import AbstractPollTask
from portage.cache.mappings import slot_dict_class
@@ -28,17 +22,6 @@ class FifoIpcDaemon(AbstractPollTask):
self._files.pipe_in = \
os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000 and fcntl is not None:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
- fcntl.fcntl(self._files.pipe_in,
- fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
self.scheduler.add_reader(
self._files.pipe_in,
self._input_handler)
@@ -55,17 +38,6 @@ class FifoIpcDaemon(AbstractPollTask):
self._files.pipe_in = \
os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000 and fcntl is not None:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
- fcntl.fcntl(self._files.pipe_in,
- fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
self.scheduler.add_reader(
self._files.pipe_in,
self._input_handler)
diff --git a/lib/_emerge/PipeReader.py b/lib/_emerge/PipeReader.py
index 1aa5ee3bf..90a31679e 100644
--- a/lib/_emerge/PipeReader.py
+++ b/lib/_emerge/PipeReader.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import fcntl
@@ -27,16 +27,6 @@ class PipeReader(AbstractPollTask):
fcntl.fcntl(fd, fcntl.F_SETFL,
fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(fd, fcntl.F_SETFD,
- fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
if self._use_array:
self.scheduler.add_reader(fd, self._array_output_handler, f)
else:
diff --git a/lib/_emerge/SpawnProcess.py b/lib/_emerge/SpawnProcess.py
index 60239a65a..91f5ed1a8 100644
--- a/lib/_emerge/SpawnProcess.py
+++ b/lib/_emerge/SpawnProcess.py
@@ -1,12 +1,6 @@
# Copyright 2008-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-try:
- import fcntl
-except ImportError:
- # http://bugs.jython.org/issue1074
- fcntl = None
-
import errno
import logging
import signal
@@ -129,16 +123,6 @@ class SpawnProcess(SubProcess):
stdout_fd = None
if can_log and not self.background:
stdout_fd = os.dup(fd_pipes_orig[1])
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000 and fcntl is not None:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(stdout_fd, fcntl.F_SETFD,
- fcntl.fcntl(stdout_fd,
- fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
build_logger = BuildLogger(env=self.env,
log_path=log_file_path,
diff --git a/lib/portage/dbapi/_MergeProcess.py b/lib/portage/dbapi/_MergeProcess.py
index 236d1a255..274ef586f 100644
--- a/lib/portage/dbapi/_MergeProcess.py
+++ b/lib/portage/dbapi/_MergeProcess.py
@@ -112,16 +112,6 @@ class MergeProcess(ForkProcess):
fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(elog_reader_fd, fcntl.F_SETFD,
- fcntl.fcntl(elog_reader_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
blockers = None
if self.blockers is not None:
# Query blockers in the main process, since closing
diff --git a/lib/portage/locks.py b/lib/portage/locks.py
index 5c7a3f266..9df0089e6 100644
--- a/lib/portage/locks.py
+++ b/lib/portage/locks.py
@@ -330,17 +330,6 @@ def _lockfile_iteration(mypath, wantnewlockfile=False, unlinkfile=False,
return None
if myfd != HARDLINK_FD:
-
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(myfd, fcntl.F_SETFD,
- fcntl.fcntl(myfd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
_lock_manager(myfd, os.fstat(myfd) if fstat_result is None else fstat_result, mypath)
writemsg(str((lockfilename, myfd, unlinkfile)) + "\n", 1)
diff --git a/lib/portage/process.py b/lib/portage/process.py
index f550bcb30..6af668db4 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -223,7 +223,7 @@ def cleanup():
def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False,
uid=None, gid=None, groups=None, umask=None, cwd=None, logfile=None,
path_lookup=True, pre_exec=None,
- close_fds=(sys.version_info < (3, 4)), unshare_net=False,
+ close_fds=False, unshare_net=False,
unshare_ipc=False, unshare_mount=False, unshare_pid=False,
cgroup=None):
"""
diff --git a/lib/portage/util/_async/PipeLogger.py b/lib/portage/util/_async/PipeLogger.py
index cc746bf52..aa240806d 100644
--- a/lib/portage/util/_async/PipeLogger.py
+++ b/lib/portage/util/_async/PipeLogger.py
@@ -54,16 +54,6 @@ class PipeLogger(AbstractPollTask):
fcntl.fcntl(fd, fcntl.F_SETFL,
fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(fd, fcntl.F_SETFD,
- fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
self._io_loop_task = asyncio.ensure_future(self._io_loop(self.input_fd), loop=self.scheduler)
self._io_loop_task.add_done_callback(self._io_loop_done)
self._registered = True
diff --git a/lib/portage/util/_eventloop/EventLoop.py b/lib/portage/util/_eventloop/EventLoop.py
index a3bea97aa..f870190d9 100644
--- a/lib/portage/util/_eventloop/EventLoop.py
+++ b/lib/portage/util/_eventloop/EventLoop.py
@@ -168,18 +168,6 @@ class EventLoop(object):
# IOError: [Errno 38] Function not implemented
pass
else:
-
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000 and fcntl is not None:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(epoll_obj.fileno(), fcntl.F_SETFD,
- fcntl.fcntl(epoll_obj.fileno(),
- fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
self._poll_obj = _epoll_adapter(epoll_obj)
self.IO_ERR = select.EPOLLERR
self.IO_HUP = select.EPOLLHUP
@@ -432,17 +420,6 @@ class EventLoop(object):
fcntl.fcntl(self._sigchld_read,
fcntl.F_GETFL) | os.O_NONBLOCK)
- # FD_CLOEXEC is enabled by default in Python >=3.4.
- if sys.hexversion < 0x3040000:
- try:
- fcntl.FD_CLOEXEC
- except AttributeError:
- pass
- else:
- fcntl.fcntl(self._sigchld_read, fcntl.F_SETFD,
- fcntl.fcntl(self._sigchld_read,
- fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
-
# The IO watch is dynamically registered and unregistered as
# needed, since we don't want to consider it as a valid source
# of events when there are no child listeners. It's important
diff --git a/lib/portage/util/_eventloop/global_event_loop.py b/lib/portage/util/_eventloop/global_event_loop.py
index 2f6371dc1..73b7db0d3 100644
--- a/lib/portage/util/_eventloop/global_event_loop.py
+++ b/lib/portage/util/_eventloop/global_event_loop.py
@@ -1,4 +1,4 @@
-# Copyright 2012 Gentoo Foundation
+# Copyright 2012-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import os
@@ -7,16 +7,11 @@ import sys
from .EventLoop import EventLoop
from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop
-_asyncio_enabled = sys.version_info >= (3, 4)
-_default_constructor = AsyncioEventLoop if _asyncio_enabled else EventLoop
-
-# If _default_constructor doesn't support multiprocessing,
-# then _multiprocessing_constructor is used in subprocesses.
-_multiprocessing_constructor = EventLoop
_MAIN_PID = os.getpid()
_instances = {}
+
def global_event_loop():
"""
Get a global EventLoop (or compatible object) instance which
@@ -28,9 +23,11 @@ def global_event_loop():
if instance is not None:
return instance
- constructor = _default_constructor
+ constructor = AsyncioEventLoop
+ # If the default constructor doesn't support multiprocessing,
+ # then multiprocessing constructor is used in subprocesses.
if not constructor.supports_multiprocessing and pid != _MAIN_PID:
- constructor = _multiprocessing_constructor
+ constructor = EventLoop
# Use the _asyncio_wrapper attribute, so that unit tests can compare
# the reference to one retured from _wrap_loop(), since they should
diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py
index f4b03891f..04034911d 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -41,7 +41,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
)
from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop
from portage.util._eventloop.global_event_loop import (
- _asyncio_enabled,
global_event_loop as _global_event_loop,
)
from portage.util.futures.futures import (
@@ -111,11 +110,6 @@ def set_child_watcher(watcher):
return get_event_loop_policy().set_child_watcher(watcher)
-# Python 3.4 and later implement PEP 446, which makes newly
-# created file descriptors non-inheritable by default.
-_close_fds_default = sys.version_info < (3, 4)
-
-
def create_subprocess_exec(*args, **kwargs):
"""
Create a subprocess.
@@ -138,8 +132,10 @@ def create_subprocess_exec(*args, **kwargs):
@return: subset of asyncio.subprocess.Process interface
"""
loop = _wrap_loop(kwargs.pop('loop', None))
- kwargs.setdefault('close_fds', _close_fds_default)
- if _asyncio_enabled and isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
+ # Python 3.4 and later implement PEP 446, which makes newly
+ # created file descriptors non-inheritable by default.
+ kwargs.setdefault('close_fds', False)
+ if isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
# Use the real asyncio create_subprocess_exec (loop argument
# is deprecated since since Python 3.8).
return _real_asyncio.create_subprocess_exec(*args, **kwargs)
@@ -191,7 +187,7 @@ def ensure_future(coro_or_future, loop=None):
@return: an instance of Future
"""
loop = _wrap_loop(loop)
- if _asyncio_enabled and isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
+ if isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
# Use the real asyncio loop and ensure_future.
return _real_asyncio.ensure_future(
coro_or_future, loop=loop._asyncio_wrapper._loop)
@@ -240,18 +236,12 @@ def _wrap_loop(loop=None):
@rtype: asyncio.AbstractEventLoop (or compatible)
@return: event loop
"""
- return loop or _global_event_loop()
-
-
-if _asyncio_enabled:
# The default loop returned by _wrap_loop should be consistent
# with global_event_loop, in order to avoid accidental registration
# of callbacks with a loop that is not intended to run.
-
- def _wrap_loop(loop=None):
- loop = loop or _global_event_loop()
- return (loop if hasattr(loop, '_asyncio_wrapper')
- else _AsyncioEventLoop(loop=loop))
+ loop = loop or _global_event_loop()
+ return (loop if hasattr(loop, '_asyncio_wrapper')
+ else _AsyncioEventLoop(loop=loop))
def _safe_loop():
diff --git a/lib/portage/util/futures/unix_events.py b/lib/portage/util/futures/unix_events.py
index 3381eaa7d..4adf021ce 100644
--- a/lib/portage/util/futures/unix_events.py
+++ b/lib/portage/util/futures/unix_events.py
@@ -32,7 +32,6 @@ import subprocess
import sys
from portage.util._eventloop.global_event_loop import (
- _asyncio_enabled,
global_event_loop as _global_event_loop,
)
from portage.util.futures import (
@@ -701,5 +700,4 @@ class _AsyncioEventLoopPolicy(_PortageEventLoopPolicy):
return super(_AsyncioEventLoopPolicy, self).get_child_watcher()
-DefaultEventLoopPolicy = (_AsyncioEventLoopPolicy if _asyncio_enabled
- else _PortageEventLoopPolicy)
+DefaultEventLoopPolicy = _AsyncioEventLoopPolicy