Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› Fix compulsory inPort args in new compiler #211

Merged
merged 2 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xircuits/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down
9 changes: 8 additions & 1 deletion xircuits/compiler/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import re

from xircuits.compiler.node import Node
from xircuits.compiler.port import Port
Expand All @@ -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']
Expand Down Expand Up @@ -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]
Expand All @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion xircuits/handlers/compile_xircuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down