Repository: CORE-GATECH-GROUP/serpent-tools
Pull request #47 (2017-12-06 14:25:20)

Remove settings package; Cleaned up messages file
Wasn't a need for the settings directory, so it has been refactored out. The following files were moved, in reference to the root `serpentTools` directory

1. `settings/__init__.py` --> `settings.py`
1. `settings/messages.py` --> `messages.py`
1. `settings/variables.yaml` --> `variables.yaml`

The `setup.py` script was modified to remove the `serpentTools.settings` package, and move the variables file to/from the correct place upon install.
All calls to the settings package, i.e. `from serpentTools.settings import rc` still work, but the message imports had to be modified to point towards `serpentTools.messages`. The latter change is the cause for most of the files being modified

## Changes to `messages.py`

There is not longer a single error function with an optional `fatal` argument. There is now the `error` and `critical` functions. The difference is that `error` should be used if an exception was suppressed internally, while the `critical` function should be used in the event of a serious failure. Perhaps bundled inside the `SerpentToolsException` class?

Also, the now correctly named `deprecated` decorator takes an argument on use. 
```
@deprecated('alternativeFunc')
def foo(x, y):
     print(x * y)

foo(1, 2)
WARNING : serpentTools: Function foo has been deprecated. Use alternativeFunc instead
DeprecationWarning: Function foo has been deprecated. Use alternativeFunc instead
2
```



Patch:
diff --git a/docs/about.rst b/docs/about.rst
index eb26f32..812a4ae 100644
--- a/docs/about.rst
+++ b/docs/about.rst
@@ -41,6 +41,7 @@ Here are all the wonderful people that helped make this project happen
 
 * `Andrew Johnson <https://github.com/drewejohnson>`_
 * `Dr. Dan Kotlyar <https://github.com/CORE-GATECH>`_
+* `Stefano Terlizzi <https://github.com/sallustius>`_
 
 
 .. [1] Leppanen, J. et al. (2015) "The Serpent Monte Carlo code: Status,
diff --git a/docs/api/messages.rst b/docs/api/messages.rst
index 7541dfa..0b54bcb 100644
--- a/docs/api/messages.rst
+++ b/docs/api/messages.rst
@@ -2,4 +2,4 @@
 Messages
 ========
 
-.. automodule:: serpentTools.settings.messages
+.. automodule:: serpentTools.messages
diff --git a/serpentTools/__init__.py b/serpentTools/__init__.py
index 23f7abb..ebb1aff 100644
--- a/serpentTools/__init__.py
+++ b/serpentTools/__init__.py
@@ -2,11 +2,10 @@ import os
 
 ROOT_DIR = os.path.dirname(__file__)
 
-from serpentTools import settings
+from serpentTools import messages
 
 # List TODOS/feature requests here for now
 # Compatibility
-# TODO: Python 2 support
 # TODO: Test compatibility with earlier numpy releases
 # Usage/scripting
 # TODO: Update rc with dictionary
@@ -18,4 +17,4 @@ from ._version import get_versions
 __version__ = get_versions()['version']
 del get_versions
 
-settings.messages.info('Using version {}'.format(__version__))
+messages.info('Using version {}'.format(__version__))
diff --git a/serpentTools/settings/messages.py b/serpentTools/messages.py
similarity index 73%
rename from serpentTools/settings/messages.py
rename to serpentTools/messages.py
index 54faeef..c11b613 100644
--- a/serpentTools/settings/messages.py
+++ b/serpentTools/messages.py
@@ -58,18 +58,20 @@ def info(message):
 
 
 def warning(message):
-    """Log a warning that something that could go wrong or be avoided."""
+    """Log a warning that something that could go wrong or should be avoided."""
     __logger__.warning('%s', message)
 
 
-def error(message, fatal=True):
-    """Log that something went wrong."""
-    if fatal:
-        __logger__.critical('%s', message, exc_info=True)
-        raise SerpentToolsException('%s', message)
+def error(message):
+    """Log that something caused an exception but was supressed."""
     __logger__.error('%s', message)
 
 
