chore(lint): auto-fix 253 of 283 ruff issues (F401, I001, E402, RUF100, UP037, SIM105)
Mass ruff auto-fix:
- ruff check --fix: 109 issues fixed (F401 unused imports,
I001 unsorted imports, UP037 quoted annotations, SIM105
suppressible exception, RUF100 unused-noqa)
- ruff check --fix --unsafe-fixes: 22 additional issues
- ruff format: 70 files reformatted
- Manual pass: fix 16 misplaced import httpx lines
- Manual pass: fix remaining E402 (import-after-docstring)
Result: 283 errors -> 30 errors.
The remaining 30 are real issues that need manual review:
5 F401 unused-import (likely auto-generated stubs)
5 F821 undefined-name (real bugs in code that references
redis/pydantic/LLMRegistry without imports)
3 BLE001 (the compliance LLM fallback is intentional; the
other two are real)
3 RUF012 mutable-class-default
3 SIM105, 3 SIM117, 2 E722, 2 E741
1 B007, 1 B025, 1 E402, 1 RUF200 (pyproject.toml issue)
Tests: 436/437 pass (1 pre-existing SSE sandbox failure).
format check + import sort: now clean.
make ci: still gated on the 30 remaining real issues.
Follow-up: triage the 30 issues file-by-file.
This commit is contained in:
parent
e60a62a07a
commit
a7c30b12cd
85 changed files with 2374 additions and 1071 deletions
|
|
@ -21,6 +21,7 @@ logger = logging.getLogger(__name__)
|
|||
try:
|
||||
from camoufox import AsyncCamoufox
|
||||
from camoufox.utils import DefaultAddons
|
||||
|
||||
_has_camoufox = True
|
||||
except ImportError:
|
||||
_has_camoufox = False
|
||||
|
|
@ -31,28 +32,42 @@ class CamoufoxBrowser:
|
|||
|
||||
DEFAULT_CONFIGS = {
|
||||
"chrome_windows": {
|
||||
"headless": True, "os": "windows", "browser": "chrome",
|
||||
"screen": (1920, 1080), "window": (1920, 1080),
|
||||
"headless": True,
|
||||
"os": "windows",
|
||||
"browser": "chrome",
|
||||
"screen": (1920, 1080),
|
||||
"window": (1920, 1080),
|
||||
},
|
||||
"firefox_windows": {
|
||||
"headless": True, "os": "windows", "browser": "firefox",
|
||||
"screen": (1920, 1080), "window": (1920, 1080),
|
||||
"headless": True,
|
||||
"os": "windows",
|
||||
"browser": "firefox",
|
||||
"screen": (1920, 1080),
|
||||
"window": (1920, 1080),
|
||||
},
|
||||
"chrome_mac": {
|
||||
"headless": True, "os": "macos", "browser": "chrome",
|
||||
"screen": (2560, 1600), "window": (1440, 900),
|
||||
"headless": True,
|
||||
"os": "macos",
|
||||
"browser": "chrome",
|
||||
"screen": (2560, 1600),
|
||||
"window": (1440, 900),
|
||||
},
|
||||
"firefox_linux": {
|
||||
"headless": True, "os": "linux", "browser": "firefox",
|
||||
"screen": (1920, 1080), "window": (1920, 1080),
|
||||
"headless": True,
|
||||
"os": "linux",
|
||||
"browser": "firefox",
|
||||
"screen": (1920, 1080),
|
||||
"window": (1920, 1080),
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self, default_profile: str = "chrome_windows"):
|
||||
self.default_profile = default_profile
|
||||
if not _has_camoufox:
|
||||
logger.warning("camoufox_not_available",
|
||||
extra={"hint": "pip install camoufox && python -m camoufox fetch"})
|
||||
logger.warning(
|
||||
"camoufox_not_available",
|
||||
extra={"hint": "pip install camoufox && python -m camoufox fetch"},
|
||||
)
|
||||
|
||||
async def fetch(
|
||||
self,
|
||||
|
|
@ -74,10 +89,16 @@ class CamoufoxBrowser:
|
|||
cookies: Cookies to set before navigation
|
||||
"""
|
||||
if not _has_camoufox:
|
||||
return {"success": False, "error": "camoufox not installed. Run: pip install camoufox && python -m camoufox fetch"}
|
||||
return {
|
||||
"success": False,
|
||||
"error": "camoufox not installed. Run: pip install camoufox && python -m camoufox fetch",
|
||||
}
|
||||
profile_name = profile or self.default_profile
|
||||
config = dict(self.DEFAULT_CONFIGS.get(profile_name, self.DEFAULT_CONFIGS["chrome_windows"]))
|
||||
if proxy: config["proxy"] = proxy
|
||||
config = dict(
|
||||
self.DEFAULT_CONFIGS.get(profile_name, self.DEFAULT_CONFIGS["chrome_windows"])
|
||||
)
|
||||
if proxy:
|
||||
config["proxy"] = proxy
|
||||
try:
|
||||
start = time.time()
|
||||
async with AsyncCamoufox(**config) as browser:
|
||||
|
|
@ -98,10 +119,15 @@ class CamoufoxBrowser:
|
|||
elapsed = time.time() - start
|
||||
cookies_received = await page.context.cookies()
|
||||
return {
|
||||
"success": True, "url": url, "title": title,
|
||||
"content": content, "raw_html": content,
|
||||
"status_code": 200, "elapsed": round(elapsed, 2),
|
||||
"profile": profile_name, "cookies": cookies_received,
|
||||
"success": True,
|
||||
"url": url,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"raw_html": content,
|
||||
"status_code": 200,
|
||||
"elapsed": round(elapsed, 2),
|
||||
"profile": profile_name,
|
||||
"cookies": cookies_received,
|
||||
}
|
||||
except Exception as e: # noqa: BLE001
|
||||
return {"success": False, "error": str(e)[:300], "url": url}
|
||||
|
|
@ -120,8 +146,10 @@ class CamoufoxBrowser:
|
|||
if human_behavior:
|
||||
try:
|
||||
from camoufox import AsyncCamoufox
|
||||
|
||||
config = dict(self.DEFAULT_CONFIGS.get(self.default_profile, {}))
|
||||
if proxy: config["proxy"] = proxy
|
||||
if proxy:
|
||||
config["proxy"] = proxy
|
||||
async with AsyncCamoufox(**config) as browser:
|
||||
page = await browser.new_page()
|
||||
await page.goto(url, wait_until="domcontentloaded")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue