Commit b17def30 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[library] Fixed documentation related warnings

Also unused import cleanup
parent 5cf4f1c1
......@@ -34,16 +34,10 @@ library
Validation for libraries
"""
import os
import six
import simplejson
from . import dataformat
from . import schema
from . import prototypes
from . import loader
from . import utils
from beat.backend.python.library import Storage
from beat.backend.python.library import Library as BackendLibrary
......@@ -118,20 +112,18 @@ class Library(BackendLibrary):
self._name = None
self.storage = None
self.libraries = {} # preloaded libraries
self.libraries = {} # preloaded libraries
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
# make sure to log this into the cache (avoids recursion)
library_cache[data] = None
......@@ -141,21 +133,21 @@ class Library(BackendLibrary):
self.errors.append('Library 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 library
if data is None: # loads the default declaration for an library
self.data, self.errors = prototypes.load('library')
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('library', 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 self.storage is not None: # loading from the disk, check code
if not self.storage.code.exists():
self.errors.append('Library code not found: %s' % \
self.storage.code.path)
......@@ -165,15 +157,15 @@ class Library(BackendLibrary):
# At this point, `code' can be a string (or a binary blob) or ``None``
if code is None: # loads the default code for an library
if code is None: # loads the default code for an library
self.code = prototypes.binary_load('library.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 library data
......@@ -181,7 +173,7 @@ class Library(BackendLibrary):
# now we check for consistence
self._validate_required_libraries(library_cache)
if self.errors: return #don't proceed with the rest of validation
if self.errors: return # don't proceed with the rest of validation
self._check_language_consistence()
......@@ -191,9 +183,7 @@ class Library(BackendLibrary):
# all used libraries must be loadable; cannot use self as a library
if self.uses is not None:
for name, value in self.uses.items():
if value in library_cache:
if library_cache[value] is None:
self.errors.append("recursion for library `%s' detected" % value)
......@@ -210,13 +200,11 @@ class Library(BackendLibrary):
def _check_language_consistence(self):
# all used libraries must be programmed with the same language
if self.language == 'unknown': return #bail out on unknown language
if self.language == 'unknown': return # bail out on unknown language
if self.uses is not None:
for name, library in self.uses.items():
if library not in self.libraries: continue #invalid
if library not in self.libraries: continue # invalid
if self.libraries[library].language != self.language:
self.errors.append("language for used library `%s' (`%s') " \
......
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