Skip to content

Configuration

Marc-Olivier Buob edited this page Jan 28, 2020 · 7 revisions

Configuration

Minifold can run without writting any configuration file. Such files are only useful to separate in your application its implementation and its settings.

Configuration settings are fetched from one or more json files, usually located in ~/.minifold/conf/. Such json files can be loaded by using a Config instance (imported from minifold.config). The resulting Config instance can therefore be used to craft Connectors based on the loaded templates.

Step-by-step example

We now detail how to use such templates. In the first step, we define to templates to create easily some connectors. In the second step, we create a python script taking advantage of this configuration file. The third step checks if it works.

  1. Create ~/.minifold/conf/dblp.json:
{
    "dblp:dagstuhl" : {
        "type" : "minifold.dblp.DblpConnector",
        "args" : {
            "dblp_api_url" : "https://dblp.dagstuhl.de"
        }
    },
    "dblp:uni-trier" : {
        "type" : "minifold.dblp.DblpConnector",
        "args" : {
            "dblp_api_url" : "https://dblp.uni-trier.de"
        }
    }
}

Here, we define two templates for the minifold.dblp.DblpConnector class, namely dblp:dagstuhl and dblp:uni-trier.

The values mapped with args keys are forwarded to minifold.dblp.DblpConnector.__init__ (see dblp.py).

  • You must define each mandatory parameter of minifold.dblp.DblpConnector.__init__.
  • You're free to define or not the optional parameters.

In this example, the constructor has no mandatory parameter and dblp_api_url is an optional parameter. The remaining optional parameters are set to their default value.

  1. Let's try this configuration by creating a python script:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
from minifold.config import Config
from minifold.dblp import DblpConnector

HOME = os.path.expanduser("~")
config = Config()
config.load_file(os.path.join(HOME, ".minifold", "conf", "dblp.json"))

dblp1 = config.make_connector("dblp:dagstuhl")
print(dblp1.api_url)
dblp2 = config.make_connector("dblp:uni-trier")
print(dblp2.api_url)

Note: Do not forget import DblpConnector before calling config.make_connector. This is a requirement of minifold.connector to keep track of known Connector classes.

  1. Execute this script. You should obtain:
https://dblp.dagstuhl.de
https://dblp.uni-trier.de

Custom connectors

If you implement your own Connector, it is not required to put it in minifold package, as the type key is absolute.

Per-app configuration

In this example, the json file groups two templates related to the same Connector. But you can write a single json file gathering all the template of require, even if they are related to different Connector classes.

Real-life examples

Below are listed some examples used at LINCS.

dblp_lincs.json

{
    "dblp:lincs" : {
        "type" : "minifold.dblp.DblpConnector",
        "args" : {
            "map_dblp_name" : {
                "Bartek Blaszczyszyn" : "Bartlomiej Blaszczyszyn"
            },
            "map_dblp_id" : {
                "Bartek Blaszczyszyn"      : "88/4182",
                "Chung Shue (Calvin) Chen" : "30/1446",
                "Giovanni Pau"             : "87/6423",
                "Fabien Schneider"         : "77/2750-1",
                "Xuan Zeng"                : "58/5418-2"
            },
            "dblp_api_url" : "https://dblp.dagstuhl.de"
        }
    }
}

hal_lincs.json

{
    "hal:lincs" : {
        "type" : "minifold.hal.HalConnector",
        "args" : {
            "hal_map_name" : {
                "Bartek Blaszczyszyn" : "Bartlomiej Blaszczyszyn"
            },
            "hal_map_id" : {
                "Salah Eddine Elayoubi"    : "salah-eddine-elayoubi",
                "François Durand"          : "fradurand",
                "Chung Shue (Calvin) Chen" : "chung-shue-chen",
                "Dario Rossi"              : "rossi-dario"
            },
            "hal_api_url" : "https://api.archives-ouvertes.fr/search"
        }
    }
}

twitter.json

{
    "twitter:lincs.json" : {
        "twitter_id"          : "lincs_paris",
        "consumer_key"        : "CONSUMER_KEY",
        "consumer_secret"     : "CONSUMER_SECRET",
        "access_token"        : "ACCESS_TOKEN",
        "access_token_secret" : "ACCESS_TOKEN_SECRET"
    }
}