Browse Source

remove useless blank lines and indent. PEP 257 -- Docstring Conventions

nico 8 years ago
parent
commit
2bd2fc603b

+ 51 - 63
core/ConfigurationManager/BrainLoader.py

@@ -15,10 +15,8 @@ logger = logging.getLogger("kalliope")
 
 
 class BrainLoader(object):
-
     """
-        This Class is used to get the brain YAML and the Brain as an object
-
+    This Class is used to get the brain YAML and the Brain as an object
     """
 
     def __init__(self):
@@ -27,18 +25,16 @@ class BrainLoader(object):
     @classmethod
     def get_yaml_config(cls, file_path=None):
         """
+        Class Methods which loads default or the provided YAML file and return it as a String
+        :param file_path: the brain file path to load
+        :type file_path: String
+        :return: The loaded brain YAML
+        :rtype: String
 
-            Class Methods which loads default or the provided YAML file and return it as a String
-
-            :param file_path: the brain file path to load
-            :type file_path: String
-            :return: The loaded brain YAML
-            :rtype: String
-
-            :Example:
-                brain_yaml = BrainLoader.get_yaml_config(/var/tmp/brain.yml)
+        :Example:
+            brain_yaml = BrainLoader.get_yaml_config(/var/tmp/brain.yml)
 
-            .. warnings:: Class Method
+        .. warnings:: Class Method
         """
         if file_path is None:
             brain_file_path = cls._get_root_brain_path()
@@ -49,20 +45,19 @@ class BrainLoader(object):
     @classmethod
     def get_brain(cls, file_path=None):
         """
+        Class Methods which loads default or the provided YAML file and return a Brain
 
-            Class Methods which loads default or the provided YAML file and return a Brain
+        :param file_path: the brain file path to load
+        :type file_path: String
+        :return: The loaded Brain
+        :rtype: Brain
 
-            :param file_path: the brain file path to load
-            :type file_path: String
-            :return: The loaded Brain
-            :rtype: Brain
+        :Example:
 
-            :Example:
+            brain = BrainLoader.get_brain(file_path="/var/tmp/brain.yml")
 
-                brain = BrainLoader.get_brain(file_path="/var/tmp/brain.yml")
-
-            .. seealso:: Brain
-            .. warnings:: Class Method
+        .. seealso:: Brain
+        .. warnings:: Class Method
         """
 
         # Instantiate a brain
@@ -76,7 +71,7 @@ class BrainLoader(object):
             # create list of Synapse
             synapses = list()
             for synapses_dict in dict_brain:
-                if "includes" not in synapses_dict: # we don't need to check includes as it's not a synapse
+                if "includes" not in synapses_dict:     # we don't need to check includes as it's not a synapse
                     if ConfigurationChecker().check_synape_dict(synapses_dict):
                         # print "synapses_dict ok"
                         name = synapses_dict["name"]
@@ -100,20 +95,19 @@ class BrainLoader(object):
     @staticmethod
     def _get_neurons(neurons_dict):
         """
+        Get a list of Neuron object from a neuron dict
 
-            Get a list of Neuron object from a neuron dict
-
-            :param neurons_dict: Neuron name or dictionary of Neuron_name/Neuron_parameters
-            :type neurons_dict: String or dict
-            :return: A list of Neurons
-            :rtype: List
+        :param neurons_dict: Neuron name or dictionary of Neuron_name/Neuron_parameters
+        :type neurons_dict: String or dict
+        :return: A list of Neurons
+        :rtype: List
 
-            :Example:
+        :Example:
 
-                neurons = cls._get_neurons(synapses_dict["neurons"])
+            neurons = cls._get_neurons(synapses_dict["neurons"])
 
-            .. seealso:: Neuron
-            .. warnings:: Static and Private
+        .. seealso:: Neuron
+        .. warnings:: Static and Private
         """
 
         neurons = list()
@@ -139,20 +133,19 @@ class BrainLoader(object):
     @classmethod
     def _get_signals(cls, signals_dict):
         """
+        Get a list of Signal object from a signals dict
 
-            Get a list of Signal object from a signals dict
-
-            :param signals_dict: Signal name or dictionary of Signal_name/Signal_parameters
-            :type signals_dict: String or dict
-            :return: A list of Event and/or Order
-            :rtype: List
+        :param signals_dict: Signal name or dictionary of Signal_name/Signal_parameters
+        :type signals_dict: String or dict
+        :return: A list of Event and/or Order
+        :rtype: List
 
-            :Example:
+        :Example:
 
-                signals = cls._get_signals(synapses_dict["signals"])
+            signals = cls._get_signals(synapses_dict["signals"])
 
-            .. seealso:: Event, Order
-            .. warnings:: Class method and Private
+        .. seealso:: Event, Order
+        .. warnings:: Class method and Private
         """
         # print signals_dict
         signals = list()
