[gentoo-portage-dev] [PATCH] Mark EAPIs "4-python" and "5-progress" as deprecated

2021-03-04 Thread Matt Turner
Signed-off-by: Matt Turner 
---
I've asked Arfrever multiple times if these are still used anywhere, and
he seemingly has not responded intentionally.

According to https://bugs.gentoo.org/174536#c27 these EAPIs were only
used in Arfrever's personal overlay, and even in 2012 there were
questions about why they were supported in portage.

The "Progress Overlay" does contain ebuilds using these EAPIs but it has
not been updated since 2018 and doesn't look like it is useful at this
point.

 lib/portage/__init__.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
index 24c9d8b89..184db6ae2 100644
--- a/lib/portage/__init__.py
+++ b/lib/portage/__init__.py
@@ -465,16 +465,16 @@ def abssymlink(symlink, target=None):
 _doebuild_manifest_exempt_depend = 0
 
 _testing_eapis = frozenset([
-   "4-python",
-   "5-progress",
 ])
 _deprecated_eapis = frozenset([
+   "3_pre1",
+   "3_pre2",
"4_pre1",
+   "4-python",
"4-slot-abi",
-   "3_pre2",
-   "3_pre1",
"5_pre1",
"5_pre2",
+   "5-progress",
"6_pre1",
"7_pre1",
 ])
-- 
2.26.2




[gentoo-portage-dev] [PATCH] Use asyncio.subprocess.Process directly

2021-03-04 Thread Matt Turner
With no need to support Python 2, we can remove our private
implementation.

Signed-off-by: Matt Turner 
---
I don't know how to test this. I intentionally broke the return value of
create_subprocess_exec and didn't see any bad results.

 lib/portage/util/futures/_asyncio/__init__.py |   8 +-
 lib/portage/util/futures/_asyncio/process.py  | 116 --
 2 files changed, 4 insertions(+), 120 deletions(-)
 delete mode 100644 lib/portage/util/futures/_asyncio/process.py

diff --git a/lib/portage/util/futures/_asyncio/__init__.py 
b/lib/portage/util/futures/_asyncio/__init__.py
index 5590963f1..207e7205d 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -25,6 +25,7 @@ import types
 import weakref
 
 import asyncio as _real_asyncio
+from asyncio.subprocess import Process
 
 try:
import threading
@@ -45,7 +46,6 @@ from portage.util.futures.futures import (
TimeoutError,
 )
 # pylint: enable=redefined-builtin
