Commit 095e9d9a authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[plotter] Fixed documentation related warnings

Also unused import cleanup
parent b17def30
......@@ -36,18 +36,16 @@ Validation for plotters
import os
import six
import simplejson
from . import dataformat
from . import algorithm
from . import library
from . import schema
from . import prototypes
from . import utils
from . import loader
#----------------------------------------------------------
# ----------------------------------------------------------
class Storage(utils.CodeStorage):
......@@ -77,7 +75,7 @@ class Storage(utils.CodeStorage):
super(Storage, self).__init__(path, language)
#----------------------------------------------------------
# ----------------------------------------------------------
class Runner(algorithm.Runner):
......@@ -101,7 +99,7 @@ class Runner(algorithm.Runner):
return loader.run(self.obj, 'process', self.exc, inputs)
#----------------------------------------------------------
# ----------------------------------------------------------
class Plotter(object):
......@@ -159,8 +157,8 @@ class Plotter(object):
uses (dict): A mapping object defining the required library import name
(keys) and the full-names (values).
parameters (dict): A dictionary containing all pre-defined parameters that
this algorithm accepts.
parameters (dict): A dictionary containing all pre-defined parameters
that this algorithm accepts.
errors (list): A list containing errors found while loading this
algorithm.
......@@ -200,17 +198,17 @@ class Plotter(object):
code = None
if data is None: #loads prototype and validates it
if data is None: # loads prototype and validates it
data = None
code = None
elif isinstance(data, (tuple, list)): #user has passed individual info
elif isinstance(data, (tuple, list)): # user has passed individual info
data, code = data #break down into two components
data, code = data # break down into two components
if isinstance(data, six.string_types): #user has passed a file pointer
if isinstance(data, six.string_types): # user has passed a file pointer
self._name = data
self.storage = Storage(self.prefix, self._name)
......@@ -218,19 +216,19 @@ class Plotter(object):
self.errors.append('Plotter declaration file not found: %s' % data)
return
data = self.storage.json.path #loads data from JSON declaration
data = self.storage.json.path # loads data from JSON declaration
# At this point, `data' can be a dictionary or ``None``
if data is None: # loads the default declaration for an algorithm
if data is None: # loads the default declaration for an algorithm
self.data, self.errors = prototypes.load('plotter')
assert not self.errors, "\n * %s" % "\n *".join(self.errors)
else: # just assign it
else: # just assign it
# this runs basic validation, including JSON loading if required
self.data, self.errors = schema.validate('plotter', data)
if self.errors: return #don't proceed with the rest of validation
if self.errors: return # don't proceed with the rest of validation
if self.storage is not None: #loading from the disk, check code
if not self.storage.code.exists():
......@@ -242,15 +240,15 @@ class Plotter(object):
# At this point, `code' can be a string (or a binary blob) or ``None``
if code is None: # loads the default code for an algorithm
if code is None: # loads the default code for an algorithm
self.code = prototypes.binary_load('plotter.py')
self.data['language'] = 'python'
else: # just assign it - notice that in this case, no language is set
else: # just assign it - notice that in this case, no language is set
self.code = code
if self.errors: return #don't proceed with the rest of validation
if self.errors: return # don't proceed with the rest of validation
# if no errors so far, make sense out of the declaration data
......@@ -293,7 +291,7 @@ class Plotter(object):
name = self.data['dataformat']
if dataformat_cache and name in dataformat_cache: #reuse
if dataformat_cache and name in dataformat_cache: # reuse
self.dataformat = dataformat_cache[name]
else: #load it
self.dataformat = dataformat.DataFormat(self.prefix, name,
......@@ -321,7 +319,6 @@ class Plotter(object):
@name.setter
def name(self, value):
if self.data['language'] == 'unknown':
raise RuntimeError("plotter has no programming language set")
......@@ -369,7 +366,8 @@ class Plotter(object):
Parameters:
klass (str): The name of the class to load the runnable algorithm from
klass (str): The name of the class to load the runnable algorithm
from
exc (:std:term:`class`): If passed, must be a valid exception class
that will be used to report errors in the read-out of this
......@@ -406,7 +404,7 @@ class Plotter(object):
type, value, traceback = sys.exc_info()
six.reraise(exc, exc(value), traceback)
else:
raise #just re-raise the user exception
raise # just re-raise the user exception
return Runner(self.__module, klass, self, exc)
......@@ -469,7 +467,7 @@ class Plotter(object):
if storage is None:
if not self._name:
raise RuntimeError("plotter has no name")
storage = self.storage #overwrite
storage = self.storage # overwrite
storage.save(str(self), self.code, self.description)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment