mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
import os
|
|
import re
|
|
import inspect
|
|
from typing import Type
|
|
|
|
import litellm
|
|
|
|
|
|
def get_init_params(cls: Type) -> list[str]:
|
|
"""
|
|
Retrieve all parameters supported by the `__init__` method of a given class.
|
|
|
|
Args:
|
|
cls: The class to inspect.
|
|
|
|
Returns:
|
|
A list of parameter names.
|
|
"""
|
|
if not hasattr(cls, "__init__"):
|
|
raise ValueError(
|
|
f"The provided class {cls.__name__} does not have an __init__ method."
|
|
)
|
|
|
|
init_method = cls.__init__
|
|
argspec = inspect.getfullargspec(init_method)
|
|
|
|
# The first argument is usually 'self', so we exclude it
|
|
return argspec.args[1:] # Exclude 'self'
|
|
|
|
|
|
router_init_params = set(get_init_params(litellm.router.Router))
|
|
print(router_init_params)
|
|
router_init_params.remove("model_list")
|
|
|
|
# Parse the documentation to extract documented keys
|
|
_test_dir = os.path.dirname(os.path.abspath(__file__))
|
|
_repo_root = os.path.abspath(os.path.join(_test_dir, "..", ".."))
|
|
print(os.listdir(_repo_root))
|
|
docs_path = os.path.join(
|
|
_repo_root, "docs", "my-website", "docs", "proxy", "config_settings.md"
|
|
)
|
|
documented_keys = set()
|
|
try:
|
|
with open(docs_path, "r", encoding="utf-8") as docs_file:
|
|
content = docs_file.read()
|
|
|
|
# Find the section titled "general_settings - Reference"
|
|
general_settings_section = re.search(
|
|
r"### router_settings - Reference(.*?)###", content, re.DOTALL
|
|
)
|
|
if general_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))
|
|
except Exception as e:
|
|
raise Exception(
|
|
f"Error reading documentation: {e}, \n repo base - {os.listdir(_repo_root)}"
|
|
)
|
|
|
|
|
|
# Compare and find undocumented keys
|
|
undocumented_keys = router_init_params - documented_keys
|
|
|
|
# Print results
|
|
print("Keys expected in 'router settings' (found in code):")
|
|
for key in sorted(router_init_params):
|
|
print(key)
|
|
|
|
if undocumented_keys:
|
|
raise Exception(
|
|
f"\nKeys not documented in 'router settings - Reference': {undocumented_keys}"
|
|
)
|
|
else:
|
|
print(
|
|
"\nAll keys are documented in 'router settings - Reference'. - {}".format(
|
|
router_init_params
|
|
)
|
|
)
|