Skip to content

Commit

Permalink
fixup! common/scripts/parse-py-metadata.py: add script to parse pytho…
Browse files Browse the repository at this point in the history
…n module metadata

Closes: void-linux#53326 [via git-merge-pr]
  • Loading branch information
classabbyamp authored and ahesford committed Dec 4, 2024
1 parent 57c8802 commit 095f65b
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions common/scripts/parse-py-metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- $DESTDIR/$py3_sitelib/*.dist-info/METADATA
- $DESTDIR/$py3_sitelib/*.egg-info/PKG-INFO
./parse-py-metadata.py -S "$DESTDIR/$py3_sitelib" depends [-s] [-C] -e "extra1 extra2 ..."
./parse-py-metadata.py -S "$DESTDIR/$py3_sitelib" [-s] [-C] depends -e "extra1 extra2 ..."
-D "$PKGDESTDIR/rdeps" -V <( xbps-query -R -p provides -s "py3:" )
check that the dependencies of a package match what's listed in the python
Expand All @@ -24,21 +24,24 @@

import argparse
from pathlib import Path
from sys import stderr
from typing import TYPE_CHECKING

from packaging.metadata import Metadata
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
if TYPE_CHECKING:
from packaging.metadata import Metadata
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name


def msg_err(msg: str, *, nocolor: bool = False, strict: bool = False):
if nocolor:
print(msg)
else:
color = "31" if strict else "33"
print(f"\033[1m\033[{color}m{msg}\033[m")
print(f"\033[1m\033[{color}m{msg}\033[m", file=stderr)


def vpkgname(val: str | Requirement, *, version: str | None = None) -> str:
def vpkgname(val: "str | Requirement", *, version: str | None = None) -> str:
sfx = ""
if version is not None:
sfx = f"-{version}"
Expand Down Expand Up @@ -66,7 +69,7 @@ def getpkgdepname(pkgdep: str) -> str:
return pkgdep.rpartition("-")[0]


def match_markers(req: Requirement, extras: set[str]) -> bool:
def match_markers(req: "Requirement", extras: set[str]) -> bool:
# unconditional requirement
if req.marker is None:
return True
Expand Down Expand Up @@ -172,6 +175,8 @@ def parse_depends(args):
parser = argparse.ArgumentParser()
parser.add_argument("-S", dest="sitepkgs", type=Path)
parser.add_argument("-v", dest="pkgver")
parser.add_argument("-s", dest="strict", action="store_true")
parser.add_argument("-C", dest="nocolor", action="store_true")
subparsers = parser.add_subparsers()

prov_parser = subparsers.add_parser("provides")
Expand All @@ -181,9 +186,18 @@ def parse_depends(args):
deps_parser.add_argument("-e", dest="extras", default="")
deps_parser.add_argument("-V", dest="vpkgs", type=Path)
deps_parser.add_argument("-D", dest="rdeps", type=Path)
deps_parser.add_argument("-s", dest="strict", action="store_true")
deps_parser.add_argument("-C", dest="nocolor", action="store_true")
deps_parser.set_defaults(func=parse_depends)

args = parser.parse_args()

try:
from packaging.metadata import Metadata
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
except ImportError:
msg_err(f"=> WARNING: {args.pkgver}: missing packaging module!\n"
f"=> WARNING: {args.pkgver}: please add python3-packaging-bootstrap to hostmakedepends to run this check",
nocolor=args.nocolor)
exit(0)

args.func(args)

0 comments on commit 095f65b

Please sign in to comment.