From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/
Date: Sat, 29 Jul 2023 03:57:50 +0000 (UTC) [thread overview]
Message-ID: <1690603065.7c0086fc0ab60cf0a726e3c88b11a21e147f3aa2.sam@gentoo> (raw)
commit: 7c0086fc0ab60cf0a726e3c88b11a21e147f3aa2
Author: Andrew Udvare <audvare <AT> gmail <DOT> com>
AuthorDate: Sun Jul 16 21:42:58 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jul 29 03:57:45 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7c0086fc
dbapi: add some typing
Signed-off-by: Andrew Udvare <audvare <AT> gmail.com>
Closes: https://github.com/gentoo/portage/pull/1069
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/dbapi/__init__.py | 27 +++++++++++++++------------
lib/portage/dbapi/porttree.py | 34 ++++++++++++++++++++++++----------
2 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/lib/portage/dbapi/__init__.py b/lib/portage/dbapi/__init__.py
index 31453d149..428e4a48e 100644
--- a/lib/portage/dbapi/__init__.py
+++ b/lib/portage/dbapi/__init__.py
@@ -5,6 +5,7 @@ __all__ = ["dbapi"]
import re
import warnings
+from typing import Any, Dict, List, Optional, Sequence, Tuple
import portage
@@ -29,7 +30,7 @@ from _emerge.Package import Package
class dbapi:
_category_re = re.compile(r"^\w[-.+\w]*$", re.UNICODE)
- _categories = None
+ _categories: Optional[Tuple[str, ...]] = None
_use_mutable = False
_known_keys = frozenset(auxdbkeys)
_pkg_str_aux_keys = ("EAPI", "KEYWORDS", "SLOT", "repository")
@@ -38,7 +39,7 @@ class dbapi:
pass
@property
- def categories(self):
+ def categories(self) -> Tuple[str, ...]:
"""
Use self.cp_all() to generate a category list. Mutable instances
can delete the self._categories attribute in cases when the cached
@@ -52,11 +53,11 @@ class dbapi:
def close_caches(self):
pass
- def cp_list(self, cp, use_cache=1):
+ def cp_list(self, cp: str, use_cache: int = 1) -> Any:
raise NotImplementedError(self)
@staticmethod
- def _cmp_cpv(cpv1, cpv2):
+ def _cmp_cpv(cpv1, cpv2) -> int:
result = vercmp(cpv1.version, cpv2.version)
if result == 0 and cpv1.build_time is not None and cpv2.build_time is not None:
result = (cpv1.build_time > cpv2.build_time) - (
@@ -65,7 +66,7 @@ class dbapi:
return result
@staticmethod
- def _cpv_sort_ascending(cpv_list):
+ def _cpv_sort_ascending(cpv_list: Sequence[Any]) -> None:
"""
Use this to sort self.cp_list() results in ascending
order. It sorts in place and returns None.
@@ -76,7 +77,7 @@ class dbapi:
# dict to map strings back to their original values.
cpv_list.sort(key=cmp_sort_key(dbapi._cmp_cpv))
- def cpv_all(self):
+ def cpv_all(self) -> List[str]:
"""Return all CPVs in the db
Args:
None
@@ -93,16 +94,18 @@ class dbapi:
cpv_list.extend(self.cp_list(cp))
return cpv_list
- def cp_all(self, sort=False):
+ def cp_all(self, sort: bool = False) -> List[str]:
"""Implement this in a child class
Args
sort - return sorted results
Returns:
A list of strings 1 per CP in the datastore
"""
- return NotImplementedError
+ raise NotImplementedError
- def aux_get(self, mycpv, mylist, myrepo=None):
+ def aux_get(
+ self, mycpv: str, mylist: str, myrepo: Optional[str] = None
+ ) -> List[str]:
"""Return the metadata keys in mylist for mycpv
Args:
mycpv - "sys-apps/foo-1.0"
@@ -114,7 +117,7 @@ class dbapi:
"""
raise NotImplementedError
- def aux_update(self, cpv, metadata_updates):
+ def aux_update(self, cpv: str, metadata_updates: Dict[str, Any]) -> None:
"""
Args:
cpv - "sys-apps/foo-1.0"
@@ -124,7 +127,7 @@ class dbapi:
"""
raise NotImplementedError
- def match(self, origdep, use_cache=1):
+ def match(self, origdep: str, use_cache: int = 1):
"""Given a dependency, try to find packages that match
Args:
origdep - Depend atom
@@ -138,7 +141,7 @@ class dbapi:
self._iter_match(mydep, self.cp_list(mydep.cp, use_cache=use_cache))
)
- def _iter_match(self, atom, cpv_iter):
+ def _iter_match(self, atom: str, cpv_iter):
cpv_iter = iter(match_from_list(atom, cpv_iter))
if atom.repo:
cpv_iter = self._iter_match_repo(atom, cpv_iter)
diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
index 3c38e99d4..c47b66bda 100644
--- a/lib/portage/dbapi/porttree.py
+++ b/lib/portage/dbapi/porttree.py
@@ -49,6 +49,7 @@ import functools
import collections
from collections import OrderedDict
+from typing import List, Optional, Sequence, Type, Tuple, Union
from urllib.parse import urlparse
@@ -435,7 +436,9 @@ class portdbapi(dbapi):
return license_path
return None
- def findname(self, mycpv, mytree=None, myrepo=None):
+ def findname(
+ self, mycpv: str, mytree: Optional[str] = None, myrepo: Optional[str] = None
+ ) -> str:
return self.findname2(mycpv, mytree, myrepo)[0]
def getRepositoryPath(self, repository_id):
@@ -494,7 +497,12 @@ class portdbapi(dbapi):
"""
return self.settings.repositories.ignored_repos
- def findname2(self, mycpv, mytree=None, myrepo=None):
+ def findname2(
+ self,
+ mycpv: str,
+ mytree: Optional[str] = None,
+ myrepo: Optional[str] = None,
+ ) -> Union[Tuple[None, int], Tuple[str, str], Tuple[str, None]]:
"""
Returns the location of the CPV, and what overlay it was in.
Searches overlays first, then PORTDIR; this allows us to return the first
@@ -643,7 +651,13 @@ class portdbapi(dbapi):
return (metadata, ebuild_hash)
- def aux_get(self, mycpv, mylist, mytree=None, myrepo=None):
+ def aux_get(
+ self,
+ mycpv: str,
+ mylist: Sequence[str],
+ mytree: Optional[str] = None,
+ myrepo: Optional[str] = None,
+ ) -> List[str]:
"stub code for returning auxilliary db information, such as SLOT, DEPEND, etc."
'input: "sys-apps/foo-1.0",["SLOT","DEPEND","HOMEPAGE"]'
'return: ["0",">=sys-libs/bar-1.0","http://www.foo.com"] or raise PortageKeyError if error'
@@ -1200,12 +1214,12 @@ class portdbapi(dbapi):
def xmatch(
self,
- level,
- origdep,
- mydep=DeprecationWarning,
- mykey=DeprecationWarning,
- mylist=DeprecationWarning,
- ):
+ level: str,
+ origdep: str,
+ mydep: Type[DeprecationWarning] = DeprecationWarning,
+ mykey: Type[DeprecationWarning] = DeprecationWarning,
+ mylist: Type[DeprecationWarning] = DeprecationWarning,
+ ) -> Union[Sequence[str], str]:
"""
Caching match function.
@@ -1381,7 +1395,7 @@ class portdbapi(dbapi):
return myval
- def match(self, mydep, use_cache=1):
+ def match(self, mydep: str, use_cache: int = 1) -> Union[Sequence[str], str]:
return self.xmatch("match-visible", mydep)
def gvisible(self, mylist):
next reply other threads:[~2023-07-29 3:57 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-29 3:57 Sam James [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-06-01 19:20 [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/ Zac Medico
2024-05-27 18:13 Zac Medico
2024-03-02 22:55 Zac Medico
2024-02-25 8:25 Sam James
2024-01-16 7:52 Sam James
2024-01-16 5:26 Zac Medico
2024-01-16 5:16 Sam James
2024-01-16 5:16 Sam James
2024-01-03 5:57 Zac Medico
2023-12-10 1:28 Zac Medico
2023-10-24 18:37 Zac Medico
2023-10-23 14:28 Zac Medico
2023-10-22 21:30 Zac Medico
2023-10-22 20:58 Zac Medico
2023-10-22 15:53 Zac Medico
2023-10-20 0:34 Zac Medico
2023-10-15 22:02 Zac Medico
2023-10-08 19:48 Zac Medico
2023-10-05 5:45 Zac Medico
2023-10-04 4:29 Zac Medico
2023-09-26 21:09 Sam James
2023-09-23 22:49 Sam James
2023-09-23 22:38 Sam James
2023-09-23 22:31 Sam James
2023-09-20 18:02 Mike Gilbert
2023-09-15 4:28 Sam James
2023-05-23 0:26 Sam James
2023-05-23 0:26 Sam James
2023-05-23 0:26 Sam James
2022-12-21 1:30 Sam James
2022-12-21 1:28 Sam James
2022-11-08 23:07 Sam James
2022-09-25 19:12 Mike Gilbert
2022-09-09 10:16 Michał Górny
2022-08-18 19:00 Mike Gilbert
2022-04-20 20:24 Zac Medico
2022-04-13 15:34 Sam James
2022-04-13 15:34 Sam James
2021-11-26 21:09 Mike Gilbert
2021-09-21 5:51 Zac Medico
2021-09-21 5:51 Zac Medico
2021-09-21 5:51 Zac Medico
2021-06-05 18:08 Zac Medico
2021-03-07 11:42 Zac Medico
2021-02-23 21:31 Zac Medico
2021-01-18 9:20 Zac Medico
2021-01-17 13:31 Zac Medico
2021-01-17 8:49 Zac Medico
2021-01-17 8:49 Zac Medico
2020-09-08 2:52 Zac Medico
2020-08-09 0:15 Zac Medico
2020-08-04 3:16 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 19:30 Zac Medico
2020-07-22 20:14 Zac Medico
2020-07-22 19:52 Zac Medico
2020-07-22 17:46 Zac Medico
2020-06-07 3:26 Zac Medico
2020-02-20 9:55 Zac Medico
2020-02-03 3:04 Zac Medico
2019-08-24 3:15 Zac Medico
2019-06-20 19:43 Zac Medico
2019-05-11 21:16 Zac Medico
2019-01-20 6:55 Zac Medico
2019-01-11 10:14 Fabian Groffen
2018-09-24 7:30 Zac Medico
2018-09-24 0:46 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=1690603065.7c0086fc0ab60cf0a726e3c88b11a21e147f3aa2.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