-from portage.util.futures._asyncio.process import _Process
 from portage.util.futures._asyncio.tasks import (
ALL_COMPLETED,
FIRST_COMPLETED,
@@ -124,8 +124,8 @@ def create_subprocess_exec(*args, **kwargs):
@type loop: event loop
@type kwargs: varies
@param kwargs: subprocess.Popen parameters
-   @rtype: asyncio.Future (or compatible)
-   @return: subset of asyncio.subprocess.Process interface
+   @rtype: asyncio.subprocess.Process (or compatible)
+   @return: asyncio.subprocess.Process interface
"""
loop = _wrap_loop(kwargs.pop('loop', None))
# Python 3.4 and later implement PEP 446, which makes newly
@@ -138,7 +138,7 @@ def create_subprocess_exec(*args, **kwargs):
 
result = loop.create_future()
 
-   result.set_result(_Process(subprocess.Popen(
+   result.set_result(Process(subprocess.Popen(
args,
stdin=kwargs.pop('stdin', None),
stdout=kwargs.pop('stdout', None),
diff --git a/lib/portage/util/futures/_asyncio/process.py 
b/lib/portage/util/futures/_asyncio/process.py
deleted file mode 100644
index 275c9031a..0
--- a/lib/portage/util/futures/_asyncio/process.py
+++ /dev/null
@@ -1,116 +0,0 @@
-# Copyright 2018-2020 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-import os
-
-import portage
-portage.proxy.lazyimport.lazyimport(globals(),
-   'portage.util.futures:asyncio',
-   'portage.util.futures.unix_events:_set_nonblocking',
-)
-from portage.util.futures._asyncio.streams import _reader, _writer
-from portage.util.futures.compat_coroutine import coroutine, coroutine_return
-
-
-class _Process:
-   """
-   Emulate a subset of the asyncio.subprocess.Process interface,
-   for python2.
-   """
-   def __init__(self, proc, loop):
-   """
-   @param proc: process instance
-   @type proc: subprocess.Popen
-   @param loop: asyncio.AbstractEventLoop (or compatible)
-   @type loop: event loop
-   """
-   self._proc = proc
-   self._loop = loop
-   self.terminate = proc.terminate
-   self.kill = proc.kill
-   self.send_signal = proc.send_signal
-   self.pid = proc.pid
-   self._waiters = []
-   loop._asyncio_child_watcher.\
-   add_child_handler(self.pid, self._proc_exit)
-
-   @property
-   def returncode(self):
-   return self._proc.returncode
-
-   @coroutine
-   def communicate(self, input=None, loop=None): # pylint: 
disable=redefined-builtin
-   """
-   Read data from stdout and stderr, until end-of-file is reached.
-   Wait for process to terminate.
-
-   @param input: stdin content to write
-   @type input: bytes
-   @return: tuple (stdout_data, stderr_data)
-   @rtype: asyncio.Future (or compatible)
-   """
-   loop = asyncio._wrap_loop(loop or self._loop)
-   futures = []
-   for input_file in (self._proc.stdout, self._proc.stderr):
-   if input_file is None:
-   future = loop.create_future()
-   future.set_result(None)
-   else:
-   future = _reader(input_file, loop=loop)
-   futures.append(future)
-
-   writer = None
-   if input is not None:
-   if self._proc.stdin is None:
-   raise TypeError('communicate: expected file or 
int, got {}'.format(type(self._proc.stdin)))
-   stdin = self._proc.stdin
-   stdin = os.fdopen(stdin, 'wb', 0) if isinstance(stdin, 
int) else stdin
-   

[gentoo-portage-dev] [PATCH 3/3] lib: Remove outdated Python 2 comments

2021-03-04 Thread Matt Turner
Fixes: 788c0e8bb ("Remove from __future__ import unicode_literals")
Signed-off-by: Matt Turner 
---
 bin/egencache   | 2 --
 lib/_emerge/Package.py  | 9 -
 lib/_emerge/Scheduler.py| 2 --
 lib/_emerge/UseFlagDisplay.py   | 2 --
 lib/_emerge/resolver/output.py  | 2 --
 lib/portage/cache/flat_hash.py  | 3 ---
 lib/portage/tests/unicode/test_string_format.py | 9 -
 lib/portage/util/digraph.py | 3 ---
 8 files changed, 32 deletions(-)

diff --git a/bin/egencache b/bin/egencache
index 9b6df2e7d..fc18b892f 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -2,8 +2,6 @@
 # Copyright 2009-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
-# unicode_literals for compat with TextIOWrapper in Python 2
-
 import argparse
 import platform
 import signal
diff --git a/lib/_emerge/Package.py b/lib/_emerge/Package.py
index 995af6311..0ee25b90a 100644
--- a/lib/_emerge/Package.py
+++ b/lib/_emerge/Package.py
@@ -453,15 +453,6 @@ class Package(Task):
else:
qacat = k + ".syntax"
 
-   # For unicode safety with python-2.x we need to avoid
-   # using the string format operator with a non-unicode
-   # format string, since that will result in the
-   # PortageException.__str__() method being invoked,
-   # followed by unsafe decoding that may result in a
-   # UnicodeDecodeError. Therefore, use unicode_literals
-   # to ensure that format strings are unicode, so that
-   # PortageException.__unicode__() is used when necessary
-   # in python-2.x.
if not self.installed:
categorized_error = False
if e.errors:
diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py
index 465f928a0..0ed2ee530 100644
--- a/lib/_emerge/Scheduler.py
+++ b/lib/_emerge/Scheduler.py
@@ -1188,8 +1188,6 @@ class Scheduler(PollScheduler):
printer.eerror(line)
printer.eerror("")
for failed_pkg in self._failed_pkgs_all:
-   # Use unicode_literals to force unicode format 
string so
-   # that Package.__unicode__() is called in 
python2.
msg = " %s" % (failed_pkg.pkg,)
if failed_pkg.postinst_failure:
msg += " (postinst failed)"
diff --git a/lib/_emerge/UseFlagDisplay.py b/lib/_emerge/UseFlagDisplay.py
index 5e3ba400d..fffc8144a 100644
--- a/lib/_emerge/UseFlagDisplay.py
+++ b/lib/_emerge/UseFlagDisplay.py
@@ -111,8 +111,6 @@ def pkg_use_display(pkg, opts, modified_use=None):
flags.sort(key=UseFlagDisplay.sort_combined)
else:
flags.sort(key=UseFlagDisplay.sort_separated)
-   # Use unicode_literals to force unicode format string so
-   # that UseFlagDisplay.__unicode__() is called in python2.
flag_displays.append('%s="%s"' % (varname,
' '.join("%s" % (f,) for f in flags)))
 
diff --git a/lib/_emerge/resolver/output.py b/lib/_emerge/resolver/output.py
index 0c90abefb..dea8a4be8 100644
--- a/lib/_emerge/resolver/output.py
+++ b/lib/_emerge/resolver/output.py
@@ -554,8 +554,6 @@ class Display:
"""
writemsg_stdout('\n%s\n' % (self.counters,), noiselevel=-1)
if show_repos:
-   # Use unicode_literals to force unicode format string so
-   # that RepoDisplay.__unicode__() is called in python2.
writemsg_stdout("%s" % (self.conf.repo_display,),
noiselevel=-1)
 
diff --git a/lib/portage/cache/flat_hash.py b/lib/portage/cache/flat_hash.py
index 7d48bae81..25930f0a4 100644
--- a/lib/portage/cache/flat_hash.py
+++ b/lib/portage/cache/flat_hash.py
@@ -73,9 +73,6 @@ class database(fs_template.FsBased):
v = values.get(k)
if not v:
continue
-   # NOTE: This format string requires 
unicode_literals, so that
-   # k and v are coerced to unicode, in order to 
prevent TypeError
-   # when writing raw bytes to TextIOWrapper with 
Python 2.
myf.write("%s=%s\n" % (k, v))
 
self._ensure_access(fp)
diff --git a/lib/portage/tests/unicode/test_string_format.py 
b/lib/portage/tests/unicode/test_string_format.py
index 3b994d622..54ac038a6 100644
--- a/lib/portage/tests/unicode/test_string_format.py
+++ 

[gentoo-portage-dev] [PATCH 2/3] Remove outdated mention of Python 2 from comment

2021-03-04 Thread Matt Turner
Fixes: 5e9fe0f2a ("Eliminate basestring/long/_unicode py3 compat")
Signed-off-by: Matt Turner 
---
 lib/portage/versions.py | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/portage/versions.py b/lib/portage/versions.py
index 317683b17..1dc942124 100644
--- a/lib/portage/versions.py
+++ b/lib/portage/versions.py
@@ -341,11 +341,11 @@ def catpkgsplit(mydata, silent=1, eapi=None):
 
 class _pkg_str(str):
"""
-   This class represents a cpv. It inherits from str (unicode in python2) 
and
-   has attributes that cache results for use by functions like catpkgsplit 
and
-   cpv_getkey which are called frequently (especially in match_from_list).
-   Instances are typically created in dbapi.cp_list() or the Atom 
contructor,
-   and propagate from there. Generally, code that pickles these objects 
will
+   This class represents a cpv. It inherits from str and has attributes
+   that cache results for use by functions like catpkgsplit and cpv_getkey
+   which are called frequently (especially in match_from_list).  Instances
+   are typically created in dbapi.cp_list() or the Atom contructor, and
+   propagate from there. Generally, code that pickles these objects will
manually convert them to a plain unicode object first.
 
Instances of this class will have missing attributes for metadata that
-- 
2.26.2




[gentoo-portage-dev] [PATCH 1/3] Remove Python 2 workaround

2021-03-04 Thread Matt Turner
Signed-off-by: Matt Turner 
---
 lib/portage/__init__.py | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
index 184db6ae2..1d202f557 100644
--- a/lib/portage/__init__.py
+++ b/lib/portage/__init__.py
@@ -484,11 +484,7 @@ def _eapi_is_deprecated(eapi):
return eapi in _deprecated_eapis
 
 def eapi_is_supported(eapi):
-   if not isinstance(eapi, str):
-   # Only call str() when necessary since with python2 it
-   # can trigger UnicodeEncodeError if EAPI is corrupt.
-   eapi = str(eapi)
-   eapi = eapi.strip()
+   eapi = str(eapi).strip()
 
return eapi in _supported_eapis
 
-- 
2.26.2