-
Notifications
You must be signed in to change notification settings - Fork 280
portage.porttree: pass basic mypy checks #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
159e825
b84232a
b816158
6e5401b
ddb68ce
d911212
cf900ed
a8c778e
1ad6027
4cb842c
27c01b0
2678843
be03e43
469dfd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,7 @@ | ||||||
| # Copyright 1998-2024 Gentoo Authors | ||||||
| # Distributed under the terms of the GNU General Public License v2 | ||||||
| from __future__ import annotations | ||||||
|
|
||||||
|
|
||||||
| __all__ = ["close_portdbapi_caches", "FetchlistDict", "portagetree", "portdbapi"] | ||||||
|
|
||||||
|
|
@@ -52,10 +54,23 @@ | |||||
|
|
||||||
| import collections | ||||||
| from collections import OrderedDict | ||||||
| from collections.abc import Sequence | ||||||
| from typing import Optional, Union | ||||||
| from collections.abc import Iterable, Sequence | ||||||
| from typing import TYPE_CHECKING, Any, Literal, Optional, Union | ||||||
| from urllib.parse import urlparse | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from portage.dbapi import _AuxKeys | ||||||
| from portage.dep import _match_slot, Atom, match_from_list, use_reduce | ||||||
| from portage.package.ebuild.config import config as config_type | ||||||
| from portage.package.ebuild.fetch import _download_suffix | ||||||
| from portage.util import ensure_dirs, writemsg | ||||||
| from portage.util.listdir import listdir | ||||||
| from portage.versions import _pkg_str, catpkgsplit, catsplit, pkgsplit, ver_regexp | ||||||
| import portage.data | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, sorry, this is terrible for maintenance.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I do not see a way we can have full typing within Portage at this time. We basically have to only do simple typing and get the benefits of that but nothing more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is precedence for it: Line 24 in 6a2bd85
portage/lib/portage/dep/__init__.py Line 62 in 6a2bd85
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now reduced to only names used in type-hinting and not to fill in missing globals that are lazy-loaded.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No need to cite cases where, unlike what I called out, it is solely annotations. It does not make your point. |
||||||
|
|
||||||
| portage_gid: int | ||||||
| secpass: int | ||||||
|
|
||||||
|
|
||||||
| def close_portdbapi_caches(): | ||||||
| # The python interpreter does _not_ guarantee that destructors are | ||||||
|
|
@@ -177,6 +192,7 @@ def _scan_cat(self, cat): | |||||
| class portdbapi(dbapi): | ||||||
| """this tree will scan a portage directory located at root (passed to init)""" | ||||||
|
|
||||||
| settings: config_type | ||||||
| portdbapi_instances = _dummy_list() | ||||||
| _use_mutable = True | ||||||
|
|
||||||
|
|
@@ -207,7 +223,9 @@ def eclassdb(self): | |||||
| return None | ||||||
| return main_repo.eclass_db | ||||||
|
|
||||||
| def __init__(self, _unused_param=DeprecationWarning, mysettings=None): | ||||||
| def __init__( | ||||||
| self, _unused_param=DeprecationWarning, mysettings: Optional[config_type] = None | ||||||
| ): | ||||||
| """ | ||||||
| @param _unused_param: deprecated, use mysettings['PORTDIR'] instead | ||||||
| @type _unused_param: None | ||||||
|
|
@@ -264,15 +282,15 @@ def __init__(self, _unused_param=DeprecationWarning, mysettings=None): | |||||
| ) | ||||||
|
|
||||||
| # if the portdbapi is "frozen", then we assume that we can cache everything (that no updates to it are happening) | ||||||
| self.xcache = {} | ||||||
| self.xcache: dict[str, Any] = {} | ||||||
| self.frozen = 0 | ||||||
|
|
||||||
| # Keep a list of repo names, sorted by priority (highest priority first). | ||||||
| self._ordered_repo_name_list = tuple(reversed(self.repositories.prepos_order)) | ||||||
|
|
||||||
| self.auxdbmodule = self.settings.load_best_module("portdbapi.auxdbmodule") | ||||||
| self.auxdb = {} | ||||||
| self._pregen_auxdb = {} | ||||||
| self._pregen_auxdb: dict[str, Any] = {} | ||||||
| # If the current user doesn't have depcachedir write permission, | ||||||
| # then the depcachedir cache is kept here read-only access. | ||||||
| self._ro_auxdb = {} | ||||||
|
|
@@ -356,9 +374,9 @@ def __init__(self, _unused_param=DeprecationWarning, mysettings=None): | |||||
| "REQUIRED_USE", | ||||||
| } | ||||||
|
|
||||||
| self._aux_cache = {} | ||||||
| self._aux_cache: dict[str, Any] = {} | ||||||
| self._better_cache = None | ||||||
| self._broken_ebuilds = set() | ||||||
| self._broken_ebuilds: set[Any] = set() | ||||||
|
|
||||||
| def __getstate__(self): | ||||||
| state = self.__dict__.copy() | ||||||
|
|
@@ -453,7 +471,7 @@ def findLicensePath(self, license_name): | |||||
|
|
||||||
| def findname( | ||||||
| self, mycpv: str, mytree: Optional[str] = None, myrepo: Optional[str] = None | ||||||
| ) -> str: | ||||||
| ) -> Optional[str]: | ||||||
| return self.findname2(mycpv, mytree, myrepo)[0] | ||||||
|
|
||||||
| def getRepositoryPath(self, repository_id): | ||||||
|
|
@@ -514,7 +532,7 @@ def getIgnoredRepos(self): | |||||
|
|
||||||
| def findname2( | ||||||
| self, | ||||||
| mycpv: str, | ||||||
| mycpv: str | _pkg_str, | ||||||
| mytree: Optional[str] = None, | ||||||
| myrepo: Optional[str] = None, | ||||||
| ) -> Union[tuple[None, int], tuple[str, str], tuple[str, None]]: | ||||||
|
|
@@ -543,15 +561,15 @@ def findname2( | |||||
| raise InvalidPackageName(mycpv) | ||||||
|
|
||||||
| try: | ||||||
| cp = mycpv.cp | ||||||
| cp = mycpv.cp # type: ignore[attr-defined] | ||||||
| except AttributeError: | ||||||
| cp = mysplit[0] + "/" + psplit[0] | ||||||
|
|
||||||
| if self._better_cache is None: | ||||||
| if mytree: | ||||||
| mytrees = [mytree] | ||||||
| mytrees: list[str] = [mytree] | ||||||
| else: | ||||||
| mytrees = reversed(self.porttrees) | ||||||
| mytrees = list(reversed(self.porttrees)) | ||||||
| else: | ||||||
| try: | ||||||
| repos = self._better_cache[cp] | ||||||
|
|
@@ -582,6 +600,7 @@ def findname2( | |||||
| and myrepo == getattr(mycpv, "repo", None) | ||||||
| and self is getattr(mycpv, "_db", None) | ||||||
| ): | ||||||
| assert isinstance(mytree, str) | ||||||
| return (mytree + _os.sep + relative_path, mytree) | ||||||
|
|
||||||
| for x in mytrees: | ||||||
|
|
@@ -666,10 +685,10 @@ def _pull_valid_cache(self, cpv, ebuild_path, repo_path): | |||||
|
|
||||||
| return (metadata, ebuild_hash) | ||||||
|
|
||||||
| def aux_get( | ||||||
| def aux_get( # type: ignore[override] | ||||||
| self, | ||||||
| mycpv: str, | ||||||
| mylist: Sequence[str], | ||||||
| mylist: Sequence[_AuxKeys], | ||||||
| mytree: Optional[str] = None, | ||||||
| myrepo: Optional[str] = None, | ||||||
| ) -> list[str]: | ||||||
|
|
@@ -876,7 +895,12 @@ def _aux_get_return( | |||||
|
|
||||||
| future.set_result(returnme) | ||||||
|
|
||||||
| def getFetchMap(self, mypkg, useflags=None, mytree=None): | ||||||
| def getFetchMap( | ||||||
| self, | ||||||
| mypkg: str, | ||||||
| useflags: Optional[Sequence[str]] = None, | ||||||
| mytree: Optional[str] = None, | ||||||
| ) -> dict[str, tuple[str, ...]]: | ||||||
| """ | ||||||
| Get the SRC_URI metadata as a dict which maps each file name to a | ||||||
| set of alternative URIs. | ||||||
|
|
@@ -898,7 +922,13 @@ def getFetchMap(self, mypkg, useflags=None, mytree=None): | |||||
| self.async_fetch_map(mypkg, useflags=useflags, mytree=mytree, loop=loop) | ||||||
| ) | ||||||
|
|
||||||
| def async_fetch_map(self, mypkg, useflags=None, mytree=None, loop=None): | ||||||
| def async_fetch_map( | ||||||
| self, | ||||||
| mypkg: str, | ||||||
| useflags: Optional[Sequence[str]] = None, | ||||||
| mytree: Optional[str] = None, | ||||||
| loop: Any = None, | ||||||
| ) -> dict[str, tuple[str, ...]]: | ||||||
| """ | ||||||
| Asynchronous form of getFetchMap. | ||||||
|
|
||||||
|
|
@@ -968,9 +998,16 @@ def aux_get_done(aux_get_future): | |||||
| aux_get_future.add_done_callback(aux_get_done) | ||||||
| return result | ||||||
|
|
||||||
| def getfetchsizes(self, mypkg, useflags=None, debug=0, myrepo=None): | ||||||
| def getfetchsizes( | ||||||
| self, | ||||||
| mypkg: str, | ||||||
| useflags: Optional[Sequence[str]] = None, | ||||||
| debug: int = 0, | ||||||
| myrepo: Optional[str] = None, | ||||||
| ): | ||||||
| # returns a filename:size dictionary of remaining downloads | ||||||
| myebuild, mytree = self.findname2(mypkg, myrepo=myrepo) | ||||||
| mytree: str | ||||||
| myebuild, mytree = self.findname2(mypkg, myrepo=myrepo) # type: ignore[assignment] | ||||||
|
Tatsh marked this conversation as resolved.
|
||||||
| if myebuild is None: | ||||||
| raise AssertionError(_("ebuild not found for '%s'") % mypkg) | ||||||
| pkgdir = os.path.dirname(myebuild) | ||||||
|
|
@@ -1042,7 +1079,12 @@ def getfetchsizes(self, mypkg, useflags=None, debug=0, myrepo=None): | |||||
| return filesdict | ||||||
|
|
||||||
| def fetch_check( | ||||||
| self, mypkg, useflags=None, mysettings=None, all=False, myrepo=None | ||||||
| self, | ||||||
| mypkg: str, | ||||||
| useflags: Optional[Sequence[str]] = None, | ||||||
| mysettings=None, | ||||||
| all=False, | ||||||
| myrepo=None, | ||||||
| ): # pylint: disable=redefined-builtin | ||||||
| """ | ||||||
| TODO: account for PORTAGE_RO_DISTDIRS | ||||||
|
|
@@ -1089,18 +1131,25 @@ def fetch_check( | |||||
| return False | ||||||
| return True | ||||||
|
|
||||||
| def cpv_exists(self, mykey, myrepo=None): | ||||||
| def cpv_exists(self, mykey: str, myrepo: Optional[str] = None) -> Literal[0, 1]: | ||||||
| "Tells us whether an actual ebuild exists on disk (no masking)" | ||||||
| cps2 = mykey.split("/") | ||||||
| cps = catpkgsplit(mykey, silent=0) | ||||||
| if not cps: | ||||||
| # invalid cat/pkg-v | ||||||
| return 0 | ||||||
| assert isinstance(cps[0], str) | ||||||
| if self.findname(cps[0] + "/" + cps2[1], myrepo=myrepo): | ||||||
| return 1 | ||||||
| return 0 | ||||||
|
|
||||||
| def cp_all(self, categories=None, trees=None, reverse=False, sort=True): | ||||||
| def cp_all( # type: ignore[override] | ||||||
|
Tatsh marked this conversation as resolved.
|
||||||
| self, | ||||||
| categories: Optional[Iterable[str]] = None, | ||||||
| trees=None, | ||||||
| reverse: bool = False, | ||||||
| sort: bool = True, | ||||||
| ) -> list[str]: | ||||||
| """ | ||||||
| This returns a list of all keys in our tree or trees | ||||||
| @param categories: optional list of categories to search or | ||||||
|
|
@@ -1111,7 +1160,7 @@ def cp_all(self, categories=None, trees=None, reverse=False, sort=True): | |||||
| @param sort: return sorted results (default is True) | ||||||
| @rtype list of [cat/pkg,...] | ||||||
| """ | ||||||
| d = {} | ||||||
| d: dict[str, Any] = {} | ||||||
| if categories is None: | ||||||
| categories = self.settings.categories | ||||||
| if trees is None: | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.