pybliometrics-dev / pybliometrics

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

Easy way to set up "portable" behavior #296

Closed claell closed 7 months ago

claell commented 11 months ago

pybliometrics version: 3.5.2

Affected classes: -

Expected behavior: Currently, the configuration contains absolute paths to a user's directory. That way, a project is not really portable.

Either the config is stored on each machine individually (then the API key needs to be set on every machine, see #294), or the config location is changed to a synced folder (then the directories are not portable).

Workaround might be to set the directories at runtime.

Michael-E-Rose commented 10 months ago

The configuration is not portable, no. But that's why by default it's not part of the project you're running pybliometrics in. Yet you can set it up that way, see https://pybliometrics.readthedocs.io/en/stable/configuration.html#custom-location.

My intention was to let each user of say a shared repo where pybliometrics is part of set its own location. Meaning, users configure pybliometrics once, and that's it.

claell commented 10 months ago

Yes, I saw that. Problem is that paths are kind of "hard coded" in the config file, so if I add it to the project folder, every user will have my cache directory (C:/Users/Username) and it will break for them. I changed the paths there to relative paths, but it's not really straight-forward.

Michael-E-Rose commented 9 months ago

I thought about this a bit and I want to change this. I want to introduce a mandatory

pybliometrics.init()

statement, which loads the configuration. Instead of loading it during import. Users can optionally provide the link to the configuration file in this statement.

claell commented 9 months ago

Sounds good to me, as that will also fix problems where auto formatting messes up the order of

import os

os.environ['PYB_CONFIG_FILE'] = "C:/Custom/Location/pybliometrics.cfg"

import pybliometrics

For this particular issue, I was looking for some function like

pybliometrics.set_base_directory()

which sets the base directories for all directories in the config:

[Directories]
AbstractRetrieval = PPP/.pybliometrics/Scopus/abstract_retrieval
AffiliationSearch = PPP/.pybliometrics/Scopus/affiliation_search
AuthorRetrieval = PPP/.pybliometrics/Scopus/author_retrieval
AuthorSearch = PPP/.pybliometrics/Scopus/author_search
CitationOverview = PPP/.pybliometrics/Scopus/citation_overview
AffiliationRetrieval = PPP/.pybliometrics/Scopus/affiliation_retrieval
ScopusSearch = PPP/.pybliometrics/Scopus/scopus_search
SerialTitle = PPP/.pybliometrics/Scopus/serial_title

(Basically replacing the PPP for all entries, I guess).

Michael-E-Rose commented 7 months ago

The init change will be handled in #311 soon. This will constitute pybliometrics 3.0. Maybe we can augment this with an option to pass on keys. Then the configuration is fixed per project but the keys are not. We will also make sure that the paths can be relative.

But there will not be a function to replace base directories in a configuration file. That is such an easy thing to do in an editor, it's really not worth the time to write code for it.