Interpret function file path in menu data relative to menu json #428
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.
Previously, it was tricky for application code to use the declarative json menu feature,
because the file paths (
'file'key) were relative to the cwd of the Python interpreter.With this change, application code can construct an absolute path to the shortcut
menu json definition at runtime (using importlib.resources or relative to file, etc)
while the dynamically loaded python module path is assumed relative to the json path.
If an absolute filepath is given in the menu data dict, that is used instead.
I updated the basic_example to use this feature, and as a side effect, it is much more robust and easy to execute.
Now, the user does not have to
cd examples/in order to run the file. The example no long relies on the cwd to resolve file names. Evenpython -m examples.basic_exampleworks.I used the
pathlib.Pathmodule throughout my code. This is the modern and prefered method of dealing with cross-platform paths since Python 3.4. But I understand most of the codebase is still using os.path. My implementation can change, or I can help migrate to the "new"Path()module throughout NodeGraphQt.Edit: I also added a Exit item to the example menu
Edit 2: Oops, looks like I guessed the wrong number for branch name. Can't change that easily now.