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
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
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.
30 from importlib
.metadata
import requires
31 from packaging
.requirements
import Requirement
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()
45 r
= Requirement(re
.sub(r
"#.*", "", req
))
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
])