From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/
Date: Mon, 27 Feb 2023 06:15:46 +0000 (UTC) [thread overview]
Message-ID: <1677478540.fb4ba0ef70095bd6f17e198674e16d60284ab2dc.sam@gentoo> (raw)
commit: fb4ba0ef70095bd6f17e198674e16d60284ab2dc
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 27 05:10:23 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Feb 27 06:15:40 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fb4ba0ef
portage: news: trivial type annotations
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/news.py | 59 +++++++++++++++++++++++++++++++++++++----------------
1 file changed, 41 insertions(+), 18 deletions(-)
diff --git a/lib/portage/news.py b/lib/portage/news.py
index f81debe97..68f0c72d3 100644
--- a/lib/portage/news.py
+++ b/lib/portage/news.py
@@ -14,11 +14,17 @@ __all__ = [
]
from collections import OrderedDict
+from typing import TYPE_CHECKING, Any, Dict, List, Optional
import fnmatch
import logging
import os as _os
import re
+
+if TYPE_CHECKING:
+ import portage.dbapi.vartree
+ import portage.package.ebuild.config
+
from portage import os
from portage import _encodings
from portage import _unicode_decode
@@ -58,7 +64,14 @@ class NewsManager:
"""
- def __init__(self, portdb, vardb, news_path, unread_path, language_id="en"):
+ def __init__(
+ self,
+ portdb: "portage.dbapi.porttree.portdbapi",
+ vardb: "portage.dbapi.vartree.vardbapi",
+ news_path: str,
+ unread_path: str,
+ language_id: str = "en",
+ ):
self.news_path = news_path
self.unread_path = unread_path
self.language_id = language_id
@@ -89,19 +102,19 @@ class NewsManager:
profile_path = profile_path[len(profiles_base) :]
self._profile_path = profile_path
- def _unread_filename(self, repoid):
+ def _unread_filename(self, repoid: str) -> str:
return os.path.join(self.unread_path, f"news-{repoid}.unread")
- def _skip_filename(self, repoid):
+ def _skip_filename(self, repoid: str) -> str:
return os.path.join(self.unread_path, f"news-{repoid}.skip")
- def _news_dir(self, repoid):
+ def _news_dir(self, repoid: str) -> str:
repo_path = self.portdb.getRepositoryPath(repoid)
if repo_path is None:
raise AssertionError(_(f"Invalid repoID: {repoid}"))
return os.path.join(repo_path, self.news_path)
- def updateItems(self, repoid):
+ def updateItems(self, repoid: str) -> None:
"""
Figure out which news items from NEWS_PATH are both unread and relevant to
the user (according to the GLEP 42 standards of relevancy). Then add these
@@ -199,7 +212,7 @@ class NewsManager:
finally:
unlockfile(unread_lock)
- def getUnreadItems(self, repoid, update=False):
+ def getUnreadItems(self, repoid: str, update: bool = False) -> int:
"""
Determine if there are unread relevant items in news.repoid.unread.
If there are unread items return their number.
@@ -249,7 +262,7 @@ class NewsItem:
Creation of a news item involves passing in the path to the particular news item.
"""
- def __init__(self, path, name):
+ def __init__(self, path: str, name: str):
"""
For a given news item we only want if it path is a file.
"""
@@ -258,7 +271,12 @@ class NewsItem:
self._parsed = False
self._valid = True
- def isRelevant(self, vardb, config, profile):
+ def isRelevant(
+ self,
+ vardb: "portage.dbapi.vartree.vardbapi",
+ config: "portage.package.ebuild.config.config",
+ profile: Optional[str],
+ ) -> bool:
"""
This function takes a dict of keyword arguments; one should pass in any
objects need to do to lookups (like what keywords we are on, what profile,
@@ -292,12 +310,12 @@ class NewsItem:
return all_match
- def isValid(self):
+ def isValid(self) -> bool:
if not self._parsed:
self.parse()
return self._valid
- def parse(self):
+ def parse(self) -> None:
with open(
_unicode_encode(self.path, encoding=_encodings["fs"], errors="strict"),
encoding=_encodings["content"],
@@ -365,7 +383,7 @@ class DisplayRestriction:
are met, then it is displayed
"""
- def isValid(self):
+ def isValid(self) -> bool:
return True
def checkRestriction(self, **kwargs):
@@ -382,7 +400,7 @@ class DisplayProfileRestriction(DisplayRestriction):
self.profile = profile
self.format = news_format
- def isValid(self):
+ def isValid(self) -> bool:
return (
not fnmatch.fnmatch(self.format, "1.*")
or "*" not in self.profile
@@ -390,7 +408,7 @@ class DisplayProfileRestriction(DisplayRestriction):
or _valid_profile_RE.match(self.profile)
)
- def checkRestriction(self, **kwargs):
+ def checkRestriction(self, **kwargs) -> bool:
if fnmatch.fnmatch(self.format, "2.*") and self.profile.endswith("/*"):
return kwargs["profile"].startswith(self.profile[:-1])
return kwargs["profile"] == self.profile
@@ -406,7 +424,7 @@ class DisplayKeywordRestriction(DisplayRestriction):
self.keyword = keyword
self.format = news_format
- def checkRestriction(self, **kwargs):
+ def checkRestriction(self, **kwargs) -> bool:
return kwargs["config"].get("ARCH", "") == self.keyword
@@ -420,18 +438,23 @@ class DisplayInstalledRestriction(DisplayRestriction):
self.atom = atom
self.format = news_format
- def isValid(self):
+ def isValid(self) -> bool:
if fnmatch.fnmatch(self.format, "1.*"):
return isvalidatom(self.atom, eapi="0")
if fnmatch.fnmatch(self.format, "2.*"):
return isvalidatom(self.atom, eapi="5")
return isvalidatom(self.atom)
- def checkRestriction(self, **kwargs):
+ def checkRestriction(self, **kwargs) -> bool:
return kwargs["vardb"].match(self.atom)
-def count_unread_news(portdb, vardb, repos=None, update=True):
+def count_unread_news(
+ portdb: "portage.dbapi.porttree.portdbapi",
+ vardb: "portage.dbapi.vartree.vardbapi",
+ repos: Optional[List[Any]] = None,
+ update: bool = True,
+) -> Dict[str, int]:
"""
Returns a dictionary mapping repos to integer counts of unread news items.
By default, this will scan all repos and check for new items that have
@@ -477,7 +500,7 @@ def count_unread_news(portdb, vardb, repos=None, update=True):
return news_counts
-def display_news_notifications(news_counts: dict):
+def display_news_notifications(news_counts: Dict[Any, int]) -> None:
"""
Display a notification for unread news items, using a dictionary mapping
repos to integer counts, like that returned from count_unread_news().
next reply other threads:[~2023-02-27 6:15 UTC|newest]
Thread overview: 148+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-27 6:15 Sam James [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-01-21 21:14 [gentoo-commits] proj/portage:master commit in: lib/portage/ Sam James
2025-01-11 16:01 Mike Gilbert
2025-01-11 16:01 Mike Gilbert
2025-01-01 0:33 Zac Medico
2024-11-02 22:12 Zac Medico
2024-11-02 15:48 Zac Medico
2024-11-02 15:48 Zac Medico
2024-09-09 18:08 Ulrich Müller
2024-09-09 18:08 Ulrich Müller
2024-08-14 15:22 Zac Medico
2024-06-09 17:54 Zac Medico
2024-06-02 18:28 Zac Medico
2024-04-26 22:06 Sam James
2024-04-26 22:06 Sam James
2024-02-28 16:01 Sam James
2024-02-28 15:52 Sam James
2024-02-28 15:49 Sam James
2024-02-25 8:25 Sam James
2024-02-24 20:10 Zac Medico
2024-02-21 2:08 Sam James
2024-02-21 2:08 Sam James
2024-02-12 7:58 Zac Medico
2024-02-11 19:57 Zac Medico
2024-02-10 6:09 Zac Medico
2024-02-10 6:06 Zac Medico
2024-02-09 8:51 Sam James
2024-02-09 7:08 Sam James
2024-02-07 2:35 Zac Medico
2024-02-07 2:35 Zac Medico
2024-02-05 1:03 Zac Medico
2024-02-05 1:03 Zac Medico
2024-01-29 17:49 Zac Medico
2024-01-29 16:09 Zac Medico
2023-12-26 23:15 Zac Medico
2023-11-02 14:58 Zac Medico
2023-10-24 21:26 Zac Medico
2023-10-24 1:48 Zac Medico
2023-10-03 15:07 Zac Medico
2023-10-02 2:10 Zac Medico
2023-09-26 5:53 Zac Medico
2023-09-08 20:36 Sam James
2023-09-08 19:49 Sam James
2023-08-24 18:23 Mike Gilbert
2023-08-02 6:31 Sam James
2023-07-29 3:57 Sam James
2023-06-29 8:22 Sam James
2023-03-21 2:30 Sam James
2023-03-21 2:30 Sam James
2023-03-21 2:30 Sam James
2023-03-21 2:30 Sam James
2023-03-21 2:30 Sam James
2023-03-21 2:30 Sam James
2023-02-17 1:23 Sam James
2023-01-02 5:25 Sam James
2022-11-02 22:58 Sam James
2022-11-02 22:58 Sam James
2022-09-29 21:37 Sam James
2022-09-29 20:45 Sam James
2022-09-28 23:56 Sam James
2022-09-26 17:52 Zac Medico
2022-09-20 19:45 Sam James
2022-09-20 3:39 Sam James
2022-09-18 18:30 Mike Gilbert
2022-08-01 22:39 Sam James
2022-08-01 17:34 Mike Gilbert
2022-07-19 21:39 Sam James
2022-07-18 18:47 Sam James
2022-07-11 23:02 Sam James
2022-07-10 15:07 Mike Gilbert
2022-07-05 22:56 Sam James
2022-06-05 20:25 Zac Medico
2022-04-11 12:11 Mike Gilbert
2022-04-11 12:11 Mike Gilbert
2022-04-09 4:32 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-01 20:30 Matt Turner
2022-03-30 23:11 Sam James
2022-03-28 1:10 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-15 2:52 Matt Turner
2022-02-09 11:13 Sam James
2021-09-20 20:06 Zac Medico
2021-09-20 19:55 Mike Gilbert
2021-09-07 7:04 Michał Górny
2021-09-04 11:53 Michał Górny
2021-05-24 6:08 Zac Medico
2021-05-24 4:55 Zac Medico
2021-03-28 3:33 Zac Medico
2021-03-11 12:32 Zac Medico
2021-03-07 14:03 Zac Medico
2021-03-06 9:18 Zac Medico
2021-03-06 9:05 Zac Medico
2021-03-06 9:05 Zac Medico
2021-03-06 8:20 Zac Medico
2021-03-06 6:16 Zac Medico
2021-02-08 4:55 Zac Medico
2020-09-11 19:02 Zac Medico
2020-08-04 1:39 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-06-27 19:46 Zac Medico
2020-06-09 0:58 Zac Medico
2020-05-17 9:37 Michał Górny
2020-05-07 20:35 Zac Medico
2020-04-20 21:16 Mike Gilbert
2020-03-28 18:57 Michał Górny
2020-03-25 19:18 Zac Medico
2020-03-25 7:57 Zac Medico
2020-03-25 7:57 Zac Medico
2020-02-04 6:43 Zac Medico
2020-02-02 9:00 Zac Medico
2019-12-15 23:04 Zac Medico
2019-11-12 22:25 Zac Medico
2019-09-17 2:59 Zac Medico
2019-09-07 6:40 Zac Medico
2019-08-18 22:15 Zac Medico
2019-08-04 18:03 Zac Medico
2019-08-02 20:03 Mike Gilbert
2019-08-01 19:02 Mike Gilbert
2019-05-28 1:49 Zac Medico
2019-04-27 19:20 Zac Medico
2019-02-20 0:58 Zac Medico
2019-02-20 0:58 Zac Medico
2019-02-20 0:58 Zac Medico
2019-02-18 1:01 Zac Medico
2019-02-11 19:46 Zac Medico
2019-01-04 3:49 Zac Medico
2018-12-31 5:27 Zac Medico
2018-12-04 1:35 Zac Medico
2018-11-25 0:03 Zac Medico
2018-11-24 21:34 Zac Medico
2018-08-07 18:36 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1677478540.fb4ba0ef70095bd6f17e198674e16d60284ab2dc.sam@gentoo \
--to=sam@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox