Skip to content

Conversation

@jack-mil
Copy link
Contributor

@jack-mil jack-mil commented Jul 13, 2024

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. Even python -m examples.basic_example works.

I used the pathlib.Path module 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.

jack-mil added 3 commits July 12, 2024 20:33
this allows application code to construct an absolute
path to the shortcut menu json definition at runtime
(using importlib.resources or relative to __file__)
while the dynamically loaded python module path
('file' key) is assumed relative to the json path.
If an absolute filepath is given in the menu data dict,
that is used instead.
Makes the basic example much more robust, and able to run without
a specific cwd
@jchanvfx jchanvfx merged commit fd2fd4d into jchanvfx:main Jul 16, 2024
@jchanvfx
Copy link
Owner

Thanks for contributing 😺

@jack-mil
Copy link
Contributor Author

What's your opinion on using pathlib.Path throughout?

@jack-mil jack-mil deleted the menu_func_paths#427 branch July 16, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants