public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: lib/portage/, lib/portage/util/
@ 2022-12-31 13:33 Sam James
  0 siblings, 0 replies; 2+ messages in thread
From: Sam James @ 2022-12-31 13:33 UTC (permalink / raw
  To: gentoo-commits

commit:     9ef4e24ba6ff64bb1addb3112ebdf3b3e58bdb07
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 30 10:47:55 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 31 13:33:04 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=9ef4e24b

checksum: Consider C implementation of Whirlpool accelerated

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/checksum.py       |  9 ++++++---
 lib/portage/util/whirlpool.py | 13 -------------
 2 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/lib/portage/checksum.py b/lib/portage/checksum.py
index f23897d91..3bdb2bc53 100644
--- a/lib/portage/checksum.py
+++ b/lib/portage/checksum.py
@@ -310,10 +310,13 @@ if "STREEBOG256" not in hashfunc_map or "STREEBOG512" not in hashfunc_map:
 _whirlpool_unaccelerated = False
 if "WHIRLPOOL" not in hashfunc_map:
     # Bundled WHIRLPOOL implementation
-    _whirlpool_unaccelerated = True
-    from portage.util.whirlpool import new as _new_whirlpool
+    from portage.util.whirlpool import CWhirlpool, PyWhirlpool
 
-    _generate_hash_function("WHIRLPOOL", _new_whirlpool, origin="bundled")
+    if CWhirlpool.is_available:
+        _generate_hash_function("WHIRLPOOL", CWhirlpool, origin="bundled-c")
+    else:
+        _whirlpool_unaccelerated = True
+        _generate_hash_function("WHIRLPOOL", PyWhirlpool, origin="bundled-py")
 
 
 # There is only one implementation for size

diff --git a/lib/portage/util/whirlpool.py b/lib/portage/util/whirlpool.py
index 7caa20f6e..8454a874a 100644
--- a/lib/portage/util/whirlpool.py
+++ b/lib/portage/util/whirlpool.py
@@ -110,19 +110,6 @@ class CWhirlpool:
         return tempstr
 
 
-if WhirlpoolExt is not None:
-    Whirlpool = CWhirlpool
-else:
-    Whirlpool = PyWhirlpool
-
-
-def new(init=b""):
-    """Return a new Whirlpool object. An optional string argument
-    may be provided; if present, this string will be automatically
-    hashed."""
-    return Whirlpool(init)
-
-
 #
 # Private.
 #


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/, lib/portage/util/
@ 2023-03-04  2:56 Sam James
  0 siblings, 0 replies; 2+ messages in thread
From: Sam James @ 2023-03-04  2:56 UTC (permalink / raw
  To: gentoo-commits

commit:     e42940471a16159802bc99a542a5624d9d46251e
Author:     Siddhanth Rathod <xsiddhanthrathod <AT> gmail <DOT> com>
AuthorDate: Wed Mar  1 17:55:48 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Mar  4 02:56:34 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=e4294047

portage: news: further type annotations

Signed-off-by: Siddhanth Rathod <xsiddhanthrathod <AT> gmail.com>
Closes: https://github.com/gentoo/portage/pull/1002
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/news.py          | 52 ++++++++++++++++++++++----------------------
 lib/portage/util/__init__.py | 42 +++++++++++++++++------------------
 2 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/lib/portage/news.py b/lib/portage/news.py
index 68f0c72d3..b43d81fb7 100644
--- a/lib/portage/news.py
+++ b/lib/portage/news.py
@@ -15,7 +15,7 @@ __all__ = [
 
 from collections import OrderedDict
 from typing import TYPE_CHECKING, Any, Dict, List, Optional
-
+from typing import Pattern, Match
 import fnmatch
 import logging
 import os as _os
@@ -71,7 +71,7 @@ class NewsManager:
         news_path: str,
         unread_path: str,
         language_id: str = "en",
-    ):
+    ) -> None:
         self.news_path = news_path
         self.unread_path = unread_path
         self.language_id = language_id
@@ -89,11 +89,11 @@ class NewsManager:
         self._dir_mode = 0o0074
         self._mode_mask = 0o0000
 
-        portdir = portdb.repositories.mainRepoLocation()
-        profiles_base = None
+        portdir: Optional[str] = portdb.repositories.mainRepoLocation()
+        profiles_base: Optional[str] = None
         if portdir is not None:
             profiles_base = os.path.join(portdir, ("profiles" + os.path.sep))
-        profile_path = None
+        profile_path: Optional[str] = None
         if profiles_base is not None and portdb.settings.profile_path:
             profile_path = normalize_path(
                 os.path.realpath(portdb.settings.profile_path)
@@ -109,7 +109,7 @@ class NewsManager:
         return os.path.join(self.unread_path, f"news-{repoid}.skip")
 
     def _news_dir(self, repoid: str) -> str:
-        repo_path = self.portdb.getRepositoryPath(repoid)
+        repo_path: Optional[str] = self.portdb.getRepositoryPath(repoid)
         if repo_path is None:
             raise AssertionError(_(f"Invalid repoID: {repoid}"))
         return os.path.join(repo_path, self.news_path)
@@ -137,23 +137,23 @@ class NewsManager:
         if not os.access(self.unread_path, os.W_OK):
             return
 
-        news_dir = self._news_dir(repoid)
+        news_dir: str = self._news_dir(repoid)
         try:
-            news = _os.listdir(
+            news: list[str] = _os.listdir(
                 _unicode_encode(news_dir, encoding=_encodings["fs"], errors="strict")
             )
         except OSError:
             return
 
-        skip_filename = self._skip_filename(repoid)
-        unread_filename = self._unread_filename(repoid)
-        unread_lock = lockfile(unread_filename, wantnewlockfile=1)
+        skip_filename: str = self._skip_filename(repoid)
+        unread_filename: str = self._unread_filename(repoid)
+        unread_lock: Optional[bool] = lockfile(unread_filename, wantnewlockfile=1)
         try:
             try:
-                unread = set(grabfile(unread_filename))
-                unread_orig = unread.copy()
-                skip = set(grabfile(skip_filename))
-                skip_orig = skip.copy()
+                unread: set[str | tuple[str, str]] = set(grabfile(unread_filename))
+                unread_orig: set[str | tuple[str, str]] = unread.copy()
+                skip: set[str | tuple[str, str]] = set(grabfile(skip_filename))
+                skip_orig: set[str | tuple[str, str]] = skip.copy()
             except PermissionDenied:
                 return
 
@@ -224,7 +224,7 @@ class NewsManager:
             self.updateItems(repoid)
 
         unread_filename = self._unread_filename(repoid)
-        unread_lock = None
+        unread_lock: Optional[bool] = None
         try:
             unread_lock = lockfile(unread_filename, wantnewlockfile=1)
         except (
@@ -244,11 +244,11 @@ class NewsManager:
                 unlockfile(unread_lock)
 
 
-_formatRE = re.compile(r"News-Item-Format:\s*([^\s]*)\s*$")
-_installedRE = re.compile("Display-If-Installed:(.*)\n")
-_profileRE = re.compile("Display-If-Profile:(.*)\n")
-_keywordRE = re.compile("Display-If-Keyword:(.*)\n")
-_valid_profile_RE = re.compile(r"^[^*]+(/\*)?$")
+_formatRE: Pattern[str] = re.compile(r"News-Item-Format:\s*([^\s]*)\s*$")
+_installedRE: Pattern[str] = re.compile("Display-If-Installed:(.*)\n")
+_profileRE: Pattern[str] = re.compile("Display-If-Profile:(.*)\n")
+_keywordRE: Pattern[str] = re.compile("Display-If-Keyword:(.*)\n")
+_valid_profile_RE: Pattern[str] = re.compile(r"^[^*]+(/\*)?$")
 
 
 class NewsItem:
@@ -295,9 +295,9 @@ class NewsItem:
         if not len(self.restrictions):
             return True
 
-        kwargs = {"vardb": vardb, "config": config, "profile": profile}
+        kwargs: dict[str, Any] = {"vardb": vardb, "config": config, "profile": profile}
 
-        all_match = True
+        all_match: bool = True
         for values in self.restrictions.values():
             matches = [restriction.checkRestriction(**kwargs) for restriction in values]
             any_match = any(matches)
@@ -324,11 +324,11 @@ class NewsItem:
             lines = f.readlines()
         self.restrictions = {}
         invalids = []
-        news_format = None
+        news_format: Optional[str] = None
 
         # Look for News-Item-Format
         for i, line in enumerate(lines):
-            format_match = _formatRE.match(line)
+            format_match: Optional[Match[str]] = _formatRE.match(line)
             if format_match is not None:
                 news_format = format_match.group(1)
                 if fnmatch.fnmatch(news_format, "[12].*"):
@@ -445,7 +445,7 @@ class DisplayInstalledRestriction(DisplayRestriction):
             return isvalidatom(self.atom, eapi="5")
         return isvalidatom(self.atom)
 
-    def checkRestriction(self, **kwargs) -> bool:
+    def checkRestriction(self, **kwargs) -> Optional[Match[str]]:
         return kwargs["vardb"].match(self.atom)
 
 

diff --git a/lib/portage/util/__init__.py b/lib/portage/util/__init__.py
index 59db742d7..4d50088e7 100644
--- a/lib/portage/util/__init__.py
+++ b/lib/portage/util/__init__.py
@@ -1,6 +1,26 @@
 # Copyright 2004-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+from portage.cache.mappings import UserDict
+from portage.proxy.objectproxy import ObjectProxy
+from portage.localization import _
+from portage.exception import (
+    InvalidAtom,
+    PortageException,
+    FileNotFound,
+    IsADirectory,
+    OperationNotPermitted,
+    ParseError,
+    PermissionDenied,
+    ReadOnlyFileSystem,
+)
+from portage.const import VCS_DIRS
+from portage import _unicode_decode
+from portage import _unicode_encode
+from portage import _os_merge
+from portage import _encodings
+from portage import os
+
 __all__ = [
     "apply_permissions",
     "apply_recursive_permissions",
@@ -61,26 +81,6 @@ portage.proxy.lazyimport.lazyimport(
     "subprocess",
 )
 
-from portage import os
-from portage import _encodings
-from portage import _os_merge
-from portage import _unicode_encode
-from portage import _unicode_decode
-from portage.const import VCS_DIRS
-from portage.exception import (
-    InvalidAtom,
-    PortageException,
-    FileNotFound,
-    IsADirectory,
-    OperationNotPermitted,
-    ParseError,
-    PermissionDenied,
-    ReadOnlyFileSystem,
-)
-from portage.localization import _
-from portage.proxy.objectproxy import ObjectProxy
-from portage.cache.mappings import UserDict
-
 
 noiselimit = 0
 
@@ -142,7 +142,7 @@ def writemsg_level(msg, level=0, noiselevel=0):
     writemsg(msg, noiselevel=noiselevel, fd=fd)
 
 
-def normalize_path(mypath):
+def normalize_path(mypath) -> str:
     """
     os.path.normpath("//foo") returns "//foo" instead of "/foo"
     We dislike this behavior so we create our own normpath func


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-04  2:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-04  2:56 [gentoo-commits] proj/portage:master commit in: lib/portage/, lib/portage/util/ Sam James
  -- strict thread matches above, loose matches on Subject: below --
2022-12-31 13:33 Sam James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox