forked from d101tm/tmstats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindneeds.py
More file actions
executable file
·27 lines (22 loc) · 794 Bytes
/
findneeds.py
File metadata and controls
executable file
·27 lines (22 loc) · 794 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
#!/usr/bin/env python3
""" Find missing modules """
import sys, re, importlib, subprocess
def addto(imports, what):
what = what.split('.')[0]
if what not in imports:
try:
importlib.import_module(what)
except ModuleNotFoundError:
info = sys.exc_info()[1]
imports.add(info.name)
imports = set()
cmd = r"grep -h 'import ' *.py | sed -e 's/#.*//' -e 's/ as .*//' -e 's/,/ /g'"
ans = subprocess.run(cmd, shell=True, capture_output=True, text=True).stdout.split('\n')
for line in ans:
line = line.strip()
if line.startswith('from'):
addto(imports, line.split()[1])
elif line.startswith('import'):
for mod in line.split()[1:]:
addto(imports, mod)
print('\n'.join(sorted(imports, key=str.lower)))