Merge pull request #38 from ltworf/win_patches

Pick some fixes from the windows branch
master
Salvo 'LtWorf' Tomaselli 2020-08-30 19:47:52 +07:00 committed by GitHub
commit bf4a113f0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

@ -82,8 +82,6 @@ if __name__ == "__main__":
if x11: if x11:
import signal import signal
signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGINT, signal.SIG_DFL)
import sip # needed on windows
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
try: try:
from relational_gui import guihandler, about, surveyForm from relational_gui import guihandler, about, surveyForm

@ -39,6 +39,7 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str:
lines = code.split('\n') lines = code.split('\n')
context: Dict[str, Node] = {} context: Dict[str, Node] = {}
last_res = None
for line in lines: for line in lines:
# skip comments or empty lines # skip comments or empty lines
line = line.strip() line = line.strip()
@ -51,6 +52,9 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str:
parsed = tree(query) parsed = tree(query)
_replace_leaves(parsed, context) _replace_leaves(parsed, context)
context[res] = parsed context[res] = parsed
if last_res is None:
return ''
node = optimize_all(context[last_res], rels, tostr=False) node = optimize_all(context[last_res], rels, tostr=False)
return querysplit.split(node, rels) return querysplit.split(node, rels)

@ -113,7 +113,7 @@ class Relation:
format as defined in RFC4180. format as defined in RFC4180.
''' '''
import csv import csv
with open(filename, 'w') as fp: with open(filename, 'w', newline='\n') as fp:
writer = csv.writer(fp) # Creating csv writer writer = csv.writer(fp) # Creating csv writer
# It wants an iterable containing iterables # It wants an iterable containing iterables
@ -193,7 +193,7 @@ class Relation:
if eval(c_expr, attributes): if eval(c_expr, attributes):
content.append(i) content.append(i)
except Exception as e: except Exception as e:
raise Exception(f'Failed to evaluate {expr} with {attributes}\n{e}') raise Exception(f'Failed to evaluate {expr} with {i}\n{e}')
return Relation(self.header, frozenset(content)) return Relation(self.header, frozenset(content))
def product(self, other: 'Relation') -> 'Relation': def product(self, other: 'Relation') -> 'Relation':