mottosso / bleeding-rez

Rez - Reproducible software environments for Windows, Linux and MacOS
GNU Lesser General Public License v3.0
72 stars 10 forks source link

Environment Variable Source #59

Open mottosso opened 5 years ago

mottosso commented 5 years ago

Goal

Help the package author understand where a given variable is coming from.

Motivation

In a complex environment, it can be challenging or impossible to determine whether a particular environment variable, or part of a variable, is coming from. Every package is able to append, prepend or replace a given variable.

Alternatives

Implementation

Wrap variables in a mutable EnvironmentVariable class, that tracks its point of origin during use.

def commands():
  env["MYVARIABLE"] = "Test"
  # Storing {"MYVARIABLE": [__file__]}

Stored values are of type list, so as to facilitate multiple authors of a given variable.

env["MYVARIBLE"].authors()
["~/packages/mypackage/1.0.1/package.py", "~/packages/otherpackage/3.15/package.py"]

Ordered by which wrote first.

For PATH-like variables, the same principle applies.

env["PATH"].authors()
["~/packages/mypackages/1.0.1/package.py"]

An empty list indicates that this variable is not coming from any package, but could come from e.g. the system.

assert env["ARCH"].authors() == []