Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stubs/portage/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
portage.dbapi.dbapi.aux_get
portage.dbapi.dbapi.match
portage.dbapi.porttree.portagetree.__init__
portage.dbapi.porttree.portdbapi.__init__
portage.dbapi.porttree.portdbapi.xmatch
portage.package.ebuild.doebuild.doebuild
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add comment(s) explaining why the allowlist entries are needed?

Spot checking the first few from this run: https://github.com/python/typeshed/actions/runs/23243671825/job/67566324113, some of these look like valid errors that should be corrected in the stubs.

For example:

error: portage.dbapi.dbapi.match is inconsistent, stub parameter "mydep" differs from runtime parameter "origdep"
Stub: in file /home/runner/work/typeshed/typeshed/stubs/portage/portage/dbapi/__init__.pyi:49
def (self: portage.dbapi.dbapi, mydep: builtins.str, use_cache: Literal[0] | Literal[1] =) -> builtins.list[builtins.str] | builtins.str
Runtime: in file /tmp/stubtest-5vdnllvt/lib/python3.13/site-packages/portage/dbapi/__init__.py:132
def (self, origdep: str, use_cache: int = 1)

This looks right, the runtime parameter is named origdep, not mydep: https://github.com/gentoo/portage/blob/ac461a291c52e754f313bb3a42477be4545a0c7e/lib/portage/dbapi/__init__.py#L132

6 changes: 6 additions & 0 deletions stubs/portage/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version = "3.0.*"
upstream_repository = "https://gitweb.gentoo.org/proj/portage.git"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub mirror, which seems to be up to date and used for active development. Generally github upstream repos play nicer with our automation

Suggested change
upstream_repository = "https://gitweb.gentoo.org/proj/portage.git"
upstream_repository = "https://github.com/gentoo/portage"

partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
15 changes: 15 additions & 0 deletions stubs/portage/portage/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from collections.abc import Mapping
from typing import Any, TypedDict, type_check_only

from .dbapi.porttree import portagetree
from .package.ebuild.config import config

@type_check_only
class _DBRootDict(TypedDict):
bintree: Any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These days we require a comment for each use of Any explaining why it's necessary / what the allowable runtime types are. If you are unsure what the correct types are, you can use Incomplete (from _typeshed) – which is an alias of Any – instead.

porttree: portagetree
virtuals: Any

db: Mapping[str, _DBRootDict]
root: str
settings: config
32 changes: 32 additions & 0 deletions stubs/portage/portage/dbapi/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Literal

class dbapi:
def aux_get(
self,
mycpv: str,
mylist: list[
Literal[
"DEFINED_PHASES",
"DEPEND",
"EAPI",
"HDEPEND",
"HOMEPAGE",
"INHERITED",
"IUSE",
"KEYWORDS",
"LICENSE",
"PDEPEND",
"PROPERTIES",
"PROVIDE",
"RDEPEND",
"REQUIRED_USE",
"repository",
"RESTRICT",
"SRC_URI",
"SLOT",
]
],
mytree: str | None = ...,
myrepo: str | None = ...,
) -> list[str]: ...
def match(self, mydep: str, use_cache: Literal[0, 1] = ...) -> list[str] | str: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal defaults should use the actual value:

Suggested change
def match(self, mydep: str, use_cache: Literal[0, 1] = ...) -> list[str] | str: ...
def match(self, mydep: str, use_cache: Literal[0, 1] = 1) -> list[str] | str: ...

29 changes: 29 additions & 0 deletions stubs/portage/portage/dbapi/porttree.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from collections.abc import Sequence
from typing import Literal

from portage.dbapi import dbapi

