AcademySoftwareFoundation / rez

An integrated package configuration, build and deployment system for software
https://rez.readthedocs.io
Apache License 2.0
938 stars 332 forks source link

Should rez env inherit all variables from the parent rez environment? #1435

Open 1xinghuan opened 1 year ago

1xinghuan commented 1 year ago

Need an option to not inherit undefined variables from parent environment.

Motivation Here's an example, I have 2 packages: PySide2 and maya

In PySide2: env.PYTHONPATH.append('{root}/site-packages')

In maya: env.PATH.append('{this.root}/bin')

I first do 'rez env PySide2' to open a gui, then in this gui I will click maya icon to open maya by executing 'rez env maya -- maya'. In the final environment, the PySide2 dir still exists in PYTHONPATH and maya crash(I know it's because I used a different version of PySide2). Currently I have to add a new line in maya package.py env.PYTHONPATH.append('a not existing path') Then in final environment, the PySide2 dir will not exist in PYTHONPATH

This is just an example and will be dangerous in other cases. Actually I hope each rez env is based on the clean environment at beginning.

Is there any way to avoid inheriting variables from parent rez environment?

instinct-vfx commented 1 year ago

What platform are you on? rez does try its best to isolate its own environment from the environments it resolves as way as nested resolves. However it does not simply wipe all environment variables. It only resets environment variables that are touched by any package of the resolve. So if any package in your nested resolve edits PYTHONPATH then it will be reset. If not it will be left alone. Here is also a bit of information in the Wiki: https://github.com/AcademySoftwareFoundation/rez/wiki/Configuring-Rez#parent_variables

1xinghuan commented 1 year ago

I'm using CentOS8, python 3.6(from system), rez 2.112.0. Here's my test process:

  1. set env: rez-env PySide2-5.15.2.1
  2. open a gui which contains a maya icon
  3. click the icon then open maya using subprocess rez-env maya-2022 -- maya

In this case, maya will try to launch under wrong PYTHONPATH and fail.

Is it possible to record the initial (before rez-env) environment under tmp, and then use that original environment as parent during each nested resolves?

instinct-vfx commented 1 year ago

rez has no way to really know what your intent is. I think what you are looking for is patched requests. (rez-env --patch) This takes an existing resolve and changes it. From the docstrings:

A patched request is a copy of this context’s request, but with some changes applied. This can then be used to create a new, ‘patched’ context.

New package requests override original requests based on the type - normal, conflict or weak. So ‘foo-2’ overrides ‘foo-1’, ‘!foo-2’ overrides ‘!foo-1’ and ‘~foo-2’ overrides ‘~foo-1’, but a request such as ‘!foo-2’ would not replace ‘foo-1’ - it would be added instead.

Note that requests in package_requests can have the form ‘^foo’. This is another way of supplying package subtractions.

Any new requests that don’t override original requests are appended, in the order that they appear in package_requests.