Refactor Nodes to individual files; Add/execute Custom Nodes#70
Merged
Refactor Nodes to individual files; Add/execute Custom Nodes#70
Conversation
Factors out some duplicate code. PR #57 adds a `to_json()` method that might be able to replace the `extract_node_info()` method here. TBD.
`check_missing_packages()` is duplicated from `vp/views.py`. It should find a home.
Closed
reddigari
approved these changes
Apr 25, 2020
Collaborator
There was a problem hiding this comment.
Absolutely phenomenal work!
Only issue I had was when checking out the branch, the node collection fails because there's no custom_nodes directory by default, and so the import fails. Worked fine after I added an empty directory. I'd recommend checking in an empty directory with that name if that's possible.
Member
Author
|
Good catch on the Latest commit should address this bug and also streamlines the two 'dir' methods into one |
reddigari
requested changes
Apr 25, 2020
reddigari
approved these changes
Apr 25, 2020
Collaborator
|
As soon as this is merged I've got a PR with the front end upload functionality ready to go. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This builds off the initial approach for custom nodes in now-closed #66, in much the same way, but now more refined and now with a change to regular Node classes.
Changed endpoints:
/nodes->/workflow/nodes: Retrieves list of Nodes for the front-end to display. Response is structured the same; more on the move to Workflow below./workflow/upload: Now a generic upload endpoint that can accept Node data files (e.g. CSVs) and now custom Node classes. If nonode_idis specified in thePOSTbody, a file path for the custom node is generated.For custom nodes, no package/import validation is performed on upload. The intended process would be:
/workflow/nodesagain for an updating node listing.Changes to
workflow.py:_node_dirattribute to theWorkflowclassnode_pathaccessor method that constructs a path to a given Node file.get_packaged_nodes: This is the method that handles parsing of pyworkflow and custom nodes. There's documentation in the code, but briefly this:self.node_path. Each directory is thenode_type(e.g. 'io', 'manipulation', and now 'custom_nodes') and each file within the directory represents an individual Node class.import lib.import_moduleto dynamically load the Class and usesModuleFinder.run_scriptto extract any missing packages if the import failed.self._graphcalls to the publicself.graph. Changesupload_fileto static, and accepting ato_openfile path instead ofnode_id. See bullet 2 above in Changed endpoints.Changes to
node.py:This is the biggest change of the PR and should help with modularity/customization moving forward. The main
Nodeclass is still defined inpyworkflow/node.py, but now, concrete classes are defined in individual files withinpyworkflow/nodes/<node_type>directories.Benefits this approach brings are:
import_module('pyworkflow.nodes.' + node_type + '.' + node)for all node types.nodes.pyfile.Testing:
This should not affect any other functionality and all Postman/unit tests continue to pass. To test out custom nodes, you can copy any exiting node (e.g.,
io/read_csv.py) to thepyworkflow/custom_nodesdirectory. If you refresh the front-end, the Node should now appear under 'Custom Nodes' and if you drag it to the workspace, it should work identically to the 'I/O' Read CSV Node, including execution. (If you change the name and/or color attributes in the custom Node file, it is easier to see the different Nodes once in the workspace).TBD:
This addresses question 1 in issue #67 (where do custom nodes live). It still does not address question 2 (installation of missing packages), but it has features in place to help with that (e.g., returning a list of missing package names). @matthew-t-smith had mentioned
docker execmight be able to runpipenv installwithout starting/stopping the container. I think it's probably best to wait for the Docker-ization before tackling package installation to better see how it interacts in that case.