[cleanup] Fix some flake8 errors
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 03 Nov 2017 12:27:51 +0100
changeset 12227 dc333e9104c9
parent 12226 2e2425d2d54d
child 12229 a812e9a75831
[cleanup] Fix some flake8 errors
cubicweb/hooks/synccomputed.py
cubicweb/server/ssplanner.py
flake8-ok-files.txt
--- a/cubicweb/hooks/synccomputed.py	Mon Oct 30 09:37:20 2017 +0100
+++ b/cubicweb/hooks/synccomputed.py	Fri Nov 03 12:27:51 2017 +0100
@@ -18,8 +18,6 @@
 """Hooks for synchronizing computed attributes"""
 
 
-from cubicweb import _
-
 from collections import defaultdict
 
 from rql import nodes
@@ -33,6 +31,7 @@
     recompute twice the same attribute
     """
     containercls = dict
+
     def add_data(self, computed_attribute, eid=None):
         try:
             self._container[computed_attribute].add(eid)
@@ -42,7 +41,7 @@
     def precommit_event(self):
         for computed_attribute_rdef, eids in self.get_data().items():
             attr = computed_attribute_rdef.rtype
-            formula  = computed_attribute_rdef.formula
+            formula = computed_attribute_rdef.formula
             select = self.cnx.repo.vreg.rqlhelper.parse(formula).children[0]
             xvar = select.get_variable('X')
             select.add_selected(xvar, index=0)
@@ -151,7 +150,7 @@
         # depending entity types {dep. etype: {computed rdef: dep. etype attributes}}
         self.computed_attribute_by_etype_attrs = defaultdict(lambda: defaultdict(set))
         # depending relations def {dep. rdef: [computed rdefs]
-        self.computed_attribute_by_relation = defaultdict(list) # by rdef
+        self.computed_attribute_by_relation = defaultdict(list)  # by rdef
         # Walk through all attributes definitions
         for rdef in schema.iter_computed_attributes():
             self.computed_attribute_by_etype[rdef.subject.type].append(rdef)
@@ -171,7 +170,8 @@
                         object_etypes = rschema.objects(subject_etype)
                     for object_etype in object_etypes:
                         if rschema.final:
-                            attr_for_computations = self.computed_attribute_by_etype_attrs[subject_etype]
+                            attr_for_computations = self.computed_attribute_by_etype_attrs[
+                                subject_etype]
                             attr_for_computations[rdef].add(rschema.type)
                         else:
                             depend_on_rdef = rschema.rdefs[subject_etype, object_etype]
@@ -184,7 +184,7 @@
             yield type('%sCreatedHook' % etype,
                        (EntityWithCACreatedHook,),
                        {'__regid__': regid,
-                        '__select__':  hook.Hook.__select__ & selector,
+                        '__select__': hook.Hook.__select__ & selector,
                         'computed_attributes': computed_attributes})
 
     def generate_relation_change_hooks(self):
@@ -198,11 +198,11 @@
                 optimized_computed_attributes.append(
                     (computed_rdef,
                      _optimize_on(computed_rdef.formula_select, rdef.rtype))
-                     )
+                )
             yield type('%sModifiedHook' % rdef.rtype,
                        (RelationInvolvedInCAModifiedHook,),
                        {'__regid__': regid,
-                        '__select__':  hook.Hook.__select__ & selector,
+                        '__select__': hook.Hook.__select__ & selector,
                         'optimized_computed_attributes': optimized_computed_attributes})
 
     def generate_entity_update_hooks(self):
@@ -212,7 +212,7 @@
             yield type('%sModifiedHook' % etype,
                        (AttributeInvolvedInCAModifiedHook,),
                        {'__regid__': regid,
-                        '__select__':  hook.Hook.__select__ & selector,
+                        '__select__': hook.Hook.__select__ & selector,
                         'attributes_computed_attributes': attributes_computed_attributes})
 
 
--- a/cubicweb/server/ssplanner.py	Mon Oct 30 09:37:20 2017 +0100
+++ b/cubicweb/server/ssplanner.py	Fri Nov 03 12:27:51 2017 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -32,6 +32,7 @@
 _CONSTANT = object()
 _FROM_SUBSTEP = object()
 
+
 def _extract_const_attributes(plan, rqlst, to_build):
     """add constant values to entity def, mark variables to be selected
     """
@@ -61,9 +62,10 @@
                 # create a relation between two newly created variables
                 plan.add_relation_def((edef, rtype, to_build[rhs.name]))
             else:
-                to_select.setdefault(edef, []).append( (rtype, rhs, 0) )
+                to_select.setdefault(edef, []).append((rtype, rhs, 0))
     return to_select
 
+
 def _extract_eid_consts(plan, rqlst):
     """return a dict mapping rqlst variable object to their eid if specified in
     the syntax tree
@@ -78,10 +80,10 @@
     for rel in rqlst.where.get_nodes(Relation):
         # only care for 'eid' relations ...
         if (rel.r_type == 'eid'
-            # ... that are not part of a NOT clause ...
-            and not rel.neged(strict=True)
-            # ... and where eid is specified by '=' operator.
-            and rel.children[1].operator == '='):
+                # ... that are not part of a NOT clause ...
+                and not rel.neged(strict=True)
+                # ... and where eid is specified by '=' operator.
+                and rel.children[1].operator == '='):
             lhs, rhs = rel.get_variable_parts()
             if isinstance(rhs, Constant):
                 eid = int(rhs.eval(plan.args))
