From 0ecc25034908e98e9794ffd1588f5c0362a60368 Mon Sep 17 00:00:00 2001 From: cryptorugmunch Date: Mon, 6 Jul 2026 10:25:44 +0200 Subject: [PATCH] refactor(pry): rename 19 root modules to pry_ to remove naming collision with routers/ The duplicate file names (advanced, agency, auth, compliance, costing, etc.) in both root and routers/ made imports ambiguous. Renamed root modules to pry_.py so: from quality import X -> from pry_quality import X from routers.quality import router (unchanged) Also: - Renamed x402.py to pry_x402/ package directory - Fixed 21+ bare imports across api.py, deps.py, routers/, tests/, llm_providers/ Tests: 593 passed, 1 skipped (test_ready_returns_200 fails pre-existing because Ollama is unreachable from test env, unrelated to this refactor). Audit item 8. --- api.py | 2 +- deps.py | 2 +- llm_providers/base.py | 2 +- llm_providers/registry.py | 2 +- proxy_manager.py | 6 +++--- advanced.py => pry_advanced.py | 0 agency.py => pry_agency.py | 0 auth.py => pry_auth.py | 0 compliance.py => pry_compliance.py | 0 costing.py => pry_costing.py | 0 enrichment.py => pry_enrichment.py | 0 extraction.py => pry_extraction.py | 0 freshness.py => pry_freshness.py | 0 gdpr.py => pry_gdpr.py | 0 intelligence.py => pry_intelligence.py | 0 pry_mcp/fallback_server.py | 2 +- pipeline.py => pry_pipeline.py | 0 pipelines.py => pry_pipelines.py | 0 quality.py => pry_quality.py | 0 reconciliation.py => pry_reconciliation.py | 0 referrals.py => pry_referrals.py | 0 reports.py => pry_reports.py | 0 review.py => pry_review.py | 0 sessions.py => pry_sessions.py | 0 x402.py => pry_x402/__init__.py | 0 routers/extraction.py | 2 +- routers/pipeline.py | 2 +- routers/x402.py | 14 +++++++------- template_engine.py | 2 +- tests/test_agency.py | 2 +- tests/test_api_surface_snapshot.py | 4 ++-- tests/test_compliance.py | 2 +- tests/test_costing.py | 2 +- tests/test_enrichment.py | 4 ++-- tests/test_freshness.py | 2 +- tests/test_gdpr.py | 2 +- tests/test_infrastructure.py | 2 +- tests/test_intelligence.py | 4 ++-- tests/test_llm_fallback.py | 10 +++++----- tests/test_pipeline.py | 2 +- tests/test_pipelines.py | 2 +- tests/test_quality.py | 2 +- tests/test_reconciliation.py | 2 +- tests/test_referrals.py | 4 ++-- tests/test_reports.py | 2 +- tests/test_review.py | 2 +- tests/test_x402_mcp_spec.py | 2 +- x402_middleware.py | 4 ++-- 48 files changed, 46 insertions(+), 46 deletions(-) rename advanced.py => pry_advanced.py (100%) rename agency.py => pry_agency.py (100%) rename auth.py => pry_auth.py (100%) rename compliance.py => pry_compliance.py (100%) rename costing.py => pry_costing.py (100%) rename enrichment.py => pry_enrichment.py (100%) rename extraction.py => pry_extraction.py (100%) rename freshness.py => pry_freshness.py (100%) rename gdpr.py => pry_gdpr.py (100%) rename intelligence.py => pry_intelligence.py (100%) rename pipeline.py => pry_pipeline.py (100%) rename pipelines.py => pry_pipelines.py (100%) rename quality.py => pry_quality.py (100%) rename reconciliation.py => pry_reconciliation.py (100%) rename referrals.py => pry_referrals.py (100%) rename reports.py => pry_reports.py (100%) rename review.py => pry_review.py (100%) rename sessions.py => pry_sessions.py (100%) rename x402.py => pry_x402/__init__.py (100%) diff --git a/api.py b/api.py index 4bcbb42..44c90e9 100644 --- a/api.py +++ b/api.py @@ -27,7 +27,7 @@ from errors import ( ) from mcp_sse import mcp_post_message, mcp_sse_endpoint from observability import REQUEST_COUNT, REQUEST_LATENCY, setup_tracing -from pipeline import get_pipeline +from pry_pipeline import get_pipeline from pry_mcp import make_fallback_server, register_all from routers.advanced import router as advanced_router from routers.agency import router as agency_router diff --git a/deps.py b/deps.py index d1c0e2e..9b0a10d 100644 --- a/deps.py +++ b/deps.py @@ -12,7 +12,7 @@ Usage: # Copyright (c) 2026 Rug Munch Media LLC from __future__ import annotations -from advanced import PryAdvanced +from pry_advanced import PryAdvanced from automator import PryAutomator from cache import ResponseCache from extractor import SchemaExtractor diff --git a/llm_providers/base.py b/llm_providers/base.py index bb496cb..6a1bd61 100644 --- a/llm_providers/base.py +++ b/llm_providers/base.py @@ -44,7 +44,7 @@ class ReferralConfig: def __post_init__(self): if not self.referral_links: - from referrals import PROVIDER_CATALOG + from pry_referrals import PROVIDER_CATALOG for _category, providers in PROVIDER_CATALOG.items(): for p in providers: diff --git a/llm_providers/registry.py b/llm_providers/registry.py index 579cf0d..70a137a 100644 --- a/llm_providers/registry.py +++ b/llm_providers/registry.py @@ -146,7 +146,7 @@ class LLMRegistry: u["last_used"] = datetime.now(UTC).isoformat() # NEW: track in-app LLM usage as referral revenue try: - from referrals import ReferralTracker + from pry_referrals import ReferralTracker if not hasattr(self, "_referral_tracker"): self._referral_tracker = ReferralTracker() diff --git a/proxy_manager.py b/proxy_manager.py index 8728630..2655711 100644 --- a/proxy_manager.py +++ b/proxy_manager.py @@ -328,7 +328,7 @@ class ProxyManager: if not provider: provider = PREMIUM_PROXY_PROVIDERS[0] try: - from referrals import ReferralTracker + from pry_referrals import ReferralTracker tracker = ReferralTracker() tracker.record_click( @@ -435,7 +435,7 @@ class ProxyManager: if not provider: return "" try: - from referrals import ReferralTracker + from pry_referrals import ReferralTracker tracker = ReferralTracker() return tracker.record_click( @@ -451,7 +451,7 @@ class ProxyManager: def get_recent_clicks(self, days_back: int = 30) -> list[dict[str, Any]]: """Get recent proxy referral clicks for revenue tracking.""" try: - from referrals import ReferralTracker + from pry_referrals import ReferralTracker tracker = ReferralTracker() cutoff = datetime.now(UTC).timestamp() - (days_back * 86400) diff --git a/advanced.py b/pry_advanced.py similarity index 100% rename from advanced.py rename to pry_advanced.py diff --git a/agency.py b/pry_agency.py similarity index 100% rename from agency.py rename to pry_agency.py diff --git a/auth.py b/pry_auth.py similarity index 100% rename from auth.py rename to pry_auth.py diff --git a/compliance.py b/pry_compliance.py similarity index 100% rename from compliance.py rename to pry_compliance.py diff --git a/costing.py b/pry_costing.py similarity index 100% rename from costing.py rename to pry_costing.py diff --git a/enrichment.py b/pry_enrichment.py similarity index 100% rename from enrichment.py rename to pry_enrichment.py diff --git a/extraction.py b/pry_extraction.py similarity index 100% rename from extraction.py rename to pry_extraction.py diff --git a/freshness.py b/pry_freshness.py similarity index 100% rename from freshness.py rename to pry_freshness.py diff --git a/gdpr.py b/pry_gdpr.py similarity index 100% rename from gdpr.py rename to pry_gdpr.py diff --git a/intelligence.py b/pry_intelligence.py similarity index 100% rename from intelligence.py rename to pry_intelligence.py diff --git a/pry_mcp/fallback_server.py b/pry_mcp/fallback_server.py index 3cd7091..15c52de 100644 --- a/pry_mcp/fallback_server.py +++ b/pry_mcp/fallback_server.py @@ -237,7 +237,7 @@ def make_fallback_server( ) if uri == "pry://x402/pricing": try: - from x402 import X402Handler + from pry_x402 import X402Handler return json.dumps(X402Handler().get_stats(), indent=2) except (json.JSONDecodeError, ValueError) as e: diff --git a/pipeline.py b/pry_pipeline.py similarity index 100% rename from pipeline.py rename to pry_pipeline.py diff --git a/pipelines.py b/pry_pipelines.py similarity index 100% rename from pipelines.py rename to pry_pipelines.py diff --git a/quality.py b/pry_quality.py similarity index 100% rename from quality.py rename to pry_quality.py diff --git a/reconciliation.py b/pry_reconciliation.py similarity index 100% rename from reconciliation.py rename to pry_reconciliation.py diff --git a/referrals.py b/pry_referrals.py similarity index 100% rename from referrals.py rename to pry_referrals.py diff --git a/reports.py b/pry_reports.py similarity index 100% rename from reports.py rename to pry_reports.py diff --git a/review.py b/pry_review.py similarity index 100% rename from review.py rename to pry_review.py diff --git a/sessions.py b/pry_sessions.py similarity index 100% rename from sessions.py rename to pry_sessions.py diff --git a/x402.py b/pry_x402/__init__.py similarity index 100% rename from x402.py rename to pry_x402/__init__.py diff --git a/routers/extraction.py b/routers/extraction.py index dcde526..7bf22c9 100644 --- a/routers/extraction.py +++ b/routers/extraction.py @@ -19,7 +19,7 @@ from fastapi import APIRouter, Body from client import get_client from deps import advanced, scraper from errors import InvalidRequestError, ScrapeError -from extraction import JsonCssExtractionStrategy, extract_with_chunking +from pry_extraction import JsonCssExtractionStrategy, extract_with_chunking from extractor import SchemaExtractor logger = logging.getLogger(__name__) diff --git a/routers/pipeline.py b/routers/pipeline.py index 9571eb3..eae121c 100644 --- a/routers/pipeline.py +++ b/routers/pipeline.py @@ -14,7 +14,7 @@ from typing import Any from fastapi import APIRouter, Body from errors import InvalidRequestError -from pipeline import HOOK_POINTS, get_pipeline, run_pipeline +from pry_pipeline import HOOK_POINTS, get_pipeline, run_pipeline logger = logging.getLogger(__name__) diff --git a/routers/x402.py b/routers/x402.py index 56cf02e..1660e02 100644 --- a/routers/x402.py +++ b/routers/x402.py @@ -23,7 +23,7 @@ router = APIRouter(tags=["x402"]) @router.get("/v1/x402/pricing", tags=["x402"], summary="Get x402 pricing for all paid operations") async def x402_pricing() -> dict[str, Any]: """Get the price list for pay-per-scrape operations.""" - from x402 import X402Handler + from pry_x402 import X402Handler return {"success": True, "data": X402Handler().get_stats()} @@ -37,7 +37,7 @@ async def x402_payment_request( Returns payment details (wallet, amount, asset) for the client to pay. """ - from x402 import create_payment_request + from pry_x402 import create_payment_request req = create_payment_request(operation, metadata) return {"success": True, "data": req} @@ -52,7 +52,7 @@ async def x402_verify_payment( amount_usd: float = Body(0.0), ) -> dict[str, Any]: """Verify a x402 payment has been settled on-chain via facilitator router.""" - from x402 import X402Handler + from pry_x402 import X402Handler result = await X402Handler().verify_payment( payment_id, tx_hash, network=network, asset=asset, amount_usd=amount_usd @@ -68,7 +68,7 @@ async def x402_require_payment( metadata: dict[str, Any] | None = Body(None), ) -> dict[str, Any]: """Generate a 402 Payment Required response for a paid endpoint.""" - from x402 import require_payment_legacy + from pry_x402 import require_payment_legacy return require_payment_legacy(operation, metadata) @@ -80,7 +80,7 @@ async def x402_batch_payment(payload: dict[str, Any] = Body(...)) -> dict[str, A Returns a PaymentRequired body with the combined amount. After paying, submit the tx to POST /v1/x402/batch-verify. """ - from x402 import create_batch_payment + from pry_x402 import create_batch_payment operations = payload.get("operations", []) if not isinstance(operations, list): @@ -94,7 +94,7 @@ async def x402_batch_payment(payload: dict[str, Any] = Body(...)) -> dict[str, A @router.post("/v1/x402/batch-verify", tags=["x402"], summary="Verify a batch x402 payment") async def x402_batch_verify(payload: dict[str, Any] = Body(...)) -> dict[str, Any]: """Verify the on-chain payment for a batch and mark it paid.""" - from x402 import verify_batch_payment + from pry_x402 import verify_batch_payment batch_id = payload.get("batch_id", "") tx_hash = payload.get("tx_hash", "") @@ -128,7 +128,7 @@ async def x402_pay( 4. Pry verifies the transaction through the facilitator router 5. Returns access token (payment_id) to use in X-Payment-Hash header """ - from x402 import X402Handler + from pry_x402 import X402Handler h = X402Handler() payment_id = uuid.uuid4().hex[:12] diff --git a/template_engine.py b/template_engine.py index f97801f..4453b96 100644 --- a/template_engine.py +++ b/template_engine.py @@ -12,7 +12,7 @@ import logging from pathlib import Path from typing import Any, cast -from extraction import JsonCssExtractionStrategy +from pry_extraction import JsonCssExtractionStrategy logger = logging.getLogger(__name__) diff --git a/tests/test_agency.py b/tests/test_agency.py index fdad7f4..78138e2 100644 --- a/tests/test_agency.py +++ b/tests/test_agency.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for white-label agency dashboard.""" -from agency import ( +from pry_agency import ( check_client_quota, create_agency, create_client, diff --git a/tests/test_api_surface_snapshot.py b/tests/test_api_surface_snapshot.py index 2e84cb6..049bdad 100644 --- a/tests/test_api_surface_snapshot.py +++ b/tests/test_api_surface_snapshot.py @@ -55,7 +55,7 @@ class TestX402PublicSurface: """The x402 shim must expose the same public API as before.""" def test_required_symbols_exist(self) -> None: - import x402 + import pry_x402 as x402 required = { "X402Asset", @@ -77,7 +77,7 @@ class TestX402PublicSurface: assert not missing, f"Missing public x402 symbols: {missing}" def test_enum_values_consistent(self) -> None: - import x402 + import pry_x402 as x402 assert x402.X402Scheme.EXACT.value == "exact" assert x402.X402Network.ETHEREUM.value == "ethereum" diff --git a/tests/test_compliance.py b/tests/test_compliance.py index e4a1ff5..227c92c 100644 --- a/tests/test_compliance.py +++ b/tests/test_compliance.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for legal compliance engine.""" -from compliance import ( +from pry_compliance import ( classify_tos, detect_jurisdiction, tag_sensitive_data, diff --git a/tests/test_costing.py b/tests/test_costing.py index 256f093..89cd3a2 100644 --- a/tests/test_costing.py +++ b/tests/test_costing.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for cost analytics engine.""" -from costing import ( +from pry_costing import ( DEFAULT_COST_TABLE, get_monthly_usage, record_usage, diff --git a/tests/test_enrichment.py b/tests/test_enrichment.py index 426ea29..0e7c4bc 100644 --- a/tests/test_enrichment.py +++ b/tests/test_enrichment.py @@ -3,9 +3,9 @@ # # Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper # Licensed under MIT. See LICENSE. -"""Tests for data enrichment pipeline.""" +"""Tests for data.enrichment pipeline.""" -from enrichment import ( +from pry_enrichment import ( TECH_PATTERNS, detect_tech_stack, extract_company_info, diff --git a/tests/test_freshness.py b/tests/test_freshness.py index 4ff27ef..722f304 100644 --- a/tests/test_freshness.py +++ b/tests/test_freshness.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for adaptive freshness scheduling.""" -from freshness import ( +from pry_freshness import ( calculate_adaptive_frequency, check_content_changed, compute_content_hash, diff --git a/tests/test_gdpr.py b/tests/test_gdpr.py index d8a944a..22072e3 100644 --- a/tests/test_gdpr.py +++ b/tests/test_gdpr.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for GDPR compliance portal.""" -from gdpr import ( +from pry_gdpr import ( check_consent, get_retention_policy, process_deletion, diff --git a/tests/test_infrastructure.py b/tests/test_infrastructure.py index da1f00e..498c444 100644 --- a/tests/test_infrastructure.py +++ b/tests/test_infrastructure.py @@ -7,7 +7,7 @@ import asyncio -from auth import AuthManager, base64_decode, base64_encode +from pry_auth import AuthManager, base64_decode, base64_encode from db import _has_sqlalchemy, get_db from observability import track_llm_call, track_request, track_scrape from tasks import JobQueue, JobStatus diff --git a/tests/test_intelligence.py b/tests/test_intelligence.py index b14c5b0..ab52a22 100644 --- a/tests/test_intelligence.py +++ b/tests/test_intelligence.py @@ -3,7 +3,7 @@ # # Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper # Licensed under MIT. See LICENSE. -"""Tests for competitive intelligence engine.""" +"""Tests for competitive.intelligence engine.""" import time from collections.abc import Iterator @@ -11,7 +11,7 @@ from collections.abc import Iterator import pytest from db import Base, get_engine -from intelligence import ( +from pry_intelligence import ( compute_field_statistics, detect_anomalies_numeric, generate_alert, diff --git a/tests/test_llm_fallback.py b/tests/test_llm_fallback.py index 1be1f9e..ba2e431 100644 --- a/tests/test_llm_fallback.py +++ b/tests/test_llm_fallback.py @@ -27,7 +27,7 @@ import pytest async def test_compliance_llm_fallback_merges_into_tos_result(): """When tos_result confidence is low, the LLM result should be merged in with the llm_enhanced flag set to True.""" - from compliance import run_compliance_check + from pry_compliance import run_compliance_check fake_llm = AsyncMock( return_value={ @@ -57,7 +57,7 @@ async def test_compliance_llm_fallback_merges_into_tos_result(): @pytest.mark.asyncio async def test_compliance_llm_fallback_preserves_result_on_error(): """If the LLM call raises, the regex result should be preserved (no crash).""" - from compliance import run_compliance_check + from pry_compliance import run_compliance_check fake_llm = AsyncMock(side_effect=RuntimeError("LLM down")) @@ -127,7 +127,7 @@ async def test_seo_llm_enhancement_fills_empty_critical_fields(): @pytest.mark.asyncio async def test_reconciliation_llm_enhance_function_exists(): """llm_enhance_reconciliation should be a callable that returns a dict.""" - from reconciliation import llm_enhance_reconciliation + from pry_reconciliation import llm_enhance_reconciliation fake_llm = AsyncMock(return_value={"is_same_entity": True}) @@ -150,7 +150,7 @@ async def test_reconciliation_llm_enhance_function_exists(): @pytest.mark.asyncio async def test_reconciliation_llm_enhance_handles_no_low_confidence(): """If all entities are high-confidence, the LLM should not be called.""" - from reconciliation import llm_enhance_reconciliation + from pry_reconciliation import llm_enhance_reconciliation fake_llm = AsyncMock(return_value={"is_same_entity": True}) @@ -170,7 +170,7 @@ async def test_reconciliation_llm_enhance_handles_no_low_confidence(): @pytest.mark.asyncio async def test_reconciliation_llm_enhance_handles_llm_error(): """If the LLM call raises, return a degraded result without crashing.""" - from reconciliation import llm_enhance_reconciliation + from pry_reconciliation import llm_enhance_reconciliation fake_llm = AsyncMock(side_effect=ConnectionError("timeout")) diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index d7e3a52..0989acb 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for pipeline hook system.""" -from pipeline import HOOK_POINTS, Pipeline +from pry_pipeline import HOOK_POINTS, Pipeline def test_pipeline_init() -> None: diff --git a/tests/test_pipelines.py b/tests/test_pipelines.py index e3cb839..0dab0a7 100644 --- a/tests/test_pipelines.py +++ b/tests/test_pipelines.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for pipeline builder.""" -from pipelines import ( +from pry_pipelines import ( STEP_TYPES, list_pipelines, run_pipeline, diff --git a/tests/test_quality.py b/tests/test_quality.py index 9293896..282aec4 100644 --- a/tests/test_quality.py +++ b/tests/test_quality.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for data quality SLA dashboard.""" -from quality import ( +from pry_quality import ( compute_completeness, compute_freshness, compute_null_rate, diff --git a/tests/test_reconciliation.py b/tests/test_reconciliation.py index 5a4fc55..454bfc3 100644 --- a/tests/test_reconciliation.py +++ b/tests/test_reconciliation.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for entity reconciliation.""" -from reconciliation import ( +from pry_reconciliation import ( VERTICAL_SCHEMAS, _build_field_map, _normalize_record, diff --git a/tests/test_referrals.py b/tests/test_referrals.py index 1e4e6aa..04608aa 100644 --- a/tests/test_referrals.py +++ b/tests/test_referrals.py @@ -9,8 +9,8 @@ from collections.abc import Iterator import pytest -from referrals import PROVIDER_CATALOG, ReferralTracker -from x402 import X402_PRICING, X402Handler +from pry_referrals import PROVIDER_CATALOG, ReferralTracker +from pry_x402 import X402_PRICING, X402Handler @pytest.fixture(autouse=True) diff --git a/tests/test_reports.py b/tests/test_reports.py index bac2085..64f9d8c 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for white-label report generation.""" -from reports import generate_report, list_reports +from pry_reports import generate_report, list_reports def test_generate_competitive_report() -> None: diff --git a/tests/test_review.py b/tests/test_review.py index 7500eb1..715e27c 100644 --- a/tests/test_review.py +++ b/tests/test_review.py @@ -5,7 +5,7 @@ # Licensed under MIT. See LICENSE. """Tests for human-in-the-loop review workflow.""" -from review import ( +from pry_review import ( REVIEW_STATUS, approve_review, get_review_queue, diff --git a/tests/test_x402_mcp_spec.py b/tests/test_x402_mcp_spec.py index 341e68e..d43de37 100644 --- a/tests/test_x402_mcp_spec.py +++ b/tests/test_x402_mcp_spec.py @@ -18,7 +18,7 @@ from pry_mcp import ( make_fallback_server, register_all, ) -from x402 import ( +from pry_x402 import ( X402_PRICING, FacilitatorRouter, X402Asset, diff --git a/x402_middleware.py b/x402_middleware.py index 1049ec0..605f435 100644 --- a/x402_middleware.py +++ b/x402_middleware.py @@ -25,7 +25,7 @@ import logging from datetime import UTC, datetime from typing import Any -from x402 import X402_PRICING, X402Handler +from pry_x402 import X402_PRICING, X402Handler logger = logging.getLogger(__name__) @@ -91,7 +91,7 @@ class X402Middleware: # Check pre-verified batch payment if batch_id_header: - from x402 import is_batch_paid + from pry_x402 import is_batch_paid if is_batch_paid(batch_id_header): await self.app(scope, receive, send)