pryscraper/paths.py
cryptorugmunch a7c30b12cd
Some checks failed
CI / lint (push) Failing after 2s
CI / typecheck (push) Failing after 2s
CI / test (push) Failing after 2s
CI / Secret scan (gitleaks) (push) Failing after 1s
CI / Security audit (bandit) (push) Failing after 2s
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.
2026-07-02 21:51:25 +02:00

79 lines
2 KiB
Python

"""Pry - centralized data-directory resolution.
Single source of truth for the on-disk data root. Override at runtime via
the PRY_DATA_DIR environment variable.
Examples:
PRY_DATA_DIR=/var/lib/pry # systemd / docker production
PRY_DATA_DIR=/tmp/pry-test-$$ # CI scratch space
All other modules should import PRY_DATA_DIR (or use subdir(name)) instead
of hardcoding Path("~/.pry/x").
Part of Pry - https://git.rugmunch.io/RugMunchMedia/pryscraper
Licensed under MIT. See LICENSE.
"""
# SPDX-License-Identifier: MIT
# Copyright (c) 2026 Rug Munch Media LLC
#
# Part of Pry - https://git.rugmunch.io/RugMunchMedia/pryscraper
# Licensed under MIT. See LICENSE.
from __future__ import annotations
import os
from pathlib import Path
# Single source of truth. Override with PRY_DATA_DIR env var.
PRY_DATA_DIR: Path = Path(os.getenv("PRY_DATA_DIR", "~/.pry")).expanduser().resolve()
# Known subdirectories. Not enforced - subdir() accepts any name - but
# useful for documentation and tooling that wants to enumerate them.
SUBDIRS: tuple[str, ...] = (
"accounts",
"actors",
"agency",
"commerce",
"costing",
"freshness",
"gdpr",
"gdpr_real",
"intel",
"jobs",
"llm_usage",
"monitors",
"pipelines",
"proxies",
"quality",
"referrals",
"reports",
"reports_real",
"reviews",
"seo",
"sessions",
"structure",
"training",
"vault",
"webhooks",
"x402",
)
def subdir(name: str) -> Path:
"""Get a subdirectory under PRY_DATA_DIR, creating it if needed.
Use this in modules that write files: `from paths import subdir; d = subdir("quality")`.
"""
path = PRY_DATA_DIR / name
path.mkdir(parents=True, exist_ok=True)
return path
def ensure_data_dir() -> Path:
"""Ensure PRY_DATA_DIR itself exists. Returns the path.
Call once at process startup if you want the root created eagerly
(e.g., before any subdir access).
"""
PRY_DATA_DIR.mkdir(parents=True, exist_ok=True)
return PRY_DATA_DIR