-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: main
Are you sure you want to change the base?
Conversation
cthoyt
commented
Jun 24, 2022
•
edited
Loading
edited
- Replace builtin code for configuration access and writing
- Write documentation on how this works
@cmungall @pkalita-lbl can you please set the |
Sorry I don't have permission to do that either |
I think I have permission to do this now. I can add my BioPortal API key as a repo secret named |
@pkalita-lbl yes that's it |
Done! |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'