-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_data.py
More file actions
127 lines (87 loc) · 3.07 KB
/
read_data.py
File metadata and controls
127 lines (87 loc) · 3.07 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import json
from functools import cache
from pathlib import PurePath, PurePosixPath
from utils.structs import ASConArg, UnknownFileError
with open("class_parsed.json", "r") as fp:
class_cache = json.load(fp)
class_path_to_file = {v["class_path"].replace("Top.Level.", ""): k for k, v in class_cache.items()}
def add_keys(in_dict, keys):
if not keys:
return
n_key = keys.pop(0)
if n_key not in in_dict:
in_dict[n_key] = {}
add_keys(in_dict[n_key], keys)
class_tree = {}
for k in class_cache:
ks = k.replace("doc_trunk/doc_pages/", "").replace(".html", "").split(r"/")
add_keys(class_tree, ks)
@cache
def get_info(in_key):
try:
if isinstance(in_key, PurePath):
return class_cache[str(PurePosixPath(in_key))]
return class_cache[in_key]
except KeyError as e:
raise UnknownFileError from e
def get_parents(file_key):
file_info = get_info(file_key)
return file_info["inheritance_links"]
def get_parent(file_key):
file_info = get_info(file_key)
return file_info["inheritance_links"][file_info["inheritance"][1]]
def get_used_types(in_details):
used_types = {}
for detail in in_details:
used_types |= detail["types_used"]
return {k: v for k, v in used_types.items() if v in class_cache}
def get_import_path(file_key, in_type):
file_info = get_info(file_key)
types_to_key = get_used_types(file_info["details"])
type_key = types_to_key.get(in_type, None)
if type_key is None:
return None
type_info = get_info(type_key)
return (
None
if tuple(type_info["package"]) == ("Top", "Level")
else f"import {type_info['class_path']};"
)
def get_constructor(file_key):
file_info = get_info(file_key)
return file_info["constructor"]
def get_constructor_args(file_key):
file_info = get_info(file_key)
return [ASConArg(*con_arg) for con_arg in file_info["constructor_args"]]
def get_parent_args(file_key):
if c_parent := get_parent(file_key):
return get_constructor_args(c_parent)
return []
def is_top_level(file_key):
file_info = get_info(file_key)
c_pkg = tuple(file_info["package"])
return ("Top", "Level") == c_pkg
def get_class_sig(file_key):
file_info = get_info(file_key)
return " ".join(file_info["class"])
def get_inherit_sig(file_key):
file_info = get_info(file_key)
return file_info["inheritance"]
def get_class_props(file_key):
file_info = get_info(file_key)
return file_info["properties"]
def get_class_methods(file_key):
file_info = get_info(file_key)
return [xx for xx in file_info["methods"] if xx[0] != file_info["class_name"]]
def get_class_consts(file_key):
file_info = get_info(file_key)
return file_info["constants"]
def get_class_details(file_key):
file_info = get_info(file_key)
return file_info["organized_details"]
def get_class_package(file_key):
file_info = get_info(file_key)
return file_info["package"]
def get_string_format(file_key):
file_info = get_info(file_key)
return file_info["string_format"]