Skip to content

Commit

Permalink
June Fixes Round 2 (#167)
Browse files Browse the repository at this point in the history
* Fixes inability to load transformations with selected items

* Bump version

* Add fallback method for older versions for getting xforms

* Remove production dependency on node_modules

* Query online metadata if available

Closes #158

* Start process of adding custom transformations

* Allow adding of custom transformations

Closes #106.

* Allow adding custom xfs from files or directories

* Fix indiscriminate expansion of library nodes

Closes #161.
Closes #168.

* Fix vanishing subgraph transformations from xf history

Closes #131.
  • Loading branch information
phschaad authored Jun 23, 2022
1 parent 7cc5d17 commit 1fdeabb
Show file tree
Hide file tree
Showing 14 changed files with 1,220 additions and 3,578 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"preLaunchTask": "${defaultBuildTask}"
}
]
}
}
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.vscode/**
.vscode-test/**
out/test/**
out/**
src/**
.gitignore
tslint.json
Expand All @@ -10,3 +10,4 @@ vsc-extension-quickstart.md
**/.eslintrc.json
**/*.map
**/*.ts
node_modules/**
31 changes: 28 additions & 3 deletions backend/dace_vscode/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dace_vscode import utils
import sys
import traceback
import importlib.util

def expand_library_node(json_in):
"""
Expand All @@ -30,7 +31,7 @@ def expand_library_node(json_in):
}

try:
sdfg_id, state_id, node_id = json_in['nodeId']
sdfg_id, state_id, node_id = json_in['nodeid']
except KeyError:
sdfg_id, state_id, node_id = None, None, None

Expand Down Expand Up @@ -80,6 +81,7 @@ def reapply_history_until(sdfg_json, index):
transformation._sdfg = original_sdfg.sdfg_list[transformation.sdfg_id]
try:
if isinstance(transformation, SubgraphTransformation):
transformation._sdfg.append_transformation(transformation)
transformation.apply(
original_sdfg.sdfg_list[transformation.sdfg_id]
)
Expand Down Expand Up @@ -149,6 +151,20 @@ def apply_transformation(sdfg_json, transformation_json):
}


def add_custom_transformations(filepaths):
for xf_path in filepaths:
if not xf_path in sys.modules:
xf_module_spec = importlib.util.spec_from_file_location(
xf_path, xf_path
)
xf_module = importlib.util.module_from_spec(xf_module_spec)
sys.modules[xf_path] = xf_module
xf_module_spec.loader.exec_module(xf_module)
return {
'done': True,
}


def get_transformations(sdfg_json, selected_elements, permissive):
# We lazy import DaCe, not to break cyclic imports, but to avoid any large
# delays when booting in daemon mode.
Expand Down Expand Up @@ -217,9 +233,18 @@ def get_transformations(sdfg_json, selected_elements, permissive):
extensions = SubgraphTransformation.subclasses_recursive()

for xform in extensions:
if len(selected_states) > 0: # Subgraph transformations are single-state
# Subgraph transformations are single-state.
if len(selected_states) > 0:
continue
xform_obj = xform(subgraph)
xform_obj = None
try:
xform_obj = xform()
xform_obj.setup_match(subgraph)
except:
# If the above method throws an exception, it might be because
# an older version of dace (<= 0.13.1) is being used - attempt
# to construct subgraph transformations using the old API.
xform_obj = xform(subgraph)
if xform_obj.can_be_applied(selected_sdfg, subgraph):
transformations.append(xform_obj.to_json())
docstrings[xform.__name__] = xform_obj.__doc__
Expand Down
5 changes: 5 additions & 0 deletions backend/run_dace.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ def _get_transformations():
request_json['sdfg'], request_json['selected_elements'],
request_json['permissive'])

@daemon.route('/add_transformations', methods=['POST'])
def _add_transformations():
request_json = request.get_json()
return transformations.add_custom_transformations(request_json['paths'])

@daemon.route('/apply_transformation', methods=['POST'])
def _apply_transformation():
request_json = request.get_json()
Expand Down
16 changes: 4 additions & 12 deletions media/components/sdfv/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
<script>
// Reference to the VSCode API.
let vscode = undefined;
const SPLIT_DIRECTION = 'vertical';
</script>

<script src="{{ NODE_MODULES }}/@spcl/sdfv/external_lib/pdfkit.standalone.js"></script>
<script src="{{ NODE_MODULES }}/@spcl/sdfv/external_lib/blob-stream.js"></script>
<script src="{{ NODE_MODULES }}/@spcl/sdfv/external_lib/canvas2pdf.js"></script>

<script src="{{ NODE_MODULES }}/split.js/dist/split.min.js"></script>
<script src="{{ SCRIPT_SRC }}/pdfkit.standalone.js"></script>
<script src="{{ SCRIPT_SRC }}/blob-stream.js"></script>
<script src="{{ SCRIPT_SRC }}/canvas2pdf.js"></script>
</head>

<body style="display: none;">
Expand Down Expand Up @@ -198,13 +197,6 @@ <h5 id="info-title"></h5>

<script>
vscode = acquireVsCodeApi();

Split(['#contents', '#info-container'], {
sizes: [60, 40],
minSize: [0, 0],
snapOffset: 10,
direction: 'vertical',
});
</script>
</body>

Expand Down
Loading

0 comments on commit 1fdeabb

Please sign in to comment.