@@ -95,6 +97,7 @@
                 eidconsts[lhs.variable] = eid
     return eidconsts
 
+
 def _build_substep_query(select, origrqlst):
     """Finalize substep select query that should be executed to get proper
     selection of stuff to insert/update.
@@ -119,6 +122,7 @@
         return select
     return None
 
+
 class SSPlanner(object):
     """SingleSourcePlanner: build execution plan for rql queries
 
@@ -160,7 +164,7 @@
         # add constant values to entity def, mark variables to be selected
         to_select = _extract_const_attributes(plan, rqlst, to_build)
         # add necessary steps to add relations and update attributes
-        step = InsertStep(plan) # insert each entity and its relations
+        step = InsertStep(plan)  # insert each entity and its relations
         step.children += self._compute_relation_steps(plan, rqlst, to_select)
         return (step,)
 
@@ -237,9 +241,8 @@
         getrschema = self.schema.rschema
         select = Select()   # potential substep query
         selectedidx = {}    # local state
-        attributes = set()  # edited attributes
         updatedefs = []     # definition of update attributes/relations
-        selidx = residx = 0 # substep selection / resulting rset indexes
+        selidx = residx = 0  # substep selection / resulting rset indexes
         # search for eid const in the WHERE clause
         eidconsts = _extract_eid_consts(plan, rqlst)
         # build `updatedefs` describing things to update and add necessary
@@ -250,7 +253,7 @@
                                  % relation.r_type)
             lhs, rhs = relation.get_variable_parts()
             lhskey = lhs.as_string()
-            if not lhskey in selectedidx:
+            if lhskey not in selectedidx:
                 if lhs.variable in eidconsts:
                     eid = eidconsts[lhs.variable]
                     lhsinfo = (_CONSTANT, eid, residx)
@@ -263,7 +266,7 @@
             else:
                 lhsinfo = selectedidx[lhskey][:-1] + (None,)
             rhskey = rhs.as_string()
-            if not rhskey in selectedidx:
+            if rhskey not in selectedidx:
                 if isinstance(rhs, Constant):
                     rhsinfo = (_CONSTANT, rhs.eval(plan.args), residx)
                 elif getattr(rhs, 'variable', None) in eidconsts:
@@ -278,7 +281,7 @@
             else:
                 rhsinfo = selectedidx[rhskey][:-1] + (None,)
             rschema = getrschema(relation.r_type)
-            updatedefs.append( (lhsinfo, rhsinfo, rschema) )
+            updatedefs.append((lhsinfo, rhsinfo, rschema))
         # the update step
         step = UpdateStep(plan, updatedefs)
         # when necessary add substep to fetch yet unknown values
@@ -359,7 +362,6 @@
         # get results for query
         source = cnx.repo.system_source
         result = source.syntax_tree_search(cnx, union, args, cachekey)
-        #print 'ONEFETCH RESULT %s' % (result)
         return result
 
     def mytest_repr(self):
@@ -413,10 +415,10 @@
                 if rorder == InsertRelationsStep.FINAL:
                     edef.edited_attribute(rtype, value)
                 elif rorder == InsertRelationsStep.RELATION:
-                    self.plan.add_relation_def( (edef, rtype, value) )
+                    self.plan.add_relation_def((edef, rtype, value))
                     edef.querier_pending_relations[(rtype, 'subject')] = value
                 else:
-                    self.plan.add_relation_def( (value, rtype, edef) )
+                    self.plan.add_relation_def((value, rtype, edef))
                     edef.querier_pending_relations[(rtype, 'object')] = value
             edefs.append(edef)
         self.plan.substitute_entity_def(base_edef, edefs)
@@ -452,6 +454,7 @@
             cnx.repo.glob_delete_entities(cnx, todelete)
         return results
 
+
 class DeleteRelationsStep(Step):
     """step consisting in deleting relations"""
 
@@ -513,10 +516,11 @@
             repo.glob_update_entity(cnx, edited)
         return result
 
+
 def _handle_relterm(info, row, newrow):
     if info[0] is _CONSTANT:
         val = info[1]
-    else: # _FROM_SUBSTEP
+    else:  # _FROM_SUBSTEP
         val = row[info[1]]
     if info[-1] is not None:
         newrow.append(val)
--- a/flake8-ok-files.txt	Mon Oct 30 09:37:20 2017 +0100
+++ b/flake8-ok-files.txt	Fri Nov 03 12:27:51 2017 +0100
@@ -27,6 +27,7 @@
 cubicweb/etwist/request.py
 cubicweb/etwist/service.py
 cubicweb/ext/__init__.py
+cubicweb/hooks/synccomputed.py
 cubicweb/hooks/syncsources.py
 cubicweb/hooks/test/data/hooks.py
 cubicweb/hooks/test/unittest_notificationhooks.py
@@ -46,6 +47,7 @@
 cubicweb/server/sources/__init__.py
 cubicweb/server/sources/native.py
 cubicweb/server/sqlutils.py
+cubicweb/server/ssplanner.py
 cubicweb/server/utils.py
 cubicweb/server/test/datacomputed/migratedapp/schema.py
 cubicweb/server/test/datacomputed/schema.py