Repository: wandb/wandb

Issue:
use six for configparser for py2 compat



Discussion:
Not the right fix,  looks like we are using internal configparser stuff

Resolving patch:
diff --git a/wandb/settings.py b/wandb/settings.py
--- a/wandb/settings.py
+++ b/wandb/settings.py
@@ -1,5 +1,6 @@
 import os
-import configparser
+
+from six.moves import configparser
 
 import wandb.util as util
 from wandb import core, env, wandb_dir
@@ -9,7 +10,9 @@ class Settings(object):
     """Global W&B settings stored under $WANDB_CONFIG_DIR/settings.
     """
 
-    DEFAULT_SECTION = "default"
+    DEFAULT_SECTION = "client"
+
+    _UNSET = object()
 
     def __init__(self, load_settings=True):
         config_dir = os.environ.get(env.CONFIG_DIR, os.path.join(os.path.expanduser("~"), ".config", "wandb"))
@@ -19,23 +22,29 @@ def __init__(self, load_settings=True):
         util.mkdir_exists_ok(wandb_dir())
 
         self._global_settings_path = os.path.join(config_dir, 'settings')
-        self._global_settings = Settings._settings_wth_defaults({})
+        self._global_settings = Settings._settings()
 
         self._local_settings_path = os.path.join(wandb_dir(), 'settings')
-        self._local_settings = Settings._settings_wth_defaults({})
+        self._local_settings = Settings._settings()
 
         if load_settings:
             self._global_settings.read([self._global_settings_path])
             self._local_settings.read([self._local_settings_path])
 
-    def get(self, section, key, fallback=configparser._UNSET):
+    def get(self, section, key, fallback=_UNSET):
         # Try the local settings first. If we can't find the key, then try the global settings.
         # If a fallback is provided, return it if we can't find the key in either the local or global
         # settings.
         try:
             return self._local_settings.get(section, key)
         except configparser.NoOptionError:
-            return self._global_settings.get(section, key, fallback=fallback)
+            try:
+                return self._global_settings.get(section, key)
+            except configparser.NoOptionError:
+                if fallback is not Settings._UNSET:
+                    return fallback
+                else:
+                    raise
 
     def set(self, section, key, value, globally=False):
         def write_setting(settings, settings_path):
@@ -79,7 +88,7 @@ def items(self, section=None):
         return result
 
     @staticmethod
-    def _settings_wth_defaults(default_settings):
+    def _settings(default_settings={}):
         config = configparser.ConfigParser()
         config.add_section(Settings.DEFAULT_SECTION)
         for key, value in default_settings.items():


Test patch:
diff --git a/tests/test_internal_api.py b/tests/test_internal_api.py
--- a/tests/test_internal_api.py
+++ b/tests/test_internal_api.py
@@ -219,7 +219,7 @@ def test_settings(mocker):
         'base_url': 'https://api.wandb.ai',
         'entity': 'test_entity',
         'project': 'test_model',
-        'section': 'default',
+        'section': 'client',
         'run': 'latest',
         'ignore_globs': ["diff.patch", "*.secure"],
         'git_remote': 'origin',
@@ -235,7 +235,7 @@ def test_default_settings():
     assert internal.Api({'base_url': 'http://localhost'}, load_settings=False).settings() == {
         'base_url': 'http://localhost',
         'entity': None,
-        'section': 'default',
+        'section': 'client',
         'run': 'latest',
         # TODO(adrian): it looks like this test interacts with test_settings. sometimes we get 'ignore_globs': ['*.patch']
         'ignore_globs': [],
diff --git a/tests/test_settings.py b/tests/test_settings.py
--- a/tests/test_settings.py
+++ b/tests/test_settings.py
@@ -3,65 +3,65 @@
 
 from click.testing import CliRunner
 import wandb.util as util
-from wandb import settings as gs
+from wandb.settings import Settings
 from wandb import env
 
 
 def test_read_empty_settings():
-    settings = gs.Settings()
-    assert settings.get('default', 'foo', fallback=None) is None
+    settings = Settings()
+    assert settings.get(Settings.DEFAULT_SECTION, 'foo', fallback=None) is None
 
 
 def test_read_global_setting(global_wandb_settings):
-    global_wandb_settings.write("[default]\nfoo = bar\n")
+    global_wandb_settings.write("[client]\nfoo = bar\n")
     global_wandb_settings.flush()
 
-    settings = gs.Settings()
-    assert settings.get('default', 'foo') == 'bar'
+    settings = Settings()
+    assert settings.get(Settings.DEFAULT_SECTION, 'foo') == 'bar'
 
 
 def test_read_local_setting(global_wandb_settings, local_wandb_settings):
-    global_wandb_settings.write("[default]\nfoo = baz\n")
+    global_wandb_settings.write("[client]\nfoo = baz\n")
     global_wandb_settings.flush()
 
-    local_wandb_settings.write("[default]\nfoo = bar\n")
+    local_wandb_settings.write("[client]\nfoo = bar\n")
     local_wandb_settings.flush()
 
-    settings = gs.Settings()
-    assert settings.get('default', 'foo') == 'bar'
+    settings = Settings()
+    assert settings.get(Settings.DEFAULT_SECTION, 'foo') == 'bar'
 
 
 def test_write_setting_globally(global_wandb_settings):
-    settings = gs.Settings()
-    settings.set('default', 'foo', 'bar', globally=True)
+    settings = Settings()
+    settings.set(Settings.DEFAULT_SECTION, 'foo', 'bar', globally=True)
 
     with open(global_wandb_settings.name, "r") as f:
         data = f.read()
-        assert "[default]" in data
+        assert "[client]" in data
         assert "foo = bar" in data
 
 
 def test_write_setting_locally(local_wandb_settings):
-    settings = gs.Settings()
-    settings.set('default', 'foo', 'bar')
+    settings = Settings()
+    settings.set(Settings.DEFAULT_SECTION, 'foo', 'bar')
 
     with open(local_wandb_settings.name, "r") as f:
         data = f.read()
-        assert "[default]" in data
+        assert "[client]" in data
         assert "foo = bar" in data
 
 
 def test_items(global_wandb_settings, local_wandb_settings):
-    global_wandb_settings.write("[default]\nfoo = baz\n")
+    global_wandb_settings.write("[client]\nfoo = baz\n")
     global_wandb_settings.flush()
 
-    local_wandb_settings.write("[default]\nfoo = bar\n")
+    local_wandb_settings.write("[client]\nfoo = bar\n")
     local_wandb_settings.flush()
 
-    settings = gs.Settings()
+    settings = Settings()
 
     assert settings.items() == {
-        'section': 'default',
+        'section': Settings.DEFAULT_SECTION,
         'foo': 'bar',
     }