- Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathtest_general_setting_keys.py
78 lines (67 loc) · 2.82 KB
/
test_general_setting_keys.py
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
importos
importre
# Define the base directory for the litellm repository and documentation path
repo_base="./litellm"# Change this to your actual path
# Regular expressions to capture the keys used in general_settings.get() and general_settings[]
get_pattern=re.compile(
r'general_settings\.get\(\s*[\'"]([^\'"]+)[\'"](,?\s*[^)]*)?\)'
)
bracket_pattern=re.compile(r'general_settings\[\s*[\'"]([^\'"]+)[\'"]\s*\]')
# Set to store unique keys from the code
general_settings_keys=set()
# Walk through all files in the litellm repo to find references of general_settings
forroot, dirs, filesinos.walk(repo_base):
forfileinfiles:
iffile.endswith(".py"): # Only process Python files
file_path=os.path.join(root, file)
withopen(file_path, "r", encoding="utf-8") asf:
content=f.read()
# Find all keys using general_settings.get()
get_matches=get_pattern.findall(content)
general_settings_keys.update(
match[0] formatchinget_matches
) # Extract only the key part
# Find all keys using general_settings[]
bracket_matches=bracket_pattern.findall(content)
general_settings_keys.update(bracket_matches)
# Parse the documentation to extract documented keys
repo_base="./"
print(os.listdir(repo_base))
docs_path= (
"./docs/my-website/docs/proxy/config_settings.md"# Path to the documentation
)
documented_keys=set()
try:
withopen(docs_path, "r", encoding="utf-8") asdocs_file:
content=docs_file.read()
# Find the section titled "general_settings - Reference"
general_settings_section=re.search(
r"### general_settings - Reference(.*?)###", content, re.DOTALL
)
ifgeneral_settings_section:
# Extract the table rows, which contain the documented keys
table_content=general_settings_section.group(1)
doc_key_pattern=re.compile(
r"\|\s*([^\|]+?)\s*\|"
) # Capture the key from each row of the table
documented_keys.update(doc_key_pattern.findall(table_content))
exceptExceptionase:
raiseException(
f"Error reading documentation: {e}, \n repo base - {os.listdir(repo_base)}"
)
# Compare and find undocumented keys
undocumented_keys=general_settings_keys-documented_keys
# Print results
print("Keys expected in 'general_settings' (found in code):")
forkeyinsorted(general_settings_keys):
print(key)
ifundocumented_keys:
raiseException(
f"\nKeys not documented in 'general_settings - Reference': {undocumented_keys}"
)
else:
print(
"\nAll keys are documented in 'general_settings - Reference'. - {}".format(
general_settings_keys
)
)