Skip to content

Session() object for global state #189

@mottosso

Description

@mottosso

Goal

Group global variables and state together into a single object.

Motivation

At the moment, state is spread across at least three places.

  1. Environment, e.g. MINDBENDER_PROJECT
  2. Registry, e.g. api.register_loader_path("c:\some\path")
  3. 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"])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions