-
Notifications
You must be signed in to change notification settings - Fork 17
Datalayer args #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Datalayer args #50
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
mikofski
commented
Aug 10, 2016
- fixes refactor layers to remove redundancy #49 refactor layers to remove redundancy
- fixes make more meaningful, less redundant, shorter names #26 more meaningful less redundant names in layers module
* 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
Member
Author
|
Move data layer arg proposed changes from untracked Summary of untracked files on disk:
--- 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)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.