+def critical(message):
+    """Log that something has gone horribly wrong."""
+    __logger__.critical('%s', message, exc_info=True)
+
+
 def updateLevel(level):
     """Set the level of the logger."""
     if level.lower() not in LOG_OPTS:
@@ -81,17 +83,19 @@ def updateLevel(level):
         return level
 
 
-def depreciated(f):
-    """Display a warning indicating a function will be depreciated."""
+def deprecated(useInstead):
+    """Display a warning that a different function should be used instead."""
 
-    @functools.wraps(f)
-    def decoratedFunc(*args, **kwargs):
-        msg = 'Call to depreciated function {}'.format(f.__name__)
-        warning(msg)
-        _updateFilterAlert(msg, DeprecationWarning)
-        return f(*args, **kwargs)
-
-    return decoratedFunc
+    def decorate(f):
+        @functools.wraps(f)
+        def decorated(*args, **kwargs):
+            msg = ('Function {} has been deprecated. Use {} instead'
+                   .format(f.__name__, useInstead))
+            warning(msg)
+            _updateFilterAlert(msg, DeprecationWarning)
+            return f(*args, **kwargs)
+        return decorated
+    return decorate
 
 
 def willChange(changeMsg):
diff --git a/serpentTools/objects/containers.py b/serpentTools/objects/containers.py
index ff8f941..afd330f 100644
--- a/serpentTools/objects/containers.py
+++ b/serpentTools/objects/containers.py
@@ -5,7 +5,7 @@ instance in time.
 """
 
 from serpentTools.objects import SupportingObject
-from serpentTools.settings import messages
+from serpentTools import messages
 
 
 class HomogUniv(SupportingObject):
diff --git a/serpentTools/objects/materials.py b/serpentTools/objects/materials.py
index ac65c6a..d67f399 100644
--- a/serpentTools/objects/materials.py
+++ b/serpentTools/objects/materials.py
@@ -3,7 +3,7 @@
 import numpy
 from matplotlib import pyplot
 
-from serpentTools.settings import messages
+from serpentTools import messages
 from serpentTools.objects import NamedObject
 
 
@@ -101,9 +101,14 @@ class DepletedMaterial(NamedObject):
                     scratch.append([float(item) for item in line.split()])
         self.data[newName] = numpy.array(scratch)
 
-    @messages.depreciated
+    @messages.deprecated('getValues')
     def getXY(self, xUnits, yUnits, timePoints=None, names=None):
-        """Depreciated. Use getValues instead"""
+        """
+        Return x values for given time, and corresponding isotope values.
+
+        .. deprecated:: 0.1.0
+            Use :meth:`getValues` instead.
+        """
         if timePoints is None:
             timePoints = self.days
             return self.getValues(xUnits, yUnits, timePoints, names), self.days
diff --git a/serpentTools/parsers/__init__.py b/serpentTools/parsers/__init__.py
index 3d3c64f..c36cbfc 100644
--- a/serpentTools/parsers/__init__.py
+++ b/serpentTools/parsers/__init__.py
@@ -9,9 +9,9 @@ try:
     HAS_SCIPY = True
 except ImportError:
     HAS_SCIPY = False
-    csr_matrix = array
+    csc_matrix = array
 
-from serpentTools.settings.messages import warning
+from serpentTools.messages import warning
 from serpentTools.parsers.depletion import DepletionReader
 from serpentTools.parsers.branching import BranchingReader
 
@@ -20,6 +20,12 @@ def depmtx(fileP):
     """
     Read the contents of the ``depmtx`` file and return contents
 
+    .. note::
+
+        If ``scipy`` is not installed, matrix ``A`` will be full.
+        This can cause some warnings or errors if sparse or
+        non-sparse solvers are used.
+
     Parameters
     ----------
     fileP: str
diff --git a/serpentTools/parsers/depletion.py b/serpentTools/parsers/depletion.py
index 15789bb..9dbf75c 100644
--- a/serpentTools/parsers/depletion.py
+++ b/serpentTools/parsers/depletion.py
@@ -8,7 +8,7 @@ from drewtils.parsers import KeywordParser
 from serpentTools.objects.readers import MaterialReader
 from serpentTools.objects.materials import DepletedMaterial
 
