Skip to content

Commit e683b32

Browse files
authored
Merge pull request #4 from labgem/failfast
Fail fast
2 parents 7de641e + 28850db commit e683b32

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎metapang/app/profile/__init__.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
from sourmash.save_load import SaveSignaturesToLocation
1212

1313
from metapang.core.graph import PWGraph, PWGraphAnnotator
14-
from metapang.core.index.dbg import MetagraphCLI, MetagraphQueryOptions
14+
from metapang.core.index.dbg import (
15+
MetagraphCLI,
16+
MetagraphQueryOptions,
17+
ensure_metagraph,
18+
)
1519
from metapang.core.index.search import IndexBuilder, IndexSearch, IndexType
1620
from metapang.core.profile.strains import (
1721
StrainProfile,
@@ -815,6 +819,8 @@ def profile(
815819
)
816820
return
817821

822+
ensure_metagraph(metagraph_path)
823+
818824
collection, collection_version, pangenome = parse_collection_name_version(pangbank)
819825

820826
if collection == LOCAL_COLLECTION:

‎metapang/app/search/pangenome.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import rich_click as click
55

66
from metapang.core.graph import PWGraph, PWGraphAnnotator
7-
from metapang.core.index.dbg import MetagraphCLI, MetagraphQueryOptions
7+
from metapang.core.index.dbg import (
8+
MetagraphCLI,
9+
MetagraphQueryOptions,
10+
ensure_metagraph,
11+
)
812
from metapang.logger import mp_log
913
from metapang.pg.api import PanGBank_Cache, parse_collection_name_version
1014
from metapang.pg.local import LOCAL_COLLECTION, LocalCacheProxy, is_built, local_dir
@@ -107,6 +111,8 @@ def pangenome(
107111

108112
config = ctx.obj.get("config")
109113

114+
ensure_metagraph(metagraph_path)
115+
110116
if pangbank:
111117
collection, collection_version, pangenome_name = (
112118
parse_collection_name_version(pangbank)

‎metapang/core/index/dbg.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import msgspec
66

7-
from metapang.exceptions import MetaPanG_ConfigError
7+
from metapang.exceptions import MetaPanG_ConfigError, MetaPanG_MissingTool
88
from metapang.logger import mp_log
99
from metapang.utils.execution import (
1010
CLIExecutor,
@@ -16,6 +16,17 @@
1616
from metapang.utils.time import timer
1717

1818

19+
def ensure_metagraph(executable: str = "metagraph") -> str:
20+
try:
21+
return find_executable(executable)
22+
except MetaPanG_MissingTool as e:
23+
raise MetaPanG_MissingTool(
24+
f"metagraph binary '{executable}' not found on PATH. Install metagraph "
25+
"or pass --metagraph-path. "
26+
"See https://metapang.readthedocs.io/en/latest/installation.html"
27+
) from e
28+
29+
1930
@cli_dataclass
2031
class MetagraphBuildOptions:
2132
"""Options for the metagraph `build` command."""

0 commit comments

Comments
 (0)