| import logging |
| from pathlib import Path |
| import os, subprocess |
| import sys |
| import torch |
| from scripts.quiet import install_quiet |
|
|
| def setup_logging( |
| level=logging.INFO, |
| fmt="%(message)s", |
| scope="legalrag", |
| ): |
| """ |
| Configure logging for the LegalRAG repository. |
| |
| This function removes existing handlers attached to loggers |
| under the given scope and installs a clean StreamHandler. |
| """ |
| base = logging.getLogger(scope) |
| base.setLevel(level) |
|
|
| |
| for name, logger in logging.root.manager.loggerDict.items(): |
| if name == scope or name.startswith(scope + "."): |
| lg = logging.getLogger(name) |
| for h in lg.handlers[:]: |
| lg.removeHandler(h) |
| lg.propagate = False |
|
|
| |
| handler = logging.StreamHandler() |
| handler.setFormatter(logging.Formatter(fmt)) |
| base.addHandler(handler) |
|
|
| def run(cmd, cwd=None): |
| res = subprocess.run(cmd, cwd=cwd, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| if res.returncode != 0: |
| tail="\n".join(res.stdout.splitlines()[-40:]) |
| raise RuntimeError(f"Command failed: {cmd}\n--- output tail ---\n{tail}") |
| return res.stdout |
|
|
| install_quiet() |
| setup_logging() |
| run([sys.executable, "-m", "pip", "install", "--no-cache-dir", "-r", "requirements.txt"]) |
|
|
| |
|
|
| run([sys.executable, "-m", "data.download_data"]) |
|
|
| torch.cuda.empty_cache() |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
|
|
|
|
|
|