pybliometrics-dev / pybliometrics

Python-based API-Wrapper to access Scopus
https://pybliometrics.readthedocs.io/en/stable/
Other
410 stars 128 forks source link

How to configure pybliometrics without requiring human response #213

Closed astrochun closed 2 years ago

astrochun commented 2 years ago

Feature request?

I think this is a feature request but perhaps more a question/solution.

While the scopus.utils.create_config works well for humans through a prompt response, I'm finding a new problem with building my codebase with CI using pybliometrics. A prompt response is required. I can have the API key stored as a secret variable, but since it's a prompt, I'm hitting the snag. I'm wondering if there is a workaround available or to add the option of enable the input of API keys (i.e., add an optional input parameter for create_config().

Michael-E-Rose commented 2 years ago

Passing parameters to the create_config() might be an interesting option. Since create_config() does more things than just setting a key, it should not be the preferred solution for most users. But it can solve the problem of automating pybliometrics, that I also face somewhere else.

As an immediate solution to your problem I propose something else however. Generate the config file yourself automatically before calling pybliometrics. create_config() will not fire up if the configuration file exists.

astrochun commented 2 years ago

As an immediate solution to your problem I propose something else however. Generate the config file yourself automatically before calling pybliometrics. create_config() will not fire up if the configuration file exists.

@Michael-E-Rose sure. But as you pointed out, there are other things that are done (e.g., specifying directories for pybliometrics). Those default paths can differ for Window/Linux/MacOS. Note also that since these are CI runners, the username and home path can differ. Thus, from what I can tell, the best way to ensure greatest compatibility is essentially for me to copy/paste create_config() and make the input parameter requirement in my codebase.

astrochun commented 2 years ago

Thanks @Michael-E-Rose. Any chance to allow for the token as an optional input?

Michael-E-Rose commented 2 years ago

I was thinking about it yesternight. The reason I decided against is the following: The simplest solution for the token would be the same as for the key, i.e. to ask if no value is provided. Since most people would leave the insttoken parameter deliberately empty, pybliometrics would still prompt for a token. And this breaks the CI.

The alternative is to use the provided token only if a key is provided as well. This would ignore cases where (accidentally) a token is provided but not a key, which should result in a warning. Two prompts would come in any case where the key parameter is empty.

Does your setting require an InstToken?

astrochun commented 2 years ago

Does your setting require an InstToken?

Unfortunately it does. I realized this after I created a separate create_config that our CI system is not whitelisted. Yes, #1 would break CI if an optional token input is not provided.

I wonder if having a prompt boolean option could be a solution. Though this is more of a hack than a long-term solution.

Michael-E-Rose commented 2 years ago

What about this solution, does it help?

astrochun commented 2 years ago

What about this solution, does it help?

👍

Yes, I believe this will work for what we need. I created a simple venv and tried it out.

(venv) (base) ➜  pybliometrics git:(master) ✗ ipython
Python 3.8.8 (default, Apr 13 2021, 12:59:45) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pybliometrics.scopus.utils import create_config

In [2]: create_config([api_key], instToken)  # masked
Configuration file successfully created at /Users/***/.pybliometrics/config.ini
For details see https://pybliometrics.rtfd.io/en/stable/configuration.html.

Note that the instToken is generally assigned to only one API key. Namely that this could be a problem if a list of keys are provided. This is very very minor issue though.

Michael-E-Rose commented 2 years ago

I'm glad it helps!

Yes, the InstToken issue is a general problem. But Scopus never replied to my requests for InstTokens, so cannot experiment -_-

astrochun commented 2 years ago

I'm glad it helps!

Yes, the InstToken issue is a general problem. But Scopus never replied to my requests for InstTokens, so cannot experiment -_-

Hmm, I asked by sending a request through the dev.elsevier.com and after some back/forth they gave me one.

I think in the mean time, I can be of help with such testing.