Knowledge-Graph-Hub / universalizer

The KG-Hub Universalizer provides functions for knowledge graph cleanup and identifier normalization.
BSD 3-Clause "New" or "Revised" License
3 stars 2 forks source link

Default argument parsing isn't working correctly #23

Open caufieldjh opened 1 year ago

caufieldjh commented 1 year ago

Running universalizer like this works as expected:

$ universalizer run local_graph/ --update_categories --contexts obo

But omit the contexts argument and it tries to use the default contexts, failing in the process:

$ universalizer run local_graph/ --update_categories
Input path: local_graph/
Will update categories.
Found these graph files:['local_graph/merged-kg_nodes.tsv', 'local_graph/merged-kg_edges.tsv']
Traceback (most recent call last):
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/bin/universalizer", line 5, in <module>
    cli()
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/harry/universalizer/universalizer/cli.py", line 74, in run
    if clean_and_normalize_graph(
  File "/home/harry/universalizer/universalizer/norm.py", line 85, in clean_and_normalize_graph
    remap_these_nodes = make_id_maps(nodepath, os.path.dirname(nodepath), contexts)
  File "/home/harry/universalizer/universalizer/norm.py", line 192, in make_id_maps
    curie_contexts = load_multi_context(contexts)
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/prefixmaps/io/parser.py", line 37, in load_multi_context
    ctxt.combine(load_context(n, refresh=refresh))
  File "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/prefixmaps/io/parser.py", line 54, in load_context
    with open(data_path / f"{name}.csv", encoding="utf-8") as file:
FileNotFoundError: [Errno 2] No such file or directory: "/home/harry/.cache/pypoetry/virtualenvs/universalizer-fyE8bHoK-py3.9/lib/python3.9/site-packages/prefixmaps/data/['obo',.csv"

The context names appear to be parsed incorrectly.

It's also not possible to pass multiple space-delimited contexts:

$ universalizer run local_graph/ --update_categories --contexts obo bioregistry.upper
Usage: universalizer run [OPTIONS] INPUT_PATH
Try 'universalizer run --help' for help.

Error: Got unexpected extra argument (bioregistry.upper)

This works if they're placed in quotes, which is fine, but that should be in the documentation.