From 03ea5047c86714d1978fda63570291b65a9df29c Mon Sep 17 00:00:00 2001 From: nanglo123 Date: Tue, 6 Aug 2024 15:49:19 -0400 Subject: [PATCH] Add conditional to extract curie version if not provided --- src/pyobo/api/names.py | 2 ++ src/pyobo/cli/lookup.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pyobo/api/names.py b/src/pyobo/api/names.py index a2cd003a..5546eeb6 100644 --- a/src/pyobo/api/names.py +++ b/src/pyobo/api/names.py @@ -32,6 +32,8 @@ def get_name_by_curie(curie: str, *, version: Optional[str] = None) -> Optional[str]: """Get the name for a CURIE, if possible.""" + if version is None: + version = get_version(curie.split(":")[0]) prefix, identifier = normalize_curie(curie) if prefix and identifier: return get_name(prefix, identifier, version=version) diff --git a/src/pyobo/cli/lookup.py b/src/pyobo/cli/lookup.py index 7d4746f0..06ff62e9 100644 --- a/src/pyobo/cli/lookup.py +++ b/src/pyobo/cli/lookup.py @@ -282,7 +282,7 @@ def ancestors(prefix: str, identifier: str, force: bool, version: Optional[str]) """Look up ancestors.""" curies = get_ancestors(prefix=prefix, identifier=identifier, force=force, version=version) for curie in sorted(curies or []): - click.echo(f"{curie}\t{get_name_by_curie(curie)}") + click.echo(f"{curie}\t{get_name_by_curie(curie, version)}") @lookup.command() @@ -295,7 +295,7 @@ def descendants(prefix: str, identifier: str, force: bool, version: Optional[str """Look up descendants.""" curies = get_descendants(prefix=prefix, identifier=identifier, force=force, version=version) for curie in sorted(curies or []): - click.echo(f"{curie}\t{get_name_by_curie(curie)}") + click.echo(f"{curie}\t{get_name_by_curie(curie, version)}") @lookup.command()