@@ -167,20 +160,19 @@ class BrainLoader(object):
     @staticmethod
     def _get_event_or_order_from_dict(signal_or_event_dict):
         """
+        The signal is either an Event or an Order
 
-            The signal is either an Event or an Order
+        :param signal_or_event_dict: A dict of event or signal
+        :type signal_or_event_dict: dict
+        :return: The object corresponding to An Order or an Event
+        :rtype: An Order or an Event
 
-            :param signal_or_event_dict: A dict of event or signal
-            :type signal_or_event_dict: dict
-            :return: The object corresponding to An Order or an Event
-            :rtype: An Order or an Event
+        :Example:
 
-            :Example:
+            event_or_order = cls._get_event_or_order_from_dict(signal_dict)
 
-                event_or_order = cls._get_event_or_order_from_dict(signal_dict)
-
-            .. seealso:: Event, Order
-            .. warnings:: Static method and Private
+        .. seealso:: Event, Order
+        .. warnings:: Static method and Private
         """
         if 'event' in signal_or_event_dict:
             # print "is event"
@@ -196,15 +188,14 @@ class BrainLoader(object):
     @staticmethod
     def _get_root_brain_path():
         """
+        Return the full path of the default brain file
 
-            Return the full path of the default brain file
+        :Example:
 
-            :Example:
-
-                brain.brain_file = cls._get_root_brain_path()
+            brain.brain_file = cls._get_root_brain_path()
 
-            .. raises:: IOError
-            .. warnings:: Static method and Private
+        .. raises:: IOError
+        .. warnings:: Static method and Private
         """
 
         # get current script directory path. We are in /an/unknown/path/kalliope/core/ConfigurationManager
@@ -216,6 +207,3 @@ class BrainLoader(object):
         if os.path.isfile(brain_path):
             return brain_path
         raise IOError("Default brain.yml file not found")
-
-
-

+ 82 - 89
core/ConfigurationManager/ConfigurationChecker.py

@@ -5,71 +5,66 @@ from core.Utils import ModuleNotFoundError
 
 class InvalidSynapeName(Exception):
     """
-        The name of the synapse is not correct. It should only contains alphanumerics at the beginning and the end of
-        its name. It can also contains dash in beetween alphanumerics.
+    The name of the synapse is not correct. It should only contains alphanumerics at the beginning and the end of
+    its name. It can also contains dash in beetween alphanumerics.
     """
     pass
 
 
 class NoSynapeName(Exception):
     """
-        A synapse needs a name
+    A synapse needs a name
     """
     pass
 
 
 class NoSynapeNeurons(Exception):
     """
-        A synapse must contains at least one neuron
+    A synapse must contains at least one neuron
 
-        .. seealso:: Synapse, Neuron
+    .. seealso:: Synapse, Neuron
     """
     pass
 
 
 class NoSynapeSignals(Exception):
     """
-        A synapse must contains at least an Event or an Order
+    A synapse must contains at least an Event or an Order
 
-        .. seealso:: Event, Order
+    .. seealso:: Event, Order
     """
     pass
 
 
 class NoValidSignal(Exception):
     """
-        A synapse must contains at least a valid Event or an Order
+    A synapse must contains at least a valid Event or an Order
 
-        .. seealso:: Event, Order
+    .. seealso:: Event, Order
     """
 
     pass
 
 
-
 class NoEventPeriod(Exception):
     """
-        An Event must contains a period corresponding to its execution
+    An Event must contains a period corresponding to its execution
 
-        .. seealso:: Event
+    .. seealso:: Event
     """
     pass
 
 
 class MultipleSameSynapseName(Exception):
     """
-
-        A synapse name must be unique
+    A synapse name must be unique
     """
     pass
 
 
-
 class ConfigurationChecker:
-
     """
-
-        This Class provides all method to Check the configuration files are properly set up.
+    This Class provides all method to Check the configuration files are properly set up.
     """
 
     def __init__(self):
