Skip to content

Commit

Permalink
More effectively use paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Aug 14, 2023
1 parent 0ad5248 commit f8031fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
20 changes: 17 additions & 3 deletions src/biomappings/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""The biomappings CLI."""

import sys
from pathlib import Path

import click
from more_click import run_app
Expand All @@ -23,12 +24,25 @@ def main():
if get_git_hash() is not None:

@main.command()
@click.option("--path", type=click.Path(), help="A predictions TSV file path")
def web(path):
@click.option("--predictions-path", type=click.Path(), help="A predictions TSV file path")
@click.option("--positives-path", type=click.Path(), help="A positives curation TSV file path")
@click.option("--negatives-path", type=click.Path(), help="A negatives curation TSV file path")
@click.option("--unsure-path", type=click.Path(), help="An unsure curation TSV file path")
def web(
predictions_path: Path,
positives_path: Path,
negatives_path: Path,
unsure_path: Path,
):
"""Run the biomappings web app."""
from .wsgi import get_app

app = get_app(predictions_path=path)
app = get_app(
predictions_path=predictions_path,
positives_path=positives_path,
negatives_path=negatives_path,
unsure_path=unsure_path,
)
run_app(app, with_gunicorn=False)

@main.command()
Expand Down
5 changes: 2 additions & 3 deletions src/biomappings/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import csv
import itertools as itt
import os
from collections import defaultdict
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -167,9 +166,9 @@ def target_curie(self) -> str:
return f"{self.target_prefix}:{self.target_identifier}"


def get_resource_file_path(fname) -> str:
def get_resource_file_path(fname) -> Path:
"""Get a resource by its file name."""
return os.path.join(RESOURCE_PATH, fname)
return RESOURCE_PATH.joinpath(fname)


def _load_table(fname) -> List[Dict[str, str]]:
Expand Down
12 changes: 7 additions & 5 deletions src/biomappings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

import os
import re
from pathlib import Path
from subprocess import CalledProcessError, check_output # noqa: S404
from typing import Any, Mapping, Optional, Tuple

import bioregistry

HERE = os.path.dirname(os.path.abspath(__file__))
RESOURCE_PATH = os.path.abspath(os.path.join(HERE, "resources"))
DOCS = os.path.abspath(os.path.join(HERE, os.pardir, os.pardir, "docs"))
IMG = os.path.join(DOCS, "img")
DATA = os.path.join(DOCS, "_data")
HERE = Path(__file__).parent.resolve()
ROOT = HERE.parent.parent.resolve()
RESOURCE_PATH = HERE.joinpath("resources")
DOCS = ROOT.joinpath("docs")
IMG = DOCS.joinpath("img")
DATA = DOCS.joinpath("_data")

OVERRIDE_MIRIAM = {
# ITO is very messy (combines mostly numbers with a few
Expand Down

0 comments on commit f8031fb

Please sign in to comment.