Repository: beetbox/confuse

Issue:
Hot reloading
Hi,

I was wondering if this cool library can perform hot reloading to update config in live if the file changed. 

Eg:

`main.py`
```python
import confuse
import sys
import time

if __name__ == "__main__":
  config = confuse.Configuration('app', __name__)
  print(config)
  time.sleep(20)
  print(config)
  sys.exit(0)
```

`~/.config/app/config.yaml`
```yaml
foo: bar
```

I launch the program, then I modify the `config.yaml` file to 
```yaml
foo: bar
test: hello world
```

Program output:
```bash
$ python3 main.py
{'foo': 'bar'}  # I change the config.yaml file after this output
{'foo': 'bar'}  # Sould be {'foo': 'bar', 'test': 'hello world'}
# Relaunching program to be sure 
% python3 main.py
{'foo': 'bar', 'test': 'hello world'}
{'foo': 'bar', 'test': 'hello world'}
```

Thanks



Discussion:

Patch:
diff --git a/confuse/__init__.py b/confuse/__init__.py
index c92c356..ef3d19c 100644
--- a/confuse/__init__.py
+++ b/confuse/__init__.py
@@ -3,7 +3,7 @@
 
 from __future__ import division, absolute_import, print_function
 
-__version__ = '1.5.0'
+__version__ = '1.6.0'
 
 from .exceptions import * # NOQA
 from .util import * # NOQA
diff --git a/confuse/core.py b/confuse/core.py
index 7a5c21e..fe1da39 100644
--- a/confuse/core.py
+++ b/confuse/core.py
@@ -701,6 +701,17 @@ class Configuration(RootView):
 
         return yaml_out
 
+    def reload(self):
+        """Reload all sources from the file system.
+
+        This only affects sources that come from files (i.e.,
+        `YamlSource` objects); other sources, such as dictionaries
+        inserted with `add` or `set`, will remain unchanged.
+        """
+        for source in self.sources:
+            if isinstance(source, YamlSource):
+                source.load()
+
 
 class LazyConfig(Configuration):
     """A Configuration at reads files on demand when it is first
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 4ccd9a2..2519ec0 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,6 +1,12 @@
 Changelog
 ---------
 
+v1.6.0
+''''''
+
+- A new `Configuration.reload` method makes it convenient to reload and
+  re-parse all YAML files from the file system.
+
 v1.5.0
 ''''''
 


Test patch:
diff --git a/test/test_yaml.py b/test/test_yaml.py
index 24965cd..a20e05f 100644
--- a/test/test_yaml.py
+++ b/test/test_yaml.py
@@ -39,6 +39,17 @@ class FileParseTest(unittest.TestCase):
         else:
             self.fail('ConfigError not raised')
 
+    def test_reload_conf(self):
+        with TempDir() as temp:
+            path = temp.sub('test_config.yaml', b'foo: bar')
+            config = confuse.Configuration('test', __name__)
+            config.set_file(filename=path)
+            self.assertEqual(config['foo'].get(), 'bar')
+            temp.sub('test_config.yaml', b'foo: bar2\ntest: hello world')
+            config.reload()
+            self.assertEqual(config['foo'].get(), 'bar2')
+            self.assertEqual(config['test'].get(), 'hello world')
+
     def test_tab_indentation_error(self):
         try:
             self._parse_contents(b"foo:\n\tbar: baz")