fix(code): Load data script from anywhere
Allow loading the script both through quarto using full absolute path and through the command line using (I believe) a relative path.
This commit is contained in:
parent
38099c3358
commit
7241b62efe
1 changed files with 5 additions and 2 deletions
|
@ -1,7 +1,10 @@
|
|||
import io
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from src import load_yaml
|
||||
try:
|
||||
import src.load_yaml as yaml # for quarto document scripts
|
||||
except ModuleNotFoundError:
|
||||
import load_yaml as yaml # for directly running the package
|
||||
from pandas import DataFrame, read_csv
|
||||
|
||||
DEFAULT_YAML_PATH = Path("02-data/processed/relevant")
|
||||
|
@ -26,7 +29,7 @@ def to_tsv(studies: list[dict]) -> str:
|
|||
|
||||
def from_yml(yml_path: Path | str = DEFAULT_YAML_PATH) -> DataFrame:
|
||||
yml_path = Path(yml_path).resolve()
|
||||
studies = load_yaml.load(yml_path)
|
||||
studies = yaml.load(yml_path)
|
||||
if not studies:
|
||||
raise ValueError(f"No studies found in directory {yml_path.resolve()}")
|
||||
tsv = to_tsv(studies)
|
||||
|
|
Loading…
Reference in a new issue