pybliometrics-dev / pybliometrics

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

Feat 311: init() function to initialize the library. #315

Closed nils-herrmann closed 6 months ago

nils-herrmann commented 7 months ago

This feature implements a new initialization pipeline by implementing the init() function. The new code logic can be found in the startup.py file. Here is an example:

from pybliometrics.scopus import *
init('/Users/user/.config/pybiliometrics.cfg',
     ['abc', 'def', 'ghi'])
ar = AbstractRetrieval('10.1016/j.sigpro.2023.109309')

here is another:

from pybliometrics.scopus import AbstractRetrieval, init
init()
ar = AbstractRetrieval('S0049089X1200097X')

The feature handles two scenarios in case no init() is called:

  1. A config file exists in one of the default directories (Old users): A warning is raised and the library works normally
  2. No config file exists: A FileNotFoundError is raised with the message No configuration file found, please create one by initialize the scopus library with init()

The feature handles three scenarios in case the init() is called:

  1. If the config file exists nothing is done
  2. If the config file does not exist it is created (with the keys)
  3. If a config file exists but another directory or keys are provided it gets overwritten

Some To-Do's after the code review:

nils-herrmann commented 6 months ago

In general this strikes me as overly complex. There's many new functions and variables and I do not yet understand why they are necessary.

The implementation of init() resulted more complex than I thought. Overall the functions are used to avoid having static global variables. Since at import the user has not had the opportunity to use init(), the configuration has to somehow be able to be changed post import

nils-herrmann commented 6 months ago

One reason the change became so complex is because of flexibility that's not been requested not desirable. In some points please revert to the previous state.

I get your point. Sorry for that.

nils-herrmann commented 6 months ago

I changed the code to have following features:

  1. A global CONFIG variable that is passed by the init() function. This variable has to be accessed by other parts of the library via the function get_config() to overwrite the initial value of None after import. Note: There is no way to have a global static config variable because the config file gets defined after import by the user using init().
  2. The init() function now reads or creates the config file
  3. The library throws a FileNotFoundError if the library was not initialised. The error message looks like this: FileNotFoundError: No configuration file found. Please initialize Pybliometrics with init(). For more information visit: https://pybliometrics.readthedocs.io/en/stable/configuration.html.
  4. A check_sections() function that checks if the config file has all the needed sections.

Notes: