fix(lint): drop ruff errors from 1470 to 0 across app/ and tests/
- Exclude generated SDK (sdks/python) and operational scripts from ruff lint - Add targeted per-file ignores for ASYNC*, S310, S603, S607, S108, S314, S102, PIE810, SIM102 in scripts/ - Auto-fix safe categories (I001, F401, W292, F841, PIE790, RUF100, etc.) - Bulk-fix S110 (try-except-pass), S112 (try-except-continue), S311 (random), S324 (md5/sha1), S301 (pickle) and similar lint categories - Rename N806 non-lowercase locals, including ML X/y variables preserved with noqa for scikit-learn conventions - Replace urllib.request calls with httpx.AsyncClient / httpx.Client (S310) - Wrap blocking os.path/os calls in asyncio.get_running_loop().run_in_executor - Replace subprocess.run with asyncio.create_subprocess_exec in async contexts - Store asyncio.create_task return values in _background_tasks set (RUF006) - Convert hardcoded subprocess binary names to absolute paths (S607) where appropriate; add noqa where path is config-driven (CAST_PATH, etc.) - Parameterize SQL queries with placeholders and add noqa for sanitized inputs - Fix all mechanical categories: SIM102, PIE810, TC001/2/3, S108, S314, S107, S306, S301, N802/N815/N817, S104, S605, S501, RUF022, UP031 - Add missing 'import asyncio' where referenced but not imported (F821) - Fix E402 module-import-not-at-top by adding '# noqa: E402' for circular-import safe cases and code-defined imports - Remove hardcoded Redis password in databus_warm_cron.py; use env vars Tests: - Add tests/unit/core/test_ai_router.py (8 tests): model resolution, chat completion with mocked httpx, fallback to OpenRouter, no-provider error, streaming - Add tests/unit/core/test_tracing.py (7 tests): setup_otel disabled/enabled, shutdown_otel, span helpers, tracing-enabled route registration - Add tests/unit/core/test_langfuse.py (2 tests): no-env init, noop flush - Fix tests/unit/domain/scanner/test_service.py to import from the moved app.domains.scanners.core.service Result: 'ruff check .' passes with 0 errors (was 1470). Pytest: 808 passed, 1 skipped (no regressions).
This commit is contained in:
parent
8491635bf2
commit
cfd75fd1a0
290 changed files with 5417 additions and 2458 deletions
|
|
@ -140,8 +140,12 @@ async def ingest_etherscan_combined() -> dict[str, int]:
|
|||
with open(csv_path, newline="", encoding="utf-8") as f:
|
||||
rows = list(csv.DictReader(f))
|
||||
|
||||
scam_rows = [r for r in rows if any(kw in r.get("label", "").lower() for kw in SCAM_LABEL_KEYWORDS)]
|
||||
wallet_rows = [r for r in rows if not any(kw in r.get("label", "").lower() for kw in SCAM_LABEL_KEYWORDS)]
|
||||
scam_rows = [
|
||||
r for r in rows if any(kw in r.get("label", "").lower() for kw in SCAM_LABEL_KEYWORDS)
|
||||
]
|
||||
wallet_rows = [
|
||||
r for r in rows if not any(kw in r.get("label", "").lower() for kw in SCAM_LABEL_KEYWORDS)
|
||||
]
|
||||
|
||||
logger.info(
|
||||
f"Etherscan combined: {len(rows)} total → {len(scam_rows)} scam → known_scams, {len(wallet_rows)} → wallet_profiles"
|
||||
|
|
@ -177,7 +181,9 @@ async def ingest_etherscan_combined() -> dict[str, int]:
|
|||
else:
|
||||
collection = "wallet_profiles"
|
||||
doc_id = make_doc_id("wallet_profiles", f"eth_combined:{address}:{chain}")
|
||||
content = f"Etherscan labeled address: {address} ({name}) on {chain}. Category: {label}."
|
||||
content = (
|
||||
f"Etherscan labeled address: {address} ({name}) on {chain}. Category: {label}."
|
||||
)
|
||||
metadata = {
|
||||
"address": address.lower(),
|
||||
"label": label,
|
||||
|
|
@ -297,7 +303,7 @@ async def ingest_rekt_hacks() -> dict[str, int]:
|
|||
|
||||
async def ingest_solana_flagged_tokens() -> dict[str, int]:
|
||||
"""Download Solana token list and ingest explicitly flagged scam tokens."""
|
||||
token_list_url = "https://raw.githubusercontent.com/solana-labs/token-list/main/src/tokens/solana.tokenlist.json"
|
||||
token_list_url = "https://raw.githubusercontent.com/solana-labs/token-list/main/src/tokens/solana.tokenlist.json" # noqa: S105
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=60) as client:
|
||||
|
|
@ -317,7 +323,9 @@ async def ingest_solana_flagged_tokens() -> dict[str, int]:
|
|||
for t in tokens:
|
||||
name_lower = (t.get("name", "") + " " + t.get("symbol", "")).lower()
|
||||
tags_lower = [str(tag).lower() for tag in t.get("tags", [])]
|
||||
if any(kw in name_lower for kw in scam_keywords) or any(kw in " ".join(tags_lower) for kw in scam_keywords):
|
||||
if any(kw in name_lower for kw in scam_keywords) or any(
|
||||
kw in " ".join(tags_lower) for kw in scam_keywords
|
||||
):
|
||||
flagged.append(t)
|
||||
|
||||
logger.info(f"Solana token list: {len(tokens)} total, {len(flagged)} flagged as scam/spam")
|
||||
|
|
@ -359,7 +367,9 @@ async def ingest_solana_flagged_tokens() -> dict[str, int]:
|
|||
|
||||
async def ingest_metamask_domains() -> dict[str, int]:
|
||||
"""Ingest MetaMask phishing domain blacklist in batches of 50."""
|
||||
config_url = "https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json"
|
||||
config_url = (
|
||||
"https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json"
|
||||
)
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=60) as client:
|
||||
|
|
@ -405,7 +415,9 @@ async def ingest_metamask_domains() -> dict[str, int]:
|
|||
errors += 1
|
||||
|
||||
if (batch_idx + 1) % 100 == 0:
|
||||
logger.info(f" MetaMask: {batch_idx + 1}/{total_batches} batches | ingested: {ingested}")
|
||||
logger.info(
|
||||
f" MetaMask: {batch_idx + 1}/{total_batches} batches | ingested: {ingested}"
|
||||
)
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
return {"ingested": ingested, "errors": errors}
|
||||
|
|
@ -602,7 +614,9 @@ async def ingest_phishdestroy() -> dict[str, int]:
|
|||
errors += 1
|
||||
|
||||
if (batch_idx + 1) % 100 == 0:
|
||||
logger.info(f" PhishDestroy: {batch_idx + 1}/{total_batches} | ingested: {ingested}")
|
||||
logger.info(
|
||||
f" PhishDestroy: {batch_idx + 1}/{total_batches} | ingested: {ingested}"
|
||||
)
|
||||
await asyncio.sleep(0.05)
|
||||
except Exception as e:
|
||||
logger.warning(f"PhishDestroy active_domains.json failed: {e}")
|
||||
|
|
@ -646,7 +660,9 @@ async def ingest_phishdestroy() -> dict[str, int]:
|
|||
errors += 1
|
||||
|
||||
if (batch_idx + 1) % 100 == 0:
|
||||
logger.info(f" PhishDestroy: {batch_idx + 1}/{total_batches} | ingested: {ingested}")
|
||||
logger.info(
|
||||
f" PhishDestroy: {batch_idx + 1}/{total_batches} | ingested: {ingested}"
|
||||
)
|
||||
await asyncio.sleep(0.05)
|
||||
except Exception as e:
|
||||
logger.warning(f"PhishDestroy domains.txt failed: {e}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue