{"action":"created","comment":{"url":"https://api.github.com/repos/QwantResearch/idunn/pulls/comments/190833363","pull_request_review_id":123294859,"id":190833363,"diff_hunk":"@@ -0,0 +1,59 @@\n+import os\n+import apistar_settings\n+import yaml\n+\n+\n+def _load_yaml_file(file):\n+    with open(file, 'r') as default:\n+        return yaml.load(default)\n+\n+\n+class SettingsComponent(apistar_settings.SettingsComponent):\n+    \"\"\"\n+    APIStar component to load settings\n+\n+    It merges settings from different sources:\n+    - the settings found in the default_settings.yaml\n+    - a yaml settings file given with an env var ({project}_CONFIG_FILE, eg. IDUNN_CONFIG_FILE)\n+    - env var only for already existing settings.\n+        The env var need to be defined as {project}_{var_name} eg. IDUNN_ES to override the \"ES\" settings.\n+    \"\"\"\n+\n+    def __init__(self, project_name) -> None:\n+        self.settings = {}\n+        self._load_default_config()\n+\n+        self._load_specific_config(project_name)\n+\n+        self._load_from_env_var(project_name)\n+\n+        print(f\"config: {self.settings}\")\n+\n+    def _load_default_config(self):\n+        \"\"\"\n+        load the default config from a default_settings.yaml in the same directory\n+        \"\"\"\n+        default_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default_settings.yaml')\n+        self.settings.update(_load_yaml_file(default_config_path))\n+\n+    def _load_specific_config(self, project_name):\n+        \"\"\"\n+        load settings from a yaml file whose pth in given\n+        with the env var {project}_CONFIG_FILE (eg. IDUNN_CONFIG_FILE for the IDUNN project)\n+        \"\"\"\n+        path = os.environ.get(f'{project_name}_CONFIG_FILE')\n+        if not path:\n+            return\n+        config_path = path","path":"utils/settings.py","position":47,"original_position":47,"commit_id":"a3be65505c9d4d11a11fa5bff111d3b1c2244999","original_commit_id":"a3be65505c9d4d11a11fa5bff111d3b1c2244999","user":{"login":"amatissart","id":4726554,"avatar_url":"https://avatars1.githubusercontent.com/u/4726554?v=4","gravatar_id":"","url":"https://api.github.com/users/amatissart","html_url":"https://github.com/amatissart","followers_url":"https://api.github.com/users/amatissart/followers","following_url":"https://api.github.com/users/amatissart/following{/other_user}","gists_url":"https://api.github.com/users/amatissart/gists{/gist_id}","starred_url":"https://api.github.com/users/amatissart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatissart/subscriptions","organizations_url":"https://api.github.com/users/amatissart/orgs","repos_url":"https://api.github.com/users/amatissart/repos","events_url":"https://api.github.com/users/amatissart/events{/privacy}","received_events_url":"https://api.github.com/users/amatissart/received_events","type":"User","site_admin":false},"body":"unnecessary variable","created_at":"2018-05-25T09:03:59Z","updated_at":"2018-05-25T09:18:30Z","html_url":"https://github.com/QwantResearch/idunn/pull/3#discussion_r190833363","pull_request_url":"https://api.github.com/repos/QwantResearch/idunn/pulls/3","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/QwantResearch/idunn/pulls/comments/190833363"},"html":{"href":"https://github.com/QwantResearch/idunn/pull/3#discussion_r190833363"},"pull_request":{"href":"https://api.github.com/repos/QwantResearch/idunn/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/QwantResearch/idunn/pulls/3","id":190016953,"html_url":"https://github.com/QwantResearch/idunn/pull/3","diff_url":"https://github.com/QwantResearch/idunn/pull/3.diff","patch_url":"https://github.com/QwantResearch/idunn/pull/3.patch","issue_url":"https://api.github.com/repos/QwantResearch/idunn/issues/3","number":3,"state":"open","locked":false,"title":"add 3 ways to configure the API","user":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars2.githubusercontent.com/u/3987698?v=4","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"body":"The configuration can be given from different ways:\r\n1. a default settings is available in utils/default_settings.yaml\r\n2. a yaml settings file can be given with an env var IDUNN_CONFIG_FILE\r\n    (the default settings is still loaded and overriden)\r\n3. specific variable can be overriden with env var. They need to be\r\ngiven like \"IDUNN_{var_name}={value}\"\r\n    eg IDUNN_ES_URL=...","created_at":"2018-05-23T15:29:18Z","updated_at":"2018-05-25T09:18:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d31d26083a921fcb29d4537c5f67dab1d28acd5","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/QwantResearch/idunn/pulls/3/commits","review_comments_url":"https://api.github.com/repos/QwantResearch/idunn/pulls/3/comments","review_comment_url":"https://api.github.com/repos/QwantResearch/idunn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/QwantResearch/idunn/issues/3/comments","statuses_url":"https://api.github.com/repos/QwantResearch/idunn/statuses/a3be65505c9d4d11a11fa5bff111d3b1c2244999","head":{"label":"antoine-de:settings","ref":"settings","sha":"a3be65505c9d4d11a11fa5bff111d3b1c2244999","user":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars2.githubusercontent.com/u/3987698?v=4","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"repo":{"id":133955642,"name":"idunn","full_name":"antoine-de/idunn","owner":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars2.githubusercontent.com/u/3987698?v=4","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/antoine-de/idunn","description":"poi API over mimir (ElasticSearch database) for QwantMaps","fork":true,"url":"https://api.github.com/repos/antoine-de/idunn","forks_url":"https://api.github.com/repos/antoine-de/idunn/forks","keys_url":"https://api.github.com/repos/antoine-de/idunn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/antoine-de/idunn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/antoine-de/idunn/teams","hooks_url":"https://api.github.com/repos/antoine-de/idunn/hooks","issue_events_url":"https://api.github.com/repos/antoine-de/idunn/issues/events{/number}","events_url":"https://api.github.com/repos/antoine-de/idunn/events","assignees_url":"https://api.github.com/repos/antoine-de/idunn/assignees{/user}","branches_url":"https://api.github.com/repos/antoine-de/idunn/branches{/branch}","tags_url":"https://api.github.com/repos/antoine-de/idunn/tags","blobs_url":"https://api.github.com/repos/antoine-de/idunn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/antoine-de/idunn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/antoine-de/idunn/git/refs{/sha}","trees_url":"https://api.github.com/repos/antoine-de/idunn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/antoine-de/idunn/statuses/{sha}","languages_url":"https://api.github.com/repos/antoine-de/idunn/languages","stargazers_url":"https://api.github.com/repos/antoine-de/idunn/stargazers","contributors_url":"https://api.github.com/repos/antoine-de/idunn/contributors","subscribers_url":"https://api.github.com/repos/antoine-de/idunn/subscribers","subscription_url":"https://api.github.com/repos/antoine-de/idunn/subscription","commits_url":"https://api.github.com/repos/antoine-de/idunn/commits{/sha}","git_commits_url":"https://api.github.com/repos/antoine-de/idunn/git/commits{/sha}","comments_url":"https://api.github.com/repos/antoine-de/idunn/comments{/number}","issue_comment_url":"https://api.github.com/repos/antoine-de/idunn/issues/comments{/number}","contents_url":"https://api.github.com/repos/antoine-de/idunn/contents/{+path}","compare_url":"https://api.github.com/repos/antoine-de/idunn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/antoine-de/idunn/merges","archive_url":"https://api.github.com/repos/antoine-de/idunn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/antoine-de/idunn/downloads","issues_url":"https://api.github.com/repos/antoine-de/idunn/issues{/number}","pulls_url":"https://api.github.com/repos/antoine-de/idunn/pulls{/number}","milestones_url":"https://api.github.com/repos/antoine-de/idunn/milestones{/number}","notifications_url":"https://api.github.com/repos/antoine-de/idunn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/antoine-de/idunn/labels{/name}","releases_url":"https://api.github.com/repos/antoine-de/idunn/releases{/id}","deployments_url":"https://api.github.com/repos/antoine-de/idunn/deployments","created_at":"2018-05-18T13:07:00Z","updated_at":"2018-05-18T13:07:02Z","pushed_at":"2018-05-25T07:27:11Z","git_url":"git://github.com/antoine-de/idunn.git","ssh_url":"git@github.com:antoine-de/idunn.git","clone_url":"https://github.com/antoine-de/idunn.git","svn_url":"https://github.com/antoine-de/idunn","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"QwantResearch:master","ref":"master","sha":"fd7af8cc4971af3fcf8e5a7cb5ea5dd53892bab5","user":{"login":"QwantResearch","id":31347303,"avatar_url":"https://avatars3.githubusercontent.com/u/31347303?v=4","gravatar_id":"","url":"https://api.github.com/users/QwantResearch","html_url":"https://github.com/QwantResearch","followers_url":"https://api.github.com/users/QwantResearch/followers","following_url":"https://api.github.com/users/QwantResearch/following{/other_user}","gists_url":"https://api.github.com/users/QwantResearch/gists{/gist_id}","starred_url":"https://api.github.com/users/QwantResearch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QwantResearch/subscriptions","organizations_url":"https://api.github.com/users/QwantResearch/orgs","repos_url":"https://api.github.com/users/QwantResearch/repos","events_url":"https://api.github.com/users/QwantResearch/events{/privacy}","received_events_url":"https://api.github.com/users/QwantResearch/received_events","type":"Organization","site_admin":false},"repo":{"id":133823727,"name":"idunn","full_name":"QwantResearch/idunn","owner":{"login":"QwantResearch","id":31347303,"avatar_url":"https://avatars3.githubusercontent.com/u/31347303?v=4","gravatar_id":"","url":"https://api.github.com/users/QwantResearch","html_url":"https://github.com/QwantResearch","followers_url":"https://api.github.com/users/QwantResearch/followers","following_url":"https://api.github.com/users/QwantResearch/following{/other_user}","gists_url":"https://api.github.com/users/QwantResearch/gists{/gist_id}","starred_url":"https://api.github.com/users/QwantResearch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QwantResearch/subscriptions","organizations_url":"https://api.github.com/users/QwantResearch/orgs","repos_url":"https://api.github.com/users/QwantResearch/repos","events_url":"https://api.github.com/users/QwantResearch/events{/privacy}","received_events_url":"https://api.github.com/users/QwantResearch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QwantResearch/idunn","description":"poi API over mimir (ElasticSearch database) for QwantMaps","fork":false,"url":"https://api.github.com/repos/QwantResearch/idunn","forks_url":"https://api.github.com/repos/QwantResearch/idunn/forks","keys_url":"https://api.github.com/repos/QwantResearch/idunn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QwantResearch/idunn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QwantResearch/idunn/teams","hooks_url":"https://api.github.com/repos/QwantResearch/idunn/hooks","issue_events_url":"https://api.github.com/repos/QwantResearch/idunn/issues/events{/number}","events_url":"https://api.github.com/repos/QwantResearch/idunn/events","assignees_url":"https://api.github.com/repos/QwantResearch/idunn/assignees{/user}","branches_url":"https://api.github.com/repos/QwantResearch/idunn/branches{/branch}","tags_url":"https://api.github.com/repos/QwantResearch/idunn/tags","blobs_url":"https://api.github.com/repos/QwantResearch/idunn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QwantResearch/idunn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QwantResearch/idunn/git/refs{/sha}","trees_url":"https://api.github.com/repos/QwantResearch/idunn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QwantResearch/idunn/statuses/{sha}","languages_url":"https://api.github.com/repos/QwantResearch/idunn/languages","stargazers_url":"https://api.github.com/repos/QwantResearch/idunn/stargazers","contributors_url":"https://api.github.com/repos/QwantResearch/idunn/contributors","subscribers_url":"https://api.github.com/repos/QwantResearch/idunn/subscribers","subscription_url":"https://api.github.com/repos/QwantResearch/idunn/subscription","commits_url":"https://api.github.com/repos/QwantResearch/idunn/commits{/sha}","git_commits_url":"https://api.github.com/repos/QwantResearch/idunn/git/commits{/sha}","comments_url":"https://api.github.com/repos/QwantResearch/idunn/comments{/number}","issue_comment_url":"https://api.github.com/repos/QwantResearch/idunn/issues/comments{/number}","contents_url":"https://api.github.com/repos/QwantResearch/idunn/contents/{+path}","compare_url":"https://api.github.com/repos/QwantResearch/idunn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QwantResearch/idunn/merges","archive_url":"https://api.github.com/repos/QwantResearch/idunn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QwantResearch/idunn/downloads","issues_url":"https://api.github.com/repos/QwantResearch/idunn/issues{/number}","pulls_url":"https://api.github.com/repos/QwantResearch/idunn/pulls{/number}","milestones_url":"https://api.github.com/repos/QwantResearch/idunn/milestones{/number}","notifications_url":"https://api.github.com/repos/QwantResearch/idunn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QwantResearch/idunn/labels{/name}","releases_url":"https://api.github.com/repos/QwantResearch/idunn/releases{/id}","deployments_url":"https://api.github.com/repos/QwantResearch/idunn/deployments","created_at":"2018-05-17T14:16:14Z","updated_at":"2018-05-22T10:16:09Z","pushed_at":"2018-05-25T07:27:12Z","git_url":"git://github.com/QwantResearch/idunn.git","ssh_url":"git@github.com:QwantResearch/idunn.git","clone_url":"https://github.com/QwantResearch/idunn.git","svn_url":"https://github.com/QwantResearch/idunn","homepage":null,"size":19,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/QwantResearch/idunn/pulls/3"},"html":{"href":"https://github.com/QwantResearch/idunn/pull/3"},"issue":{"href":"https://api.github.com/repos/QwantResearch/idunn/issues/3"},"comments":{"href":"https://api.github.com/repos/QwantResearch/idunn/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/QwantResearch/idunn/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/QwantResearch/idunn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/QwantResearch/idunn/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/QwantResearch/idunn/statuses/a3be65505c9d4d11a11fa5bff111d3b1c2244999"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"amatissart"}}