Skip to content

Conversation

@mikofski
Copy link
Member

* layers are plural and sources are singular with the exception of Data layer and DataSource
* ignore spyder project settings file
* with the exception of Data layer and DataSource
* also add messages to NotImplementedError
* new layer names and their sources
* source: DataSource, layer: Data
* source: Calc, layer: Calculations
* source: Formula, layer: Formulas
* source: Output, layer: Outputs
* source: Simulation: layer: Simulations
* add classes (maybe sources?), objects and registry as super class attributes, since they are the same in every subclass
* remove self.data_sources, self.formula_sources, self.calc_sources, self.output_sources and sim_src in lieu of self.classes (or maybe sources?)
* new add(), delete() and edit() methods for super class since required of all layers
* call super().add() in each subclass to import each source into the layer and remove redundant code that imports module/package, checks for underscores and loads updates the sources dictionary in the layer
* replace add() method arguments formula_source, calc_source, output_sources, sim_src  with just the name of the source class, ie: formula, calc, output, sim
* Layers are plural, sources are singular! -> Calculations layer with **s** -> Simulations layer with **s**,
* layers are made of source classes
* change base class items arg to sources.
* to specify registry class constructor for each layer
* remove __init__ from each layer since not necessary!
* add check if reg_cls is a Registry
* change src_obj to objects everywhere: data_obj, formula_obj, calc_obj, output_obj, sim_obj
* change registry to reg everywhere: data, formulas, calcs, outputs, simulations
* update sim_src to sources
* that reg_cls should be Registry class subclass
* that source class should not start with underscore
@mikofski mikofski added this to the v0.3 milestone Aug 10, 2016
@mikofski mikofski self-assigned this Aug 10, 2016
@mikofski mikofski merged commit e5c54a9 into BreakingBytes:master Sep 6, 2016
@mikofski
Copy link
Member Author

mikofski commented Sep 6, 2016

Move data layer arg proposed changes from untracked layers.py files to a new issue.

Summary of untracked files on disk:

layers-data-layers-args-A.py is similar to layers-data-layers-args-B.py but has proposed changes for rel_path

  • use alt_path instead of rel_path
  • filename, path and alt_path not explicitly in function signature for open() in case the data layer doesn't use them, instead method has generic positional and keyword arguments.
  • if data reader has is_file_reader True then gets filename, path and alt_path from args
  • in Outputs layer, move open() method before add() method
  • use private _open() for data layer, but why?
--- Carousel\carousel\core\layers-data-layers-args-B.py
+++ Carousel\carousel\core\layers-data-layers-args-A.py
@@ -73,12 +73,12 @@
         # get layer class definition from the module
         self.classes[src_cls] = getattr(mod, src_cls)

-    def load(self, relpath=None):
+    def load(self, alt_path=None):
         """
         Load the layer from the model data. This method must be implemented by
         each layer.

-        :param relpath: alternate path if specified path is missing or ``None``
+        :param alt_path: alternate path if specified path is missing or ``None``
         :raises: :exc:`~exceptions.NotImplementedError`
         """
         raise NotImplementedError('load')
@@ -149,7 +149,7 @@
         # add a place holder for the data source object when it's constructed
         self.data_obj[data_source] = None

-    def open(self, data_source, filename, path=None, rel_path=None):
+    def _open(self, data_source, *args, **kwargs):
         """
         Open filename to get data for data_source.

@@ -160,13 +160,15 @@
         :type filename: str
         :param path: Path of file containting data. [../data]
         :type path: str
-        :param rel_path: relative path to model file
-        """
-        # default path for data is in ../data
+        :param alt_path: relative path to model file
+        """
+        # args include filename, path and alt_path for data sources with
+        # file readers
+        if self.classes[data_source].data_reader.is_file_reader:
+            filename, path, alt_path = args[:3]
         if not path:
-            path = rel_path
-        else:
-            path = os.path.join(rel_path, path)
+            # no path given use default path relative to model file
+            path = alt_path
         # only update layer info if it is missing!
         if data_source not in self.layer:
             # update path and filename to this layer of the model
@@ -185,14 +187,16 @@
         meta = [getattr(data_src_obj, m) for m in self.data._meta_names]
         self.data.register(data_src_obj.data, *meta)

-    def load(self, rel_path=None):
+    def load(self, path=None):
         """
         Add data_sources to layer and open files with data for the data_source.
+
+        :param path: optional path to use if specified path is missing or None
         """
         for k, v in self.layer.iteritems():
             self.add(k, v['module'], v.get('package'))
             if v.get('filename'):
-                self.open(k, v['filename'], v.get('path'), rel_path)
+                self._open(k, v['filename'], v.get('path', path))

     def edit(self, data_src, value):
         """
@@ -318,6 +322,9 @@
         self.outputs = OutputRegistry()
         # layers are initialized by the model

+    def open(self, output, module, package=None):
+        self.add(output, module, package=package)
+
     def add(self, output, module, package=None):
         """
         Add output to
@@ -330,9 +337,6 @@
         meta = [getattr(out_src_obj, m) for m in self.outputs._meta_names]
         self.outputs.register(out_src_obj.outputs, *meta)

-    def open(self, output, module, package=None):
-        self.add(output, module, package=package)
-
     def load(self, _=None):
         """
         Add output_source to layer.
@@ -356,15 +360,15 @@
         """
         super(Simulations, self).add(sim, module, package)

-    def open(self, sim_src, filename, path=None, rel_path=None):
+    def open(self, sim_src, filename, path=None, alt_path=None):
         # default path for data is in ../simulations
         if not path:
-            path = rel_path
+            path = alt_path
         else:
-            path = os.path.join(rel_path, path)
+            path = os.path.join(alt_path, path)
         filename = os.path.join(path, filename)
         # call constructor of sim source with filename argument
-        self.sim_obj[sim_src] = self.sim_src[sim_src](filename)
+        self.sim_obj[sim_src] = self.classes[sim_src](filename)
         # register simulations in registry, the only reason to register an item
         # is make sure it doesn't overwrite other items
         sim_src_obj = self.sim_obj[sim_src]
@@ -372,10 +376,10 @@
                 self.simulations._meta_names]
         self.simulations.register({sim_src: sim_src_obj}, *meta)

-    def load(self, rel_path=None):
+    def load(self, alt_path=None):
         """
         Add sim_src to layer.
         """
         for k, v in self.layer.iteritems():
             self.add(k, v['module'], v.get('package'))
-            self.open(k, v['filename'], v.get('path'), rel_path)
+            self.open(k, v['filename'], v.get('path'), alt_path)
$ git diff 9771d87b45d9c460aef45c72e9d628085f7d1930:carousel/core/layers.py carousel/core/layers-data-layers-args-B.py

layers-data-layers-args-B.py is same as 9771d87

$ git diff 79c37f6d3cd79c683c0bc7da21f8a54741ff8efd:carousel/core/layers.py  carousel/core/layers-79c37f6d3cd79c683c0bc7da21f8a54741ff8efd.py

layers-79c37f6d3cd79c683c0bc7da21f8a54741ff8efd.py is same as 79c37f6

@mikofski mikofski deleted the datalayer_args branch September 6, 2016 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor layers to remove redundancy make more meaningful, less redundant, shorter names

1 participant