class portdbapi(dbapi):
def getFetchMap(
self, mypkg: str, useflags: Sequence[str] | None = ..., mytree: str | None = ...
) -> dict[str, tuple[str, ...]]: ...
def xmatch(
self,
level: Literal[
"bestmatch-visible",
"match-all-cpv-only",
"match-all",
"match-visible",
"minimum-all",
"minimum-visible",
"minimum-all-ignore-profile",
],
origdep: str,
) -> list[str] | str: ...
def findname(self, mycpv: str, mytree: str | None = ..., myrepo: str | None = ...) -> str: ...
def findname2(
self, mycpv: str, mytree: str | None = ..., myrepo: str | None = ...
) -> tuple[None, Literal[0]] | tuple[str, str] | tuple[str, None]: ...

class portagetree:
dbapi: portdbapi
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions stubs/portage/portage/package/ebuild/config.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Any

class config:
def __init__(
self,
clone: config | None = ...,
mycpv: str | None = ...,
config_profile_path: str | None = ...,
config_incrementals: dict[str, str] | None = ...,
config_root: str | None = ...,
target_root: str | None = ...,
sysroot: str | None = ...,
eprefix: str | None = ...,
local_config: bool = True,
env: dict[str, str] | None = ...,
_unmatched_removal: bool = ...,
repositories: list[str] | None = ...,
) -> None: ...
def __getitem__(self, key: str) -> str: ...
def __setitem__(self, key: str, value: str) -> None: ...
def __delitem__(self, key: str) -> None: ...
def __iter__(self) -> str: ...
def get(self, k: str, x: Any = ...) -> Any: ...
54 changes: 54 additions & 0 deletions stubs/portage/portage/package/ebuild/doebuild.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Any, Literal

from portage.dbapi.porttree import portdbapi

from .config import config

def doebuild(
myebuild: str,
mydo: Literal[
"clean",
"cleanrm",
"compile",
"config",
"configure",
"depend",
"digest",
"fetch",
"fetchall",
"help",
"info",
"install",
"instprep",
"manifest",
"merge",
"nofetch",
"package",
"postinst",
"postrm",
"preinst",
"prepare",
"prerm",
"pretend",
"qmerge",
"rpm",
"setup",
"test",
"unmerge",
"unpack",
],
settings: config | None = ...,
debug: Literal[0, 1] = ...,
listonly: Literal[0, 1] = ...,
fetchonly: Literal[0, 1] = ...,
cleanup: Literal[0, 1] = ...,
use_cache: Literal[0, 1] = ...,
fetchall: Literal[0, 1] = ...,
tree: Literal["vartree", "porttree", "bintree"] = ...,
mydbapi: portdbapi | None = ...,
vartree: Any = ...,
prev_mtimes: dict[str, Any] | None = ...,
fd_pipes: dict[str, str] | None = ...,
returnproc: int | bool = ...,
) -> Literal[0, 1] | bool | list[int]: # Missing portage.process.MultiprocessingProcess
...
44 changes: 44 additions & 0 deletions stubs/portage/portage/versions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Any, Literal
from typing_extensions import Self

def vercmp(ver1: str, ver2: str, silent: Literal[0, 1] = ...) -> int | None: ...

class _pkg_str(str):
@property
def stable(self) -> bool: ...
def __new__(
cls,
cpv: str,
metadata: dict[str, Any] | None = ...,
settings: Any = ...,
eapi: Any = ...,
repo: str | None = ...,
slot: str | None = ...,
build_time: int | None = ...,
build_id: str | None = ...,
file_size: int | None = ...,
mtime: int | None = ...,
db: Any = ...,
repoconfig: Any = ...,
) -> Self: ...
def __init__(
self,
cpv: str,
metadata: dict[str, Any] | None = ...,
settings: Any = ...,
eapi: Any = ...,
repo: str | None = ...,
slot: str | None = ...,
build_time: int | None = ...,
build_id: str | None = ...,
file_size: int | None = ...,
mtime: int | None = ...,
db: Any = ...,
repoconfig: Any = ...,
) -> None: ...
@staticmethod
def _long(var: Any, default: int) -> int: ...

def catpkgsplit(
mydata: str | _pkg_str, silent: Literal[0, 1] = ..., eapi: str | None = ...
) -> tuple[str | None, str, str, str] | None: ...
Loading