Resolve environment variables in dev bundle addon paths#1429
Resolve environment variables in dev bundle addon paths#1429
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for environment variable resolution in dev bundle addon paths using the standard {VAR_NAME} format. This allows dev bundles to work across multiple platforms by resolving environment variables at runtime.
- Adds environment variable resolution to dev addon paths using string format syntax
- Enables cross-platform compatibility for dev bundles through environment variable substitution
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
client/ayon_core/addon/base.py
Outdated
| if use_dev_path: | ||
| addon_dir = dev_addon_info["path"] | ||
| if addon_dir: | ||
| addon_dir = addon_dir.format(**os.environ) |
There was a problem hiding this comment.
Using str.format(**os.environ) with user-controlled input can be unsafe as it exposes all environment variables and could lead to format string injection attacks. Consider using os.path.expandvars() instead, which safely expands environment variables in the $VAR or ${VAR} format, or implement a safer custom formatter that only allows specific variable patterns.
| addon_dir = addon_dir.format(**os.environ) | |
| addon_dir = os.path.expandvars(addon_dir) |
client/ayon_core/addon/base.py
Outdated
| if addon_dir: | ||
| addon_dir = addon_dir.format(**os.environ) |
There was a problem hiding this comment.
The code will raise a KeyError if the path contains environment variable placeholders that don't exist in os.environ. Consider wrapping this in a try-except block or using a safer method like string.Template.safe_substitute() to handle missing variables gracefully.
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Changelog Description
Add support of resolution of environment variables in dev bundle addon paths. You can use standard
{FOO_BAR}format within the path. This can be used to set dev bundle to work on multiple platforms provided the environment variable is set there.Additional info
This also needs PR in
ayon-launcherynput/ayon-launcher#253Testing notes:
{DEV_ADDONS}/ayon-core/client