From 37b5ab618f9e2f6295e96d21de7bbd19e8b99415 Mon Sep 17 00:00:00 2001 From: MFA-X-AI <68586800+MFA-X-AI@users.noreply.github.com> Date: Fri, 24 Feb 2023 23:54:18 +0800 Subject: [PATCH 1/2] use utf-8 encoding, filter inCompArg star --- xircuits/compiler/compiler.py | 2 +- xircuits/compiler/parser.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/xircuits/compiler/compiler.py b/xircuits/compiler/compiler.py index cb2240a8..ddf8d7fa 100644 --- a/xircuits/compiler/compiler.py +++ b/xircuits/compiler/compiler.py @@ -17,7 +17,7 @@ def compile(input_file, output_file, component_python_paths=None): def main(): import argparse parser = argparse.ArgumentParser() - parser.add_argument('source_file', type=argparse.FileType('r')) + parser.add_argument('source_file', type=argparse.FileType('r', encoding='utf-8')) parser.add_argument('out_file', type=argparse.FileType('w')) parser.add_argument("python_paths_file", nargs='?', default=None, type=argparse.FileType('r'), help="JSON file with a mapping of component name to required python path. " diff --git a/xircuits/compiler/parser.py b/xircuits/compiler/parser.py index 7a604dd6..4ebea031 100644 --- a/xircuits/compiler/parser.py +++ b/xircuits/compiler/parser.py @@ -1,4 +1,5 @@ import json +import re from xircuits.compiler.node import Node from xircuits.compiler.port import Port @@ -11,6 +12,7 @@ def __init__(self): self.links = {} def parse(self, input_file): + xircuits_file = json.load(input_file) self.nodes = [n for n in xircuits_file['layers'] if n['type'] == 'diagram-nodes'][0]['models'] @@ -38,6 +40,7 @@ def traverse_node(self, node): def traverse_ports(self, node): out = [] + for port in node['ports']: for linkId in port['links']: link = self.links[linkId] @@ -47,12 +50,16 @@ def traverse_ports(self, node): sourceLabel = [p for p in source_node['ports'] if p['id'] == link['sourcePort']][0]['label'] + # filter compulsory port [★] label from port name + sourceLabel = re.sub(r"★", "", sourceLabel) + targetLabel = re.sub(r"★", "", port['label']) + p = Port( name=port['name'], type=link['type'], target=self.traverse_node(target_node), source=self.traverse_node(source_node), - targetLabel=port['label'], + targetLabel=targetLabel, sourceLabel=sourceLabel, direction="in" if port['in'] else "out" ) From ffc6193624be70f5c3be1fa5a203ad47a7cfa22b Mon Sep 17 00:00:00 2001 From: MFA-X-AI <68586800+MFA-X-AI@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:35:36 +0800 Subject: [PATCH 2/2] update compile handler to also use utf-8 --- xircuits/handlers/compile_xircuits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xircuits/handlers/compile_xircuits.py b/xircuits/handlers/compile_xircuits.py index 8f3c9574..b4415bfd 100644 --- a/xircuits/handlers/compile_xircuits.py +++ b/xircuits/handlers/compile_xircuits.py @@ -25,7 +25,7 @@ def post(self): component_python_paths = input_data["pythonPaths"] - with open(self.__get_notebook_absolute_path__(input_file_path), 'r') as infile: + with open(self.__get_notebook_absolute_path__(input_file_path), 'r', encoding='utf-8') as infile: with open(self.__get_notebook_absolute_path__(output_file_path), 'w') as outfile: compile(infile, outfile, component_python_paths)