rez
rez copied to clipboard
add Application class
Related: https://github.com/nerdvegas/rez/issues/809, https://github.com/nerdvegas/rez/issues/1033
Currently some rez state is stored globally. Specifically:
- Package / package repo cached state. Specifically, rez will not see newly released packages until you either start a new python session, or explicitly call
clear_caches
. - The config is global.
It would be better to introduce the concept of an 'application instance'. This would allow you to manage multiple different configurations of rez within the one py proc for eg. Backwards compatibility would be achieved by there being a default global app instance.
Note that I don't think this is technically a difficult thing to do, but it would touch a lot of code and be fairly disruptive. It would probably take a while to implement this change.
I just wanted to clarify for myself why having global state in Rez is bad.
The specific case I'm thinking of if is if I want to load configuration settings from entirely new configuration files at runtime (by modifying REZ_CONFIG_FILE).
Lets say I have my own package that imports Rez, called package 'A'.
From what I'm gathering, there is no clean way to rerun Config._create_main_config
currently from package 'A'. Due to some intricacies in Python, attempting to run the following in package 'A' will not entirely reload the configuration settings across the application:
import rez.config
rez.config.config = rez.config.Config._create_main_config()
I believe this is because of a few things:
-
rez.config.Config._create_main_config
creates an entirely new Object and is not mutating the original Config class. - The variable is global to the
config.py
module. - As mentioned here, "For efficiency reasons, each module is only imported once per interpreter session."
In the case above, we are actually assigning the name rez.config.config
to a new Object, and this will not be reflected in any of the submodules of rez
(ex. rez.resolved_context, rez.utils.execution etc. will NOT know about the newly loaded config).
Because of this issue, it's not currently possible to cleanly reload the config after changing the REZ_CONFIG_FILE
environment variable during a single Python runtime.
I know I'm likely missing something here, but does this sound accurate?
#My 2¢, is that given the use, perhaps Application is not the best name. Naming is of course subjective and hard, but I'd encourage picking something that is less likely to confuse a beginner as being relevant to an Application that Rez manages.
Good point Dhruv