@@ -78,21 +73,20 @@ class ConfigurationChecker:
     @staticmethod
     def check_synape_dict(synape_dict):
         """
+        Return True if the provided dict is well corresponding to a Synapse
 
-            Return True if the provided dict is well corresponding to a Synapse
-
-            :param synape_dict: The synapse Dictionary
-            :type synape_dict: Dict
-            :return: True if synapse are ok
-            :rtype: Boolean
+        :param synape_dict: The synapse Dictionary
+        :type synape_dict: Dict
+        :return: True if synapse are ok
+        :rtype: Boolean
 
-            :Example:
+        :Example:
 
-                ConfigurationChecker().check_synape_dict(synapses_dict):
+            ConfigurationChecker().check_synape_dict(synapses_dict):
 
-            .. seealso:: Synapse
-            .. raises:: NoSynapeName, InvalidSynapeName, NoSynapeNeurons, NoSynapeSignals
-            .. warnings:: Static and Public
+        .. seealso:: Synapse
+        .. raises:: NoSynapeName, InvalidSynapeName, NoSynapeNeurons, NoSynapeSignals
+        .. warnings:: Static and Public
         """
 
         if 'name' not in synape_dict:
@@ -118,31 +112,36 @@ class ConfigurationChecker:
     @staticmethod
     def check_neuron_dict(neuron_dict):
         """
+        Check received neuron dict is valid:
 
-            Check received neuron dict is valid:
-
-            :param neuron_dict: The neuron Dictionary
-            :type neuron_dict: Dict
-            :return: True if neuron is ok
-            :rtype: Boolean
+        :param neuron_dict: The neuron Dictionary
+        :type neuron_dict: Dict
+        :return: True if neuron is ok
+        :rtype: Boolean
 
-            :Example:
+        :Example:
 
-                ConfigurationChecker().check_neuron_dict(neurons_dict):
+            ConfigurationChecker().check_neuron_dict(neurons_dict):
 
-            .. seealso:: Synapse
-            .. raises:: ModuleNotFoundError
-            .. warnings:: Static and Public
+        .. seealso:: Synapse
+        .. raises:: ModuleNotFoundError
+        .. warnings:: Static and Public
         """
 
-
-        def check_neuron_exist(neuron_name):
+        def check_neuron_exist(neuron_module_name):
+            """
+            Return True if the neuron_name python Class exist in neurons package
+            :param neuron_module_name: Name of the neuron module to check
+            :type neuron_module_name: str
+            :return:
+            """
             package_name = "neurons"
-            mod = __import__(package_name, fromlist=[neuron_name])
+            mod = __import__(package_name, fromlist=[neuron_module_name])
             try:
-                getattr(mod, neuron_name)
+                getattr(mod, neuron_module_name)
             except AttributeError:
-                raise ModuleNotFoundError("The module %s does not exist in package %s" % (neuron_name, package_name))
+                raise ModuleNotFoundError("The module %s does not exist in package %s" % (neuron_module_name,
+                                                                                          package_name))
             return True
 
         if isinstance(neuron_dict, dict):
@@ -155,21 +154,20 @@ class ConfigurationChecker:
     @staticmethod
     def check_signal_dict(signal_dict):
         """
+        Check received signal dictionary is valid:
 
-            Check received signal dictionary is valid:
-
-            :param signal_dict: The signal Dictionary
-            :type signal_dict: Dict
-            :return: True if signal are ok
-            :rtype: Boolean
+        :param signal_dict: The signal Dictionary
+        :type signal_dict: Dict
+        :return: True if signal are ok
+        :rtype: Boolean
 
-            :Example:
+        :Example:
 
-                ConfigurationChecker().check_signal_dict(signal_dict):
+            ConfigurationChecker().check_signal_dict(signal_dict):
 
-            .. seealso:: Order, Event
-            .. raises:: NoValidSignal
-            .. warnings:: Static and Public
+        .. seealso:: Order, Event
+        .. raises:: NoValidSignal
+        .. warnings:: Static and Public
         """
 
         if ('event' not in signal_dict) and ('order' not in signal_dict):
@@ -179,21 +177,20 @@ class ConfigurationChecker:
     @staticmethod
     def check_event_dict(event_dict):
         """
+        Check received event dictionary is valid:
 
-            Check received event dictionary is valid:
-
-            :param event_dict: The event Dictionary
-            :type event_dict: Dict
-            :return: True if event are ok
-            :rtype: Boolean
+        :param event_dict: The event Dictionary
+        :type event_dict: Dict
+        :return: True if event are ok
+        :rtype: Boolean
 
-            :Example:
+        :Example:
 
-                ConfigurationChecker().check_event_dict(event_dict):
+            ConfigurationChecker().check_event_dict(event_dict):
 
-            .. seealso::  Event
-            .. raises:: NoEventPeriod
-            .. warnings:: Static and Public
+        .. seealso::  Event
+        .. raises:: NoEventPeriod
+        .. warnings:: Static and Public
         """
 
         if event_dict is None:
