feat: decouple market from shared_lib, add app-owned models
Phase 1-3 of decoupling: - path_setup.py adds project root to sys.path - Market-owned models in market/models/ (market, market_place) - All imports updated: shared.infrastructure, shared.db, shared.browser, etc. - MarketPlace uses container_type/container_id instead of post_id FK Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,9 +7,9 @@ from typing import Dict, Set
|
||||
from ..http_client import configure_cookies
|
||||
from ..get_auth import login
|
||||
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
from utils import log
|
||||
from shared.utils import log
|
||||
|
||||
# DB: persistence helpers
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from bs4 import BeautifulSoup
|
||||
from urllib.parse import urlparse, urljoin
|
||||
|
||||
from ._anchor_text import _anchor_text
|
||||
from suma_browser.app.bp.browse.services.slugs import product_slug_from_href
|
||||
from bp.browse.services.slugs import product_slug_from_href
|
||||
from .APP_ROOT_PLACEHOLDER import APP_ROOT_PLACEHOLDER
|
||||
|
||||
def _rewrite_links_fragment(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from urllib.parse import urljoin
|
||||
from config import config
|
||||
from utils import log
|
||||
from shared.config import config
|
||||
from shared.utils import log
|
||||
from ...listings import scrape_products
|
||||
|
||||
async def capture_category(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Dict, Set
|
||||
from .capture_category import capture_category
|
||||
from .capture_sub import capture_sub
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
|
||||
async def capture_product_slugs(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from urllib.parse import urljoin
|
||||
from urllib.parse import urljoin
|
||||
from config import config
|
||||
from utils import log
|
||||
from shared.config import config
|
||||
from shared.utils import log
|
||||
from ...listings import scrape_products
|
||||
|
||||
async def capture_sub(
|
||||
|
||||
@@ -6,12 +6,12 @@ import httpx
|
||||
|
||||
|
||||
from ...html_utils import to_fragment
|
||||
from suma_browser.app.bp.browse.services.slugs import suma_href_from_html_slug
|
||||
|
||||
from bp.browse.services.slugs import suma_href_from_html_slug
|
||||
|
||||
from config import config
|
||||
|
||||
from utils import log
|
||||
from shared.config import config
|
||||
|
||||
from shared.utils import log
|
||||
|
||||
# DB: persistence helpers
|
||||
from ...product.product_detail import scrape_product_detail
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import asyncio
|
||||
from typing import Dict, List, Set
|
||||
from config import config
|
||||
from utils import log
|
||||
from shared.config import config
|
||||
from shared.utils import log
|
||||
from .fetch_and_upsert_product import fetch_and_upsert_product
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
from typing import Dict
|
||||
from urllib.parse import urljoin
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
def rewrite_nav(nav: Dict[str, Dict], nav_redirects:Dict[str, str]):
|
||||
if nav_redirects:
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import Optional, Dict, Any, List
|
||||
from urllib.parse import urljoin
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
class LoginFailed(Exception):
|
||||
def __init__(self, message: str, *, debug: Dict[str, Any]):
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
from typing import Optional
|
||||
from bs4 import BeautifulSoup
|
||||
from urllib.parse import urljoin
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import secrets
|
||||
from typing import Optional, Dict
|
||||
|
||||
import httpx
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
_CLIENT: httpx.AsyncClient | None = None
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ from urllib.parse import parse_qsl, urlencode, urljoin, urlparse, urlunparse
|
||||
|
||||
|
||||
from .http_client import fetch
|
||||
from suma_browser.app.bp.browse.services.slugs import product_slug_from_href
|
||||
from suma_browser.app.bp.browse.services.state import (
|
||||
from bp.browse.services.slugs import product_slug_from_href
|
||||
from bp.browse.services.state import (
|
||||
KNOWN_PRODUCT_SLUGS,
|
||||
_listing_page_cache,
|
||||
_listing_page_ttl,
|
||||
@@ -16,8 +16,8 @@ from suma_browser.app.bp.browse.services.state import (
|
||||
_listing_variant_ttl,
|
||||
now,
|
||||
)
|
||||
from utils import normalize_text, soup_of
|
||||
from config import config
|
||||
from shared.utils import normalize_text, soup_of
|
||||
from shared.config import config
|
||||
|
||||
|
||||
def parse_total_pages_from_text(text: str) -> Optional[int]:
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Tuple, Optional
|
||||
from urllib.parse import urlparse, urljoin
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from config import config
|
||||
from shared.config import config
|
||||
from .http_client import fetch # only fetch; define soup_of locally
|
||||
#from .. import cache_backend as cb
|
||||
#from ..blacklist.category import is_category_blocked # Reverse map: slug -> label
|
||||
|
||||
@@ -17,7 +17,7 @@ from models.market import (
|
||||
Listing,
|
||||
ListingItem,
|
||||
)
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
|
||||
# --- Models are unchanged, see original code ---
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict
|
||||
from models.market import (
|
||||
ProductLog,
|
||||
)
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
|
||||
|
||||
async def log_product_result(ok: bool, payload: Dict) -> None:
|
||||
|
||||
@@ -7,7 +7,7 @@ from models.market import (
|
||||
LinkError,
|
||||
LinkExternal,
|
||||
)
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
|
||||
# --- Models are unchanged, see original code ---
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from models.market import (
|
||||
NavTop,
|
||||
NavSub,
|
||||
)
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from sqlalchemy import (
|
||||
from models.market import (
|
||||
SubcategoryRedirect,
|
||||
)
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
|
||||
# --- Models are unchanged, see original code ---
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ from models.market import (
|
||||
ProductNutrition,
|
||||
ProductAllergen
|
||||
)
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
|
||||
from ._get import _get
|
||||
from .log_product_result import _log_product_result
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
from typing import Dict, List, Union
|
||||
from urllib.parse import urlparse
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ..registry import extractor
|
||||
|
||||
@extractor
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Dict, List
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ...html_utils import absolutize_fragment
|
||||
from ..registry import extractor
|
||||
from ..helpers.desc import (
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Dict, Union
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ..registry import extractor
|
||||
from ..helpers.price import parse_price, parse_case_size
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Dict, List
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ..registry import extractor
|
||||
|
||||
@extractor
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ..registry import extractor
|
||||
from ..helpers.desc import (
|
||||
split_description_container, find_description_container,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Dict
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ..registry import extractor
|
||||
|
||||
@extractor
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Dict
|
||||
from bs4 import BeautifulSoup
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ..registry import extractor
|
||||
|
||||
@extractor
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
from __future__ import annotations
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from bs4 import BeautifulSoup, NavigableString, Tag
|
||||
from utils import normalize_text
|
||||
from shared.utils import normalize_text
|
||||
from ...html_utils import absolutize_fragment
|
||||
from .text import clean_title, is_blacklisted_heading
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
|
||||
def split_description_container(desc_el: Tag) -> Tuple[str, List[Dict]]:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import List, Optional
|
||||
from urllib.parse import urljoin, urlparse
|
||||
from config import config
|
||||
from shared.config import config
|
||||
|
||||
def first_from_srcset(val: str) -> Optional[str]:
|
||||
if not val:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
import re
|
||||
from utils import normalize_text
|
||||
from config import config
|
||||
from shared.utils import normalize_text
|
||||
from shared.config import config
|
||||
|
||||
def clean_title(t: str) -> str:
|
||||
t = normalize_text(t)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Dict, Tuple, Union
|
||||
from utils import soup_of
|
||||
from shared.utils import soup_of
|
||||
from ..http_client import fetch
|
||||
from ..html_utils import absolutize_fragment
|
||||
from suma_browser.app.bp.browse.services.slugs import product_slug_from_href
|
||||
from bp.browse.services.slugs import product_slug_from_href
|
||||
from .registry import REGISTRY, merge_missing
|
||||
from . import extractors as _auto_register # noqa: F401 (import-time side effects)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user