Search, chat and research over parliamentary speeches and documents
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
1.1 KiB

"""Locate the project root and make it importable.
Scripts under ``scripts/`` are run directly (``python scripts/make_embeddings.py``), so
the repository root is not on ``sys.path`` and relative paths would resolve against
whatever directory the caller happened to be in. Importing this module fixes both,
deriving the root from this file's own location.
The predecessor hardcoded ``/home/lasse/riksdagen`` in 22 files, which is why the
project could only ever run on one machine.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent
# Bulk source data — downloaded corpora, not repository content. Kept outside the
# tree by default so a checkout stays small; point PLENUM_DATA_DIR at an existing
# download to reuse one.
DATA_DIR = Path(os.environ.get("PLENUM_DATA_DIR") or PROJECT_ROOT / "data")
def set_project_root() -> None:
"""Put the project root on ``sys.path`` and make it the working directory."""
root = str(PROJECT_ROOT)
if root not in sys.path:
sys.path.insert(0, root)
os.chdir(root)
set_project_root()