Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate using PyStow for API configuration #142

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

cthoyt
Copy link
Collaborator

@cthoyt cthoyt commented Jun 24, 2022

  • Replace builtin code for configuration access and writing
  • Write documentation on how this works

@cthoyt cthoyt marked this pull request as ready for review June 24, 2022 09:18
@cthoyt
Copy link
Collaborator Author

cthoyt commented Jul 22, 2022

@cmungall @pkalita-lbl can you please set the BIOPORTAL_API_KEY environment variable for GHA to make this test pass?

@pkalita-lbl
Copy link
Collaborator

Sorry I don't have permission to do that either

@pkalita-lbl
Copy link
Collaborator

pkalita-lbl commented Jul 25, 2022

can you please set the BIOPORTAL_API_KEY environment variable for GHA

I think I have permission to do this now. I can add my BioPortal API key as a repo secret named BIOPORTAL_API_KEY. That's what you're after right?

@cthoyt
Copy link
Collaborator Author

cthoyt commented Jul 25, 2022

@pkalita-lbl yes that's it

@pkalita-lbl
Copy link
Collaborator

Done!

@cthoyt cthoyt requested a review from pkalita-lbl July 25, 2022 23:06
Copy link
Collaborator

@pkalita-lbl pkalita-lbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to start fresh by clearing out my old stored keys (in ~/Library/Application\ Support/ontology-access-kit/, for what it's worth) and test out these changes but I ran into a bit of trouble. See comments below.

Also when I tried running the BioPortal tests without an API key set, like so:

python -m unittest -v tests/test_implementations/test_bioportal.py

The test setup errored out instead of skipping the test cases:

Traceback (most recent call last):
  File "/Users/PAKalita/Work/ontology-access-kit/tests/test_implementations/test_bioportal.py", line 25, in setUp
    impl = cls()
  File "<string>", line 8, in __init__
  File "/Users/PAKalita/Work/ontology-access-kit/src/oaklib/implementations/ontoportal/ontoportal_implementation_base.py", line 53, in __post_init__
    self.client = self.ontoportal_client_class()
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/ontoportal_client/api.py", line 113, in __init__
    api_key = pystow.get_config(self.name, value_key, raise_on_missing=True)
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/pystow/config_api.py", line 102, in get_config
    raise ValueError(f"Could not look up {module}/{key} and no default given")
ValueError: Could not look up bioportal/api_key and no default given

Configuration for an arbitrary `key` (e.g., `bioportal_api_token`)
can be set in the following ways:

1. Set `OAKLIB_<key>` in the environment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by this because it seems like just BIOPORTAL_API_KEY is the required when using an environment variable. I.e. this works:

BIOPORTAL_API_KEY=[redacted] runoak -i bioportal: search swim

As opposed to:

OAKLIB_BIOPORTAL_API_KEY=[redacted] runoak -i bioportal: search swim

2. Create a configuration file `~/.config/oaklib.ini`
and set the `[oaklib]` section in it with the given key-value pair like
`<key> = <value>`
3. Use the CLI command `runoak set-apikey <key> <value>` to automatically create
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried running this:

runoak set-apikey -e bioportal [redacted]

(also, note the -e is required) I got this error:

Traceback (most recent call last):
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/bin/runoak", line 5, in <module>
    main()
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/PAKalita/Work/ontology-access-kit/src/oaklib/cli.py", line 2220, in set_apikey
    set_apikey_value(endpoint, keyval)
  File "/Users/PAKalita/Work/ontology-access-kit/src/oaklib/utilities/apikey_manager.py", line 42, in set_apikey_value
    pystow.write_config(APP_NAME, key, value)
  File "/Users/PAKalita/Work/ontology-access-kit/.venv/lib/python3.9/site-packages/pystow/config_api.py", line 135, in write_config
    cfp.set(module, key, value)
  File "/Users/PAKalita/.pyenv/versions/3.9.11/lib/python3.9/configparser.py", line 1204, in set
    super().set(section, option, value)
  File "/Users/PAKalita/.pyenv/versions/3.9.11/lib/python3.9/configparser.py", line 902, in set
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'oaklib'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants