Commits

Jonathan Eunice committed 62f0fe1

Some PEP8 cleanups. Bumped to 1.0 for better installability.

Comments (0)

Files changed (8)

+
+
+
+1.0
+===
+
+  * Cleaned up source for better PEP8 conformance
+  * Bumped version number to 1.0 as part of move to `semantic 
+    versioning <http://semver.org>`_, or at least enough of it so
+    as to not screw up Python installation procedures (which don't
+    seem to understand 0.401 is a lesser version that 0.5, because
+    401 > 5).
+
 include MANIFEST.in
 include README
 include README.rst
+include CHANGES.rst
 include pytest.ini
 include tox.ini
 recursive-include options *.py

options/__init__.py

-from options.core import *
+from options.core import * 
 
 __all__ = 'Unset Prohibited Transient attrs Options OptionsChain OptionsContext'.split()

options/configparser.py

 try:
     from ConfigParser import SafeConfigParser as ConfigParser
 except ImportError:
-    from configparser import ConfigParser # py3
+    from configparser import ConfigParser  # py3
     def push(self, kwargs):
         """
         Create the next layer down. Intended for instances to call during
-        ``__init__()``. 
-        
+        ``__init__()``.
+
         """
         return OptionsChain(self, kwargs)
 
         """
         Instance based decorator, specifying a function in the using module
         as a magical function. Note that the magical methods will be called
-        with a self of None. 
+        with a self of None.
         """
         def my_decorator(func):
             self._magic[key] = func
             c.config[k] = v
         with open(filepath, "w") as f:
             f.write(str(c))
-            
+
     def read(self, filepath):
         """
         Load configuration values from the given filepath.
         c = INIConfig(open(filepath, "r"))
         for k in c.config:
             self[k] = c.config[k]
-            
+
     def copy(self):
         """
         Return a copy of this instance.
         new = orderedstuf.copy(self)
         new._magic = self._magic.copy()
         return new
-            
+
         # UNDER CONSTRUCTION
-            
+
         # use read, sections, itesms as in this note
         # http://stackoverflow.com/questions/3587041/python-
         # http://docs.python.org/dev/library/configparser.html
-    
+
         # not sure why we take such care to get the order right for Options, because the
         # dict handed to Options.__init__ is not in order!
-        
+
         # should there be a leftovers_ok option that raises an error on push()
-        # if there are leftovers?    
+        # if there are leftovers?
+
 
 class OptionsChain(chainstuf):
-    
+
     def __init__(self, bottom, kwargs):
         """
         Create an OptionsChain, pushing one level down.
         """
         chainstuf.__init__(self, bottom)
         processed = self._process(bottom, kwargs)
-        self.maps = [ processed, bottom ]
-        
+        self.maps = [processed, bottom]
+
     def _magicalized(self, key, value):
         """
         Get the magically processed value for a single key value pair.
         for key, value in kwargs.items():
             if key in base:
                 opts[key] = self._magicalized(key, value)
-                
+
         # NB base identical to self when called from set(), but not when called
         # from __init__()
-        
+
         # empty kwargs of 'taken' options
         for key in opts:
             del kwargs[key]
 
         return opts
-    
+
     def __repr__(self):
         """
         Get repr() of OptionsChain. Dig down to find earliest ancestor, which
         contains the right ordering of keys.
         """
         grandpa = self.maps[-1]
-        n_layers  = len(self.maps)
+        n_layers = len(self.maps)
         while not isinstance(grandpa, Options):
             n_layers += len(grandpa.maps) - 1
             grandpa = grandpa.maps[-1]
-            
+
         guts = attrs(self, first=list(grandpa.keys()), underscores=True)
         return "{0}({1} layers: {2})".format(self.__class__.__name__, n_layers, guts)
-    
+
     #def __iter__(self):
     #    for k in super(OptionsChain, self).keys():
     #        if not k.startswith('_'):
     #            yield k
     #    raise StopIteration
-        
+
     def items(self):
         """
         Return items of self, but none that are 'internal' (ie start with underscore _)
         """
-        return [ (k,v) for (k,v) in super(OptionsChain, self).items() if not k.startswith('_') ]
-    
+        return [(k, v) for (k, v) in super(OptionsChain, self).items() if not k.startswith('_')]
+
     def push(self, kwargs):
         """
         Create the next layer down. Intended for instances to call
         individual method invocations, where ``self.options`` is already
-        an OptionChain. 
-        
+        an OptionChain.
+
         """
         return OptionsChain(self, kwargs)
-    
+
         # NB Implicit addflat() has been removed
 
     def addflat(self, args, keys):
                 raise KeyError("changes to '{0}' are prohibited".format(k))
             else:
                 self.maps[0][k] = v
-                
 
     def setdefault(self, key, default=None):
         """
             return value
         except KeyError as e:
             raise e
-    
-    
+
     def copy(self):
         """
         Return a copy of the self. That means a copy of just the top layer,
 
     #  TBD Handle the unsetting of magic in subclasses
 
- 
-  
+
+
     #def __setattr__(self, name, value):
     #    print "OptionsChain.__setattr__() name:", name, "value:", value
     #    if name in self:
     #    else:
     #        print "    not in self; punt to superclass"
     #        chainstuf.__setattr__(self, name, value)
-
     # could possibly extend set() magic to setattr (but would have to be
     # careful of recursions). Current draft doesn't work - infinite recursion
-    
 class OptionsContext(object):
 
     """
     Context manager so that modules that use Options can easily implement
     a `with x.settings(...):` capability. In x's class:
-    
+
     def settings(self, **kwargs):
         return OptionsContext(self, kwargs)
     """
     def __init__(self, caller, kwargs):
         """
         When `with x.method(*args, **kwargs)` is called, it creates an OptionsContext
-        passing in its **kwargs. 
+        passing in its **kwargs.
         """
         self.caller = caller
         if 'opts' in kwargs:

options/funclike.py

 
 
 def is_function(obj):
-    """
+    """ 
     Determines: Is obj a function?
     """
     return isinstance(obj, function_type)

options/nulltype.py

     is representing emptyness in a way that doesn't overload None.
     This helps create designated identifiers with specific meanings
     such as Passthrough, Prohibited, and Undefined.
-    
+
     Instantiate to create desired null singletons. While they are
     singletons, depends on usage convention rather than strict
     enforcement to maintain their singleton-ness. This is a problem
 
 setup(
     name='options',
-    version='0.5',
+    version='1.0',
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description='Container for flexible class, instance, and function call options',
     long_description=open('README.rst').read(),
     url='https://bitbucket.org/jeunice/options',
     packages=['options'],
-    install_requires=['stuf>=0.9.12', 'six'],
+    install_requires=['stuf>=0.9.12', 'six>=1.4.1'],
     tests_require = ['tox', 'pytest'],
     zip_safe = False,
     keywords='options config configuration parameters arguments',