-from serpentTools.settings import messages
+from serpentTools import messages
 
 
 class DepletionReader(MaterialReader):
diff --git a/serpentTools/settings/__init__.py b/serpentTools/settings.py
similarity index 96%
rename from serpentTools/settings/__init__.py
rename to serpentTools/settings.py
index 67a202a..ceba695 100644
--- a/serpentTools/settings/__init__.py
+++ b/serpentTools/settings.py
@@ -4,7 +4,9 @@ import os
 import yaml
 
 from serpentTools import ROOT_DIR
-from serpentTools.settings import messages
+from serpentTools import messages
+
+__all__ = ['defaultSettings', 'rc']
 
 defaultSettings = {
     'depletion.metadataKeys': {
@@ -32,7 +34,7 @@ defaultSettings = {
         'type': bool
     },
     'verbosity': {
-        'default': 'warning',
+        'default': 'info',
         'options': messages.LOG_OPTS,
         'type': str,
         'description': 'Set the level of errors to be shown.',
@@ -99,9 +101,9 @@ class DefaultSetting(object):
             listVals = [value] if not isinstance(value, list) else value
             inOptions = any([val in self.options for val in listVals])
             if not inOptions:
-                opts = [str(option) for option in self.options]
-                raise KeyError('Setting {} is\n{}\nand not one of the allowed '
-                               'options:\n{}'
+                opts = ', '.join([str(option) for option in self.options])
+                raise KeyError('Setting {} is {} and not one of the allowed '
+                               'options: {}'
                                .format(self.name, value, opts))
         return True
 
@@ -272,7 +274,7 @@ class UserSettingsLoader(dict):
         variables = set(extras) if extras else set()
         if not keywords:
             return variables
-        varFile = os.path.join(ROOT_DIR, 'settings', 'variables.yaml')
+        varFile = os.path.join(ROOT_DIR, 'variables.yaml')
         with open(varFile) as fObj:
             groups = yaml.load(fObj)
         thisVersion = groups[serpentVersion]
diff --git a/serpentTools/settings/variables.yaml b/serpentTools/variables.yaml
similarity index 100%
rename from serpentTools/settings/variables.yaml
rename to serpentTools/variables.yaml
diff --git a/setup.py b/setup.py
index 626b9f5..a6aa65d 100644
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@ if not getenv('ONTRAVIS', False):
     # PR 45/44
     installRequires.append('scipy')
 
-installVarYamlFrom = join('serpentTools', 'settings', 'variables.yaml')
+installVarYamlFrom = join('serpentTools', 'variables.yaml')
 
 pythonRequires = '>=3.5'
 
@@ -32,7 +32,7 @@ setupArgs = {
     'name': 'serpentTools',
     'python_requires': pythonRequires,
     'packages': ['serpentTools', 'serpentTools.parsers',
-                 'serpentTools.objects', 'serpentTools.settings'],
+                 'serpentTools.objects'],
     'url': 'https://github.com/CORE-GATECH-GROUP/serpent-tools',
     'description': ('A suite of parsers designed to make interacting with '
                     'SERPENT output files simple, scriptable, and flawless'),


Test patch:
diff --git a/serpentTools/tests/test_settings.py b/serpentTools/tests/test_settings.py
index adb28e9..eeccefa 100644
--- a/serpentTools/tests/test_settings.py
+++ b/serpentTools/tests/test_settings.py
@@ -2,7 +2,7 @@
 import unittest
 
 from serpentTools import settings
-from serpentTools.settings.messages import depreciated, willChange
+from serpentTools.messages import deprecated, willChange
 
 
 class DefaultSettingsTester(unittest.TestCase):
@@ -117,7 +117,7 @@ class MessagingTester(unittest.TestCase):
     def test_depreciatedDecorator(self):
         """Verify that the depreciated decorator doesn't break things"""
 
-        @depreciated
+        @deprecated('this nonexistent function')
         def demoFunction(x, val=5):
             return x + val