@@ -204,21 +201,19 @@ class ConfigurationChecker:
     @staticmethod
     def check_order_dict(order_dict):
         """
+        Check received order dictionary is valid:
 
-            Check received order dictionary is valid:
+        :param order_dict: The Order Dict
+        :type order_dict: Dict
+        :return: True if event are ok
+        :rtype: Boolean
 
-            :param order_dict: The Order Dict
-            :type order_dict: Dict
-            :return: True if event are ok
-            :rtype: Boolean
+        :Example:
 
-            :Example:
+            ConfigurationChecker().check_order_dict(order_dict):
 
-                ConfigurationChecker().check_order_dict(order_dict):
-
-            .. seealso::  Order
-            .. raises:: NoEventPeriod
-            .. warnings:: Static and Public
+        .. seealso::  Order
+        .. warnings:: Static and Public
         """
 
         if order_dict is not None:
@@ -228,25 +223,23 @@ class ConfigurationChecker:
     @staticmethod
     def check_synapes(synapses_list):
         """
-
         Check the synapse list is ok:
                 - No double same name
 
-            :param synapses_list: The Synapse List
-            :type synapses_list: List
-            :return: list of Synapse
-            :rtype: List
+        :param synapses_list: The Synapse List
+        :type synapses_list: List
+        :return: list of Synapse
+        :rtype: List
 
-            :Example:
+        :Example:
 
-                ConfigurationChecker().check_synapes(order_dict):
+            ConfigurationChecker().check_synapes(order_dict):
 
-            .. seealso::  Synapse
-            .. raises:: MultipleSameSynapseName
-            .. warnings:: Static and Public
+        .. seealso::  Synapse
+        .. raises:: MultipleSameSynapseName
+        .. warnings:: Static and Public
         """
 
-
         seen = set()
         for synapse in synapses_list:
             # convert ascii to UTF-8

+ 16 - 27
core/ConfigurationManager/YAMLLoader.py

@@ -9,16 +9,14 @@ logger = logging.getLogger("kalliope")
 
 class YAMLFileNotFound(Exception):
     """
-
-        YAML file has not been found
+    YAML file has not been found
     """
     pass
 
 
 class YAMLLoader:
     """
-        Simple Class to Verify / Load a YAML file.
-
+    Simple Class to Verify / Load a YAML file.
     """
 
     def __init__(self):
@@ -27,21 +25,20 @@ class YAMLLoader:
     @classmethod
     def get_config(cls, yaml_file):
         """
+        Return the provided YAML configuration file
 
-            Return the provided YAML configuration file
-
-            :param yaml_file: The path of the configuration file
-            :type yaml_file: String
-            :return: the configuration file
-            :rtype: String
+        :param yaml_file: The path of the configuration file
+        :type yaml_file: String
+        :return: the configuration file
+        :rtype: String
 
-            :Example:
+        :Example:
 
-                YAMLLoader.get_config(brain_file_path)
+            YAMLLoader.get_config(brain_file_path)
 
-            .. seealso::  SettingLoader, BrainLoader
-            .. raises:: YAMLFileNotFound
-            .. warnings:: Class Method and Public
+        .. seealso::  SettingLoader, BrainLoader
+        .. raises:: YAMLFileNotFound
+        .. warnings:: Class Method and Public
         """
 
         current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -60,16 +57,12 @@ class YAMLLoader:
 
 
 class IncludeImport(object):
-
     """
-
-        This class manages the Include Import statement in the brain.yml file
-
+    This class manages the Include Import statement in the brain.yml file
     """
 
     def __init__(self, file_path):
         """
-
         Load yaml file, with includes statement
         :param file_path: path to the yaml file to load
         """
@@ -93,18 +86,14 @@ class IncludeImport(object):
 
     def get_data(self):
         """
-
-            :return: the data for the IncludeImport
+        :return: the data for the IncludeImport
         """
         return self.data
 
     def update(self, data_to_add):
-
         """
-            Method to Add an other Include statement to the original brain.yml file
-
-            :param data_to_add: the data to add to the current brain.yml, provided by an Include Statement
-
+        Method to Add an other Include statement to the original brain.yml file
+        :param data_to_add: the data to add to the current brain.yml, provided by an Include Statement
         """
 
         # we add each synapse inside the extended brain into the main brain data