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
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
#----------------------------------------------
- name: Run tests
run: poetry run python -m unittest discover
env:
BIOPORTAL_API_KEY: ${{ secrets.BIOPORTAL_API_KEY }}

#----------------------------------------------
# coverage report
Expand All @@ -93,6 +95,8 @@ jobs:
poetry run coverage run -m unittest discover
poetry run coverage xml
poetry run coverage report -m
env:
BIOPORTAL_API_KEY: ${{ secrets.BIOPORTAL_API_KEY }}

#----------------------------------------------
# upload coverage results
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ runoak -i obolibrary:go.obo viz GO:0005773

## Configuration

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'

and populate the appropriate configuration file.

OAK uses [`pystow`](https://github.com/cthoyt/pystow) for caching. By default,
this goes inside `~/.data/`, but can be configured following
[these instructions](https://github.com/cthoyt/pystow#%EF%B8%8F%EF%B8%8F-configuration).
Expand Down
Loading