--- a/__pkginfo__.py Wed Feb 13 14:04:48 2019 +0100
+++ b/__pkginfo__.py Wed Feb 13 15:41:11 2019 +0100
@@ -20,7 +20,7 @@
__docformat__ = "restructuredtext en"
modname = "rql"
-numversion = (0, 35, 0)
+numversion = (0, 35, 1)
version = '.'.join(str(num) for num in numversion)
license = 'LGPL'
@@ -74,7 +74,7 @@
)
]
else:
- ext_modules = [ Extension('rql.rql_solve',
+ ext_modules = [Extension('rql.rql_solve',
['rql/gecode_solver.cpp'],
libraries=['GecodeInt-3-3-1-r-x86',
'GecodeKernel-3-3-1-r-x86',
--- a/rql/__init__.py Wed Feb 13 14:04:48 2019 +0100
+++ b/rql/__init__.py Wed Feb 13 15:41:11 2019 +0100
@@ -219,7 +219,7 @@
if nb_lines > 5:
width = log(nb_lines, 10)+1
template = " %%%ii: %%s" % width
- rqlstring = '\n'.join( template % (idx + 1, line) for idx, line in enumerate(multi_lines_rql))
+ rqlstring = '\n'.join(template % (idx + 1, line) for idx, line in enumerate(multi_lines_rql))
msg = '%s\nat: %r\n%s' % (rqlstring, ex.pos, ex.msg)
--- a/rql/analyze.py Wed Feb 13 14:04:48 2019 +0100
+++ b/rql/analyze.py Wed Feb 13 15:41:11 2019 +0100
@@ -85,13 +85,13 @@
def get_constraints(self):
return self.constraints
- def add_expr( self, vars, expr ):
- self.constraints.append( fd.make_expression( vars, expr ) )
+ def add_expr(self, vars, expr ):
+ self.constraints.append(fd.make_expression(vars, expr ) )
self.scons.append(expr)
def var_has_type(self, var, etype):
assert isinstance(etype, string_types)
- self.add_expr( (var,), '%s == %r' % (var, etype) )
+ self.add_expr((var,), '%s == %r' % (var, etype) )
def var_has_types(self, var, etypes):
etypes = tuple(etypes)
@@ -101,10 +101,10 @@
cstr = '%s == "%s"' % (var, etypes[0])
else:
cstr = '%s in %s ' % (var, etypes)
- self.add_expr( (var,), cstr)
+ self.add_expr((var,), cstr)
def vars_have_same_types(self, varnames, types):
- self.add_expr( varnames, '%s in %s' % ( '=='.join(varnames), types))
+ self.add_expr(varnames, '%s in %s' % ('=='.join(varnames), types))
def or_and(self, equalities):
orred = set()
@@ -116,14 +116,14 @@
for t in types:
assert isinstance(t, string_types)
if len(types)==1:
- anded.add( '%s == "%s"' % ( '=='.join(vars), types[0]) )
+ anded.add('%s == "%s"' % ('=='.join(vars), types[0]) )
else:
- anded.add( '%s in %s' % ( '=='.join(vars), types) )
+ anded.add('%s in %s' % ('=='.join(vars), types) )
for var in vars:
variables.add(var)
- orred.add( '(' + ' and '.join( list(anded) ) + ')' )
- expr = " or ".join( list(orred) )
- self.add_expr( tuple(variables), expr )
+ orred.add('(' + ' and '.join(list(anded) ) + ')' )
+ expr = " or ".join(list(orred) )
+ self.add_expr(tuple(variables), expr )
# GECODE based constraint solver
_AND = 0 # symbolic values
@@ -158,7 +158,7 @@
"""
def __init__(self):
self.constraints = []
- self.op = [ _AND ]
+ self.op = [_AND ]
self.domains = {} # maps var name -> var value
self.variables = {} # maps var name -> var index
self.ivariables = [] # maps var index-> var name
@@ -179,16 +179,16 @@
def pretty_print_ops(self, ops):
if ops[0] in (_AND, _OR):
- res = [ OPSYM[ops[0]], '(' ]
+ res = [OPSYM[ops[0]], '(' ]
for op in ops[1:]:
res.append(self.pretty_print_ops(op))
res.append(',')
- res.append( ')' )
+ res.append(')' )
return "".join(res)
elif ops[0] == _EQ:
return "%s==%s" % (self.ivariables[ops[1]], self.ivalues[ops[2]])
elif ops[0] == _EQV:
- res = [ self.ivariables[k] for k in ops[1:] ]
+ res = [self.ivariables[k] for k in ops[1:] ]
return '~='.join(res)
def get_output(self):
@@ -201,7 +201,7 @@
#import time
#t0=time.time()
- sols = rql_solve.solve( self.idx_domains, len(self.all_values), constraints )
+ sols = rql_solve.solve(self.idx_domains, len(self.all_values), constraints )
rql_sols = []
for s in sols:
r={}
@@ -213,7 +213,7 @@
def add_var(self, name, values):
assert name not in self.variables
- self.all_values.update( values )
+ self.all_values.update(values )
self.variables[name] = len(self.variables)
self.ivariables.append(name)
self.domains[name] = values
@@ -222,61 +222,61 @@
# maps integer->value
self.all_values = list(self.all_values)
# maps value->integer
- self.values = dict( [ (v,i) for i,v in enumerate(self.all_values)] )
+ self.values = dict([(v,i) for i,v in enumerate(self.all_values)] )
#print(self.values)
#print(self.domains)
for var_name in self.ivariables:
val_domain = self.domains[var_name]
- idx_domain = [ self.values[val] for val in val_domain ]
- self.idx_domains.append( idx_domain )
+ idx_domain = [self.values[val] for val in val_domain ]
+ self.idx_domains.append(idx_domain )
- def and_eq( self, var, value ):
- self.op.append( [_EQ, self.variables[var], self.values[value] ] )
+ def and_eq(self, var, value ):
+ self.op.append([_EQ, self.variables[var], self.values[value] ] )
def equal_vars(self, varnames):
if len(varnames)>1:
- self.op.append( [ _EQV] + [ self.variables[v] for v in varnames ] )
+ self.op.append([_EQV] + [self.variables[v] for v in varnames ] )
def var_has_type(self, var, etype):
- self.and_eq( var, etype)
+ self.and_eq(var, etype)
def var_has_types(self, var, etypes):
for t in etypes:
assert isinstance(t, string_types)
if len(etypes) == 1:
- self.and_eq( var, tuple(etypes)[0] )
+ self.and_eq(var, tuple(etypes)[0] )
else:
- orred = [ _OR ]
+ orred = [_OR ]
for t in etypes:
try:
- orred.append( [ _EQ, self.variables[var], self.values[t] ] )
+ orred.append([_EQ, self.variables[var], self.values[t] ] )
except KeyError:
# key error may be raised by self.values[t] if self.values
# reflects constraints from subqueries
continue
- self.op.append( orred )
+ self.op.append(orred )
def vars_have_same_types(self, varnames, types):
- self.equal_vars( varnames )
+ self.equal_vars(varnames )
for var in varnames:
- self.var_has_types( var, types )
+ self.var_has_types(var, types )
def or_and(self, equalities):
- orred = [ _OR ]
+ orred = [_OR ]
for orred_expr in equalities:
- anded = [ _AND ]
+ anded = [_AND ]
for vars, types in orred_expr:
- self.equal_vars( vars )
+ self.equal_vars(vars )
for t in types:
assert isinstance(t, string_types)
for var in vars:
if len(types)==1:
- anded.append( [ _EQ, self.variables[var], self.values[types[0]] ] )
+ anded.append([_EQ, self.variables[var], self.values[types[0]] ] )
else:
- or2 = [ _OR ]
+ or2 = [_OR ]
for t in types:
- or2.append( [_EQ, self.variables[var], self.values[t] ] )
- anded.append( or2 )
+ or2.append([_EQ, self.variables[var], self.values[t] ] )
+ anded.append(or2 )
orred.append(anded)
self.op.append(orred)
@@ -373,7 +373,7 @@
pb = CSPProblem()
# set domain for all the variables
for var in node.defined_vars.values():
- pb.add_var( var.name, self._base_domain )
+ pb.add_var(var.name, self._base_domain )
# no variable short cut
return pb
@@ -386,7 +386,7 @@
else:
alltypes = get_target_types()
domain = constraints.domains[var]
- constraints.var_has_types( var, [str(t) for t in alltypes if t in domain] )
+ constraints.var_has_types(var, [str(t) for t in alltypes if t in domain] )
def visit(self, node, uid_func_mapping=None, kwargs=None, debug=False):
# FIXME: not thread safe
@@ -418,7 +418,7 @@
continue
assert etype in self.schema, etype
var = variable.name
- constraints.var_has_type( var, etype )
+ constraints.var_has_type(var, etype )
for relation in node.main_relations:
self._visit(relation, constraints)
# get constraints from the restriction subtree
@@ -451,7 +451,7 @@
for ca in node.aliases.values():
etypes = set(stmt.selection[ca.colnum].get_type(sol, self.kwargs)
for stmt in ca.query.children for sol in stmt.solutions)
- constraints.add_var( ca.name, etypes )
+ constraints.add_var(ca.name, etypes )
constraints.end_domain_definition()
if self.uid_func:
# check rewritten uid const
@@ -470,7 +470,7 @@
# add constraint on real relation types if no restriction
types = [eschema.type for eschema in self.schema.entities()
if not eschema.final]
- constraints.vars_have_same_types( varnames, types )
+ constraints.vars_have_same_types(varnames, types )
self.solve(node, constraints)
def visit_relation(self, relation, constraints):
@@ -489,7 +489,7 @@
else:
etypes = self._uid_node_types(rhs)
if etypes:
- constraints.var_has_types( lhs.name, etypes )
+ constraints.var_has_types(lhs.name, etypes )
return None
if isinstance(rhs, nodes.Comparison):
rhs = rhs.children[0]
@@ -521,19 +521,19 @@
if fromtype in lhsdomain:
totypes = set(str(t) for t in toetypes)
ptypes = totypes & rhsdomain
- res.append( [ ([lhsvar], [str(fromtype)]),
+ res.append([([lhsvar], [str(fromtype)]),
([rhsvar], list(ptypes)) ] )
if same_var and (fromtype in totypes): #ptypes ?
var_types.append(fromtype)
constraints.or_and(res)
if same_var:
- constraints.var_has_types( lhsvar, var_types)
+ constraints.var_has_types(lhsvar, var_types)
else:
# XXX consider rhs.get_type?
lhsdomain = constraints.domains[lhs.name]
ptypes = [str(subj) for subj in rschema.subjects()
if subj in lhsdomain]
- constraints.var_has_types( lhs.name, ptypes )
+ constraints.var_has_types(lhs.name, ptypes )
return None
def visit_type_restriction(self, relation, constraints):
@@ -547,7 +547,7 @@
if relation.neged(strict=True):
etypes = frozenset(t for t in self._nonfinal_domain if not t in etypes)
- constraints.var_has_types( lhs.name, [ str(t) for t in etypes ] )
+ constraints.var_has_types(lhs.name, [str(t) for t in etypes ] )
def visit_and(self, et, constraints):
pass
--- a/rql/nodes.py Wed Feb 13 14:04:48 2019 +0100
+++ b/rql/nodes.py Wed Feb 13 15:41:11 2019 +0100
@@ -40,7 +40,7 @@
'String', 'Substitute', 'etype'))
-ETYPE_PYOBJ_MAP = { bool: 'Boolean',
+ETYPE_PYOBJ_MAP = {bool: 'Boolean',
int: 'Int',
float: 'Float',
Decimal: 'Decimal',
--- a/rql/parser.py Wed Feb 13 14:04:48 2019 +0100
+++ b/rql/parser.py Wed Feb 13 15:41:11 2019 +0100
@@ -562,16 +562,16 @@
while self._peek('ADD_OP', 'QMARK', 'r"\\)"', "','", 'SORT_DESC', 'SORT_ASC', 'CMP_OP', 'R_TYPE', "'IN'", 'GROUPBY', 'ORDERBY', 'WHERE', 'LIMIT', 'OFFSET', 'HAVING', 'WITH', "';'", 'AND', 'OR', context=_context) == 'ADD_OP':
ADD_OP = self._scan('ADD_OP', context=_context)
expr_mul = self.expr_mul(S, _context)
- node = MathExpression( ADD_OP, node, expr_mul )
+ node = MathExpression(ADD_OP, node, expr_mul )
return node
else: # == 'UNARY_OP'
UNARY_OP = self._scan('UNARY_OP', context=_context)
expr_mul = self.expr_mul(S, _context)
- node = UnaryExpression( UNARY_OP, expr_mul )
+ node = UnaryExpression(UNARY_OP, expr_mul )
while self._peek('ADD_OP', 'QMARK', 'r"\\)"', "','", 'SORT_DESC', 'SORT_ASC', 'CMP_OP', 'R_TYPE', "'IN'", 'GROUPBY', 'ORDERBY', 'WHERE', 'LIMIT', 'OFFSET', 'HAVING', 'WITH', "';'", 'AND', 'OR', context=_context) == 'ADD_OP':
ADD_OP = self._scan('ADD_OP', context=_context)
expr_mul = self.expr_mul(S, _context)
- node = MathExpression( ADD_OP, node, expr_mul )
+ node = MathExpression(ADD_OP, node, expr_mul )
return node
def expr_mul(self, S, _parent=None):
@@ -581,7 +581,7 @@
while self._peek('MUL_OP', 'ADD_OP', 'QMARK', 'r"\\)"', "','", 'SORT_DESC', 'SORT_ASC', 'CMP_OP', 'R_TYPE', "'IN'", 'GROUPBY', 'ORDERBY', 'WHERE', 'LIMIT', 'OFFSET', 'HAVING', 'WITH', "';'", 'AND', 'OR', context=_context) == 'MUL_OP':
MUL_OP = self._scan('MUL_OP', context=_context)
expr_pow = self.expr_pow(S, _context)
- node = MathExpression( MUL_OP, node, expr_pow)
+ node = MathExpression(MUL_OP, node, expr_pow)
return node
def expr_pow(self, S, _parent=None):
@@ -591,7 +591,7 @@
while self._peek('POW_OP', 'MUL_OP', 'ADD_OP', 'QMARK', 'r"\\)"', "','", 'SORT_DESC', 'SORT_ASC', 'CMP_OP', 'R_TYPE', "'IN'", 'GROUPBY', 'ORDERBY', 'WHERE', 'LIMIT', 'OFFSET', 'HAVING', 'WITH', "';'", 'AND', 'OR', context=_context) == 'POW_OP':
POW_OP = self._scan('POW_OP', context=_context)
expr_base = self.expr_base(S, _context)
- node = MathExpression( MUL_OP, node, expr_base)
+ node = MathExpression(MUL_OP, node, expr_base)
return node
def expr_base(self, S, _parent=None):
--- a/rql/stcheck.py Wed Feb 13 14:04:48 2019 +0100
+++ b/rql/stcheck.py Wed Feb 13 15:41:11 2019 +0100
@@ -576,7 +576,7 @@
self.schema.rschema(rel.r_type).final:
update_attrvars(newvar, rel, lhs)
lhsvar = getattr(lhs, 'variable', None)
- stinfo['attrvars'].remove( (lhsvar, rel.r_type) )
+ stinfo['attrvars'].remove((lhsvar, rel.r_type) )
if stinfo['attrvar'] is lhsvar:
if stinfo['attrvars']:
stinfo['attrvar'] = next(iter(stinfo['attrvars']))
@@ -705,7 +705,7 @@
# where the `var` attribute variable is used
lhsvar = getattr(lhs, 'variable', None)
try:
- var.stinfo['attrvars'].add( (lhsvar, relation.r_type) )
+ var.stinfo['attrvars'].add((lhsvar, relation.r_type) )
except KeyError:
var.stinfo['attrvars'] = set([(lhsvar, relation.r_type)])
# give priority to variable which is not in an EXISTS as
--- a/rql/stmts.py Wed Feb 13 14:04:48 2019 +0100
+++ b/rql/stmts.py Wed Feb 13 15:41:11 2019 +0100
@@ -920,7 +920,7 @@
#if etype == 'Any':
# raise BadRQLQuery('"Any" is not supported in DELETE statement')
vref.parent = self
- self.main_variables.append( (etype, vref) )
+ self.main_variables.append((etype, vref) )
def add_main_relation(self, relation):
"""add a relation to the list of deleted relations"""
@@ -928,7 +928,7 @@
assert isinstance(relation.children[1], nodes.Comparison)
assert isinstance(relation.children[1].children[0], nodes.VariableRef)
relation.parent = self
- self.main_relations.append( relation )
+ self.main_relations.append(relation )
# repr / as_string / copy #################################################
@@ -1009,7 +1009,7 @@
"""add a variable to the list of inserted variables"""
if etype == 'Any':
raise BadRQLQuery('"Any" is not supported in INSERT statement')
- self.main_variables.append( (etype, vref) )
+ self.main_variables.append((etype, vref) )
vref.parent = self
self.inserted_variables[vref.variable] = 1
@@ -1023,7 +1023,7 @@
insertion variable'
raise BadRQLQuery(msg % (var, var))
relation.parent = self
- self.main_relations.append( relation )
+ self.main_relations.append(relation )
# repr / as_string / copy #################################################
@@ -1096,7 +1096,7 @@
def add_main_relation(self, relation):
"""add a relation to the list of modified relations"""
relation.parent = self
- self.main_relations.append( relation )
+ self.main_relations.append(relation )
# repr / as_string / copy #################################################
--- a/test/unittest_analyze.py Wed Feb 13 14:04:48 2019 +0100
+++ b/test/unittest_analyze.py Wed Feb 13 15:41:11 2019 +0100
@@ -91,72 +91,72 @@
self._types[etype] = EntitySchema(etype)
self._types['Person']._specialized_by = [self._types['Student']]
self._relations = {
- 'eid' : RelationSchema( ( ('Person', ('Int',) ),
+ 'eid' : RelationSchema((('Person', ('Int',) ),
('Student', ('Int',) ),
('Company', ('Int',) ),
('Address', ('Int',) ),
('Eetype', ('Int',) ),
)
),
- 'creation_date' : RelationSchema( ( ('Person', ('Datetime',) ),
+ 'creation_date' : RelationSchema((('Person', ('Datetime',) ),
('Student', ('Datetime',) ),
('Company', ('Datetime',) ),
('Address', ('Datetime',) ),
('Eetype', ('Datetime',) ),
)
),
- 'name' : RelationSchema( ( ('Person', ('String',) ),
+ 'name' : RelationSchema((('Person', ('String',) ),
('Student', ('String',) ),
('Company', ('String',) ),
)
),
- 'firstname' : RelationSchema( ( ('Person', ('String',) ),
+ 'firstname' : RelationSchema((('Person', ('String',) ),
('Student', ('String',) ),
)
),
- 'work_for' : RelationSchema( ( ('Person', ('Company',) ),
+ 'work_for' : RelationSchema((('Person', ('Company',) ),
('Student', ('Company',) ),
),
card='?*'),
- 'is' : RelationSchema( ( ('Person', ('Eetype',) ),
+ 'is' : RelationSchema((('Person', ('Eetype',) ),
('Student', ('Eetype',) ),
('Company', ('Eetype',) ),
('Address', ('Eetype',) ),
('Eetype', ('Eetype',) ),
)
),
- 'is_instance_of' : RelationSchema( ( ('Person', ('Eetype',) ),
+ 'is_instance_of' : RelationSchema((('Person', ('Eetype',) ),
('Student', ('Eetype',) ),
('Company', ('Eetype',) ),
('Address', ('Eetype',) ),
('Eetype', ('Eetype',) ),
)
),
- 'connait' : RelationSchema( (('Person', ('Person',) ),
+ 'connait' : RelationSchema((('Person', ('Person',) ),
('Student', ('Person',) ),
('Student', ('Student',) ),
('Person', ('Student',) ),
),
symmetric=True),
- 'located' : RelationSchema( ( ('Person', ('Address',) ),
+ 'located' : RelationSchema((('Person', ('Address',) ),
('Student', ('Address',) ),
('Company', ('Address',) ),
)
),
- 'owned_by' : RelationSchema( ( ('Person', ('Person',) ),
+ 'owned_by' : RelationSchema((('Person', ('Person',) ),
('Student', ('Person',) ),
('Company', ('Person',) ),
('Eetype', ('Person',) ),
)
),
- 'identity' : RelationSchema( ( ('Person', ('Person',) ),
+ 'identity' : RelationSchema((('Person', ('Person',) ),
('Student', ('Student',) ),
('Company', ('Company',) ),
('Address', ('Address',) ),
('Eetype', ('Eetype',) ),
)
),
- 'number' : RelationSchema( ( ('Person', ('Int',) ),
+ 'number' : RelationSchema((('Person', ('Int',) ),
('Student', ('Int',) ),
('Company', ('Float',) ),
)
--- a/test/unittest_rqlgen.py Wed Feb 13 14:04:48 2019 +0100
+++ b/test/unittest_rqlgen.py Wed Feb 13 15:41:11 2019 +0100
@@ -62,7 +62,7 @@
"""tests select with e_type, attributes, sort, and group
"""
rql = self.rql_generator.select('Person',
- ( ('X','work_for','S'),
+ (('X','work_for','S'),
('S','name','"Logilab"'),
('X','firstname','F'),
('X','surname','S') ),
@@ -76,7 +76,7 @@
def test_where(self):
"""tests the where() method behaviour
"""
- rql = self.rql_generator.where(( ('X','work_for','S'),
+ rql = self.rql_generator.where((('X','work_for','S'),
('S','name','"Logilab"'),
('X','firstname','F'),
('X','surname','S') ) )
--- a/tools/rql_analyze.py Wed Feb 13 14:04:48 2019 +0100
+++ b/tools/rql_analyze.py Wed Feb 13 15:41:11 2019 +0100
@@ -31,7 +31,7 @@
#print(schema)
-def cmp_sol( sol1, sol2 ):
+def cmp_sol(sol1, sol2 ):
ret = True
for l in sol1:
if l not in sol2:
@@ -43,14 +43,14 @@
print("Sol2", l)
return ret
-def analyze_rq( rq ):
+def analyze_rq(rq ):
print("RQL:", rq)
- helper1 = RQLHelper( schema, Resolver=ETypeResolver )
- helper2 = RQLHelper( schema, Resolver=ETypeResolver2 )
- node1 = helper1.parse( rq )
- node2 = helper2.parse( rq )
- sol1 = helper1.get_solutions( node1 )
- sol2 = helper2.get_solutions( node2 )
+ helper1 = RQLHelper(schema, Resolver=ETypeResolver )
+ helper2 = RQLHelper(schema, Resolver=ETypeResolver2 )
+ node1 = helper1.parse(rq )
+ node2 = helper2.parse(rq )
+ sol1 = helper1.get_solutions(node1 )
+ sol2 = helper2.get_solutions(node2 )
return helper1, helper2, node1, node2, sol1, sol2
if len(sys.argv)<2:
@@ -62,6 +62,6 @@
helper1, helper2, node1, node2, sol1, sol2 = analyze_rq(l)
an1 = helper1._rql_analyser
an2 = helper2._rql_analyser
- if not cmp_sol( sol1, sol2 ):
+ if not cmp_sol(sol1, sol2 ):
break
--- a/tools/rql_cmp.py Wed Feb 13 14:04:48 2019 +0100
+++ b/tools/rql_cmp.py Wed Feb 13 15:41:11 2019 +0100
@@ -49,8 +49,8 @@
x1 = cparse(l, builder)
x2 = parse(l)
l = l.strip()
- d1 = make_canon_dict( x1 )
- d2 = make_canon_dict( x2 )
+ d1 = make_canon_dict(x1 )
+ d2 = make_canon_dict(x2 )
t = d1==d2
print('%s : "%s"' % (t,l))
if not t: