forked from dvilelaf/meme-ooorr
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_pyinstaller_dependencies.py
More file actions
79 lines (66 loc) · 2.18 KB
/
get_pyinstaller_dependencies.py
File metadata and controls
79 lines (66 loc) · 2.18 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
from importlib.metadata import distributions
from aea.cli.utils.context import Context
from aea.cli.utils.config import (
try_to_load_agent_config,
)
import os
from importlib.metadata import distributions
from pathlib import Path
def get_modules_from_dist(dist):
"""Try to get top-level modules from dist metadata, fallback to directory names."""
modules = []
# 1. Try top_level.txt
try:
top_level = dist.read_text("top_level.txt")
if top_level:
modules.extend([m.strip() for m in top_level.splitlines() if m.strip()])
except FileNotFoundError:
pass
# 2. Fallback: look in site-packages directory
if not modules:
for path in dist.files or []:
# Only consider first-level packages/modules
if ".dist-info" in str(path):
continue
parts = Path(path).parts
if len(parts) == 1 and parts[0].endswith(".py"):
name = parts[0]
modules.append(name[:-3]) # strip .py
if len(parts) == 2 and parts[1] == "__init__.py":
name = parts[0]
modules.append(name)
return sorted(set(modules))
def get_modules():
os.chdir("agent")
ctx = Context(cwd=".", verbosity="debug", registry_path=".")
try_to_load_agent_config(ctx)
deps = [i.replace("-", "_") for i in ctx.get_dependencies().keys()]
all_modules = []
for dist in distributions():
dist_name = dist.metadata["Name"].lower().replace("-", "_")
if dist_name in deps:
modules = get_modules_from_dist(dist)
for mod in modules:
all_modules.append(mod)
all_modules = list(sorted(all_modules))
return all_modules
def modules_filter(modules):
black_list = [
"pytest",
"pytest_asyncio",
"_pytest",
"py",
"hypothesis",
"Crypto",
"_yaml",
]
return [i for i in modules if i not in black_list]
def main():
all_modules = modules_filter(get_modules())
print(
" ".join([f"--hidden-import {m} --collect-all {m}" for m in all_modules]),
end="",
)
if __name__ == "__main__":
main()