-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwhl-req.py
More file actions
33 lines (28 loc) · 872 Bytes
/
whl-req.py
File metadata and controls
33 lines (28 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
# file: wheel-req.py
# vim:fileencoding=utf-8:ft=python
#
# Copyright © 2020 R.F. Smith <rsmith@xs4all.nl>.
# SPDX-License-Identifier: MIT
# Created: 2020-08-17T23:42:00+0200
# Last modified: 2022-02-05T20:19:53+0100
"""Extract the requirements from wheel files."""
import os
import sys
import zipfile as zf
def get_req(wheel):
z = zf.ZipFile(wheel)
name = [nm for nm in z.namelist() if nm.endswith("METADATA")][0]
with z.open(name) as f:
data = f.read().decode().splitlines()
requirements = [
ln.split(maxsplit=1)[1]
for ln in data
if ln.startswith("Requires-Dist:") and "extra ==" not in ln
]
return requirements
if __name__ == "__main__":
for path in sys.argv[1:]:
print(path.rsplit(os.sep, maxsplit=1)[1])
for dep in get_req(path):
print(" ", dep)