How to do string manipulations of system objects in a rez configuration file

139 views
Skip to first unread message

Brent Villalobos

unread,
Apr 29, 2019, 8:33:21 PM4/29/19
to rez-config
I see that I can specify the literal string "{system.os}" in a rez configuration python file (the file reference by the $REZ_CONFIG_FILE environment variable).  Is there a way I can query the expanded value of that in the configuration python code so I can manipulate it?  For example, currently {system.os} will expand to CentOS-7.5.  However, I want to set a my implicit_packages to request os-CentOS-7.  So is there any way I can get the expanded value of system.os in the python configuration file so that I can do some python string operations on it?  It's easy in a script since I can import rez.system.  But I can't import rez.system in the configuration file without it going into a recursive loop.  Thanks.
-Brent

Marcus Ottosson

unread,
Apr 30, 2019, 2:36:19 AM4/30/19
to rez-c...@googlegroups.com

The system variable is accessible to your commands() function as a global, so you could query it there.

name = "my_query"
version = "1.1.3"
build_command = False

def commands():
    global system
    print(system.os)

(You can skip calling global system if your linter doesn’t mind)

Results in:

$ rez build my_query
$ rez env my_query
windows-10.0.18362

You can list all available variables using locals() which at the time of this writing is:

    for key in list(locals()):
        print(key)
comment
version
shebang
defined
expandvars
expandable
__builtins__
system
resetenv
source
literal
setenv
env
building
appendenv
implicits
format
unsetenv
stop
getenv
base
prependenv
info
resolve
undefined
this
request
alias
command
error
root

On Tue, 30 Apr 2019 at 01:33, Brent Villalobos <brent...@gmail.com> wrote:
I see that I can specify the literal string "{system.os}" in a rez configuration python file (the file reference by the $REZ_CONFIG_FILE environment variable).  Is there a way I can query the expanded value of that in the configuration python code so I can manipulate it?  For example, currently {system.os} will expand to CentOS-7.5.  However, I want to set a my implicit_packages to request os-CentOS-7.  So is there any way I can get the expanded value of system.os in the python configuration file so that I can do some python string operations on it?  It's easy in a script since I can import rez.system.  But I can't import rez.system in the configuration file without it going into a recursive loop.  Thanks.
-Brent

--
You received this message because you are subscribed to the Google Groups "rez-config" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rez-config+...@googlegroups.com.
To post to this group, send email to rez-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/rez-config.
For more options, visit https://groups.google.com/d/optout.

Brent Villalobos

unread,
Apr 30, 2019, 10:35:06 AM4/30/19
to rez-config
Thanks Marcus.  While your suggestion does work fine in a package.py file, I'm trying to do something similar in the rez configuration file (see https://github.com/nerdvegas/rez/wiki/Configuring-Rez).  Any tips for querying system objects there?  To me, it looks like you can only specify them as strings that get interpreted at runtime.  I don't see a way to expand the values in the configuration file itself so I can do operations on them.
-Brent
To unsubscribe from this group and stop receiving emails from it, send an email to rez-c...@googlegroups.com.

Marcus Ottosson

unread,
Apr 30, 2019, 11:16:54 AM4/30/19
to rez-c...@googlegroups.com

That’s a good question; I would have thought you could import rez.system from there, but it looks like there’s some magic going on in that module to prevent that.


To unsubscribe from this group and stop receiving emails from it, send an email to rez-config+...@googlegroups.com.

Fede Naum

unread,
May 3, 2019, 1:51:43 AM5/3/19
to rez-config
you can do something along these lines

implicit_packages = [
"~platform=={system.platform}",
"~arch=={system.arch}",
"~os=={system.os}",
]

import platform
if platform.linux_distribution()[1].startswith('7'):
implicit_packages.add("os-CentOS-7") # or build it with the output platform.linux_distribution() i.e ('CentOS Linux', '7.4.1708', 'Core')

cheers,
fede

Joseph Yu

unread,
May 3, 2019, 5:24:05 AM5/3/19
to rez-c...@googlegroups.com
We currently override the platform_map in the rez config python file if you want to experiment with this approach:

platform_map = {
"os": {
r'[cC]ent[oO][sS].*-([\d][\d\.]*)': r'CentOS-\1',
},
}

--
You received this message because you are subscribed to the Google Groups "rez-config" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rez-config+...@googlegroups.com.
To post to this group, send email to rez-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/rez-config.
For more options, visit https://groups.google.com/d/optout.


--

Joseph Yu · Pipeline TD · +44 (0)7925535159

3rd Floor South, Times House,
Regents Quarter, N19AW

Reply all
Reply to author
Forward
0 new messages