Skip to content

Context.substitute only recognize uppercase env vars on Windows #6371

@ccronix

Description

@ccronix

Version: Gaffer 1.5.5.0-windows

Description

Environment variables which not in Context Variables will be convert to uppercase so that Context.substitute() method only recognize uppercase environment variables when use gaffer env python or gaffer dispatch to execute some background command line task.

This is because of CPython's os.environ object will convert all env var names to uppercase on Windows platform:
CPython-3.10 os.py Line: 748

In Gaffer's app env and dispatch, they will use os.environ.copy() to create an env var's dict and pass it to the subprocess.call's env param to launch a new gaffer process, this is a gaffer env's example:
Gaffer-main env-1.py Line: 102 and Line: 117

That will cause when I use GafferUI in foreground, I can use Context.substitute('${Path}') to expand env var Path normally, but in background app I must use ${PATH} rather than ${Path}.

This is because of the Context instance will use a map belongs to a global Environment instance to memorize all env vars in current process, and when a new gaffer process created, this map will be refreshed by reading env vars from the macro environ which all env var names were overrided to uppercase by the parent process in subprocess.call's param:
Gaffer-main Context.cpp Line: 76

In the CG industry pipeline, we use env var path to handle cross platform production requirement, for example working on Windows and submit some batch process or render job to Linux render farm. This bug will cause trouble for the above situation.

Steps to reproduce

  1. Launch an interactive environment by command: gaffer env python
  2. Execute these command:
import Gaffer
script = Gaffer.ScriptNode()
context = script.context()
print(context.substitute('${Path}'))
print(context.substitute('${PATH}'))
  1. print(context.substitute('${Path}')) will return nothing but print(context.substitute('${PATH}')) will return the value of env var Path on your system.
  2. Execute these code in a foreground GafferUI's python editor, print(context.substitute('${PATH}')) will return nothing but print(context.substitute('${Path}')) will return the value of env var Path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions