-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Goal
Group global variables and state together into a single object.
Motivation
At the moment, state is spread across at least three places.
- Environment, e.g.
MINDBENDER_PROJECT - Registry, e.g.
api.register_loader_path("c:\some\path") io.py, e.g.io.activate_project("this_project")
This makes it challenging to know what the current state is, which complicates tests and maintenance. Communicating and understanding state is also complicated.
Traces of leaked global state:
Implementation
Do what Python does.
Python uses environment variables for state as well, but not at run-time. Instead, it reads it once upon launch, and stores it internally. PYTHONPATH for example is parsed and stored as a list in sys.path.
On initialisation of the pipeline, look at the various sources supported, such as the environment, and build a Session object/dictionary containing all state. This is then used at run-time, and can be inspected during debugging, created during testing and replicated in order to simulate more than a single state; such as when browsing assets in one project from another.
session = api.Session(
project="Hulk",
asset="Bruce",
task="modeling",
loaders="/path/to/loaders",
creators="/path/to/creators"
)
for asset in session.find({"type": "asset"}):
print(asset["name"])