AcademySoftwareFoundation / AcademySoftwareFoundation/rez

Better Environment Variable control in Rex

Open
#737 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
1.1k
Forks
374
Avg merge
9d 12h
Merged PRs (30d)
5

Description

(Originated from #707)

## Settings and Ops

This is a rather complex topic since we want to support so many use cases so I'll build up to the suggestion based on every possible use case imaginable. It also gives us opportunity to migrate existing settings in a generic configuration.

I don't want to jump into implementation details yet (hope this is doable at all :) ), but let's see if we
can come up with use cases best demonstrated via an sample.

### References

#703
#698
#661
(more ?)

### Use cases

(cases handled by the sample are crossed)

- Path operations:
- [x] Handle paths in platform independent fashion
- [x] Handle paths in explicit platform dependant fashion
- [ ] Handle differences in Drive handling (C:\ -> C:/ vs /C/) (Needed?)
- [ ] Handle platform dependent path prefix (C:\path -> /mnt/c/path) (Needed?)
- [x] Define platform dependent settings
- [x] Migrate `all_*_variables`
- [x] Define path separators (like ; and :)
- [ ] Stable de-duplication of separated values (Needed?)
- [x] Implicit variables, system variables and there placement with context variables

### Sample

(Note: This is a completely artificial example to showcase many possible use cases)

```python
from rez.util.config import PlatformDependent # PR 739

env_var_settings = {

# -------------------------------------------------------------------------
# Global control inherited(!) by all other variables.

"*": {

# Migration of all_parent_variables
#
# Full control over variables is achieved given the following parent_variables & actions:
#
# clear (No parent variables)
# [prepend_all] [prepend_parent->FAILS] [append_parent->FAILS] [$REZ_VARS] [append_all]
#
# prepend (parent before rez variables)
# [prepend_all] [prepend_parent] [$PARENT_VARS] [append_parent] [$REZ_VARS] [append_all]
#
# append (parent after rez variables)
# [prepend_all] [$REZ_VARS] [prepend_parent] [$PARENT_VARS] [append_parent] [append_all]
#
"parent_variables": "clear"

# Migration of all_resetting_variables
# Note: Actually had a problem with understanding the naming, but kept for consistency
"resetting_variables": False

# Any variable (!!!) on this level may be "its expected type" OR dict of
# ("platform": "its expected type").
# Note we are only handling platform.system differences.
"pathsep": PlatformDependent(
{
"windows": ";",
"linux": ":",
},
# Any other platform, except specific one …
default= "🍎"
),
# Default append, prepend and set operation
"modify_op": "nativepath",
# Interestingly this could now also be implemented as followed :-)
# but we probably still need nativepath on commands() side.
"modify_op": PlatformDependent(
{
"windows": "windowspath",
},
default="posixpath"
),
},

# -------------------------------------------------------------------------
# Creation of variables without having to rely on bootstrap file or package
# (Studio must make decision of when to use implicit packages vs. rezconfig)

# Set custom variables without package.

"STUDIO_REZCONFIG_VERSION": {
"parent_variables": "clear",
"prepend_all": "2019.08.23.2",
},

"STUDIO_STORAGE": {
"parent_variables": "clear",
"prepend_all": PlatformDependent({
"windows": "P:\\",
},
default="/mnt/production"
)
},

# Sample where a user might run a local STUDIO_CACHING_SERVER
# [Parent] [This] [Rez]
"STUDIO_CACHING_SERVERS": {
"parent_variables": "prepend",
"append_parent": ["192.168.2.2", "cache.studio.com"], # Note multiple things as list
},

# Sample where user might override for debugging, rez is default authority but
# ultimately use sensible default
# [Parent] [Rez] [This]
"STUDIO_LOCATION": {
"parent_variables": "prepend",
"append_all": "UNKNOWN",
},

# Artificial case where REZ packages always have priority, but we guarantee a fallback
# coming from Parent Environment or This config
# [Rez] [Parent] [This]
"STUDIO_USER_GROUPS": {
"parent_variables": "append",
"append_parent": PlatformDependent({
"windows": ["UPDATING"],
"linux": ["WORKING"],
"osx": ["BROKE"],
})
},

# -------------------------------------------------------------------------
# Common use cases
# We now can control the "always-on" tools and their order very precisely

"PATH": {
# In this sample: Rez first
"parent_variables": "append",

"prepend_all": PlatformDependent({
"windows": "C:\\ImportantTools",
},
default="/opt/important_tools"
),

# Here after the system paths
"append_all": PlatformDependent({
"windows": ["C:\\WindowsFallbackTools"],
}),
},

"PYTHONPATH": {
"parent_variables": "clear",
},

"CMAKE_MODULE_PATH": {
"parent_variables": "clear",

# Nice.
"pathsep": ";",
"modify_op": "posixpath",
},

"PATHEXT": {
"pathsep": ";",
"parent_variables": "prepend",
"append_parent": PlatformDependent({
# Does not pollute other platforms (Not sure if this is true, yet)
"windows": [".PY", ".PS1"],
},
default=None
)
}
}
```

Naming, features and details are like always up for discussion. Let me know if I missed anything.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the proposed environment-variable use cases, the referenced issues #703, #698, and #661, and the PlatformDependent mention from PR #739. Done would require an agreed design covering platform-dependent values, parent-variable ordering, migration of existing settings, path separators, and implicit variables.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.