python/yarl: update to 1.17.2
[oi-userland.git] / tools / python-requires
blobeb027b7baca765ddc5764bb50ac6a21a1a609ef2
1 #! /usr/bin/python
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright 2022 Marcel Telka
18 # Usage:
19 # python-requires PACKAGE [EXTRA]
21 # Print requirements for PACKAGE. Evaluated and normalized.
22 # If PACKAGE is - evaluate and normalize stdin.
23 # With optional EXTRA argument passed print requirements for such extra only.
26 import sys
27 import re
29 try:
30 from importlib.metadata import requires
31 from packaging.requirements import Requirement
32 import subprocess
33 except:
34 exit()
36 if len(sys.argv) < 2:
37 exit()
39 e = {'extra': sys.argv[2]} if len(sys.argv) > 2 else None
40 reqs = requires(sys.argv[1]) if sys.argv[1] != "-" else sys.stdin.readlines()
42 try:
43 for req in reqs:
44 try:
45 r = Requirement(re.sub(r"#.*", "", req))
46 except:
47 continue
48 m = r.marker
49 if (not m and not e) or (m and m.evaluate(e) and (not e or not m.evaluate())):
50 print(re.sub(r"[-_.]+", "-", r.name).lower())
51 for extra in r.extras:
52 subprocess.run([sys.argv[0], r.name, extra])
53 except:
54 pass