Rez API as a vendor bundle (Shotgun Toolkit)?

149 views
Skip to first unread message

eldrit...@gmail.com

unread,
May 26, 2021, 9:37:21 PM5/26/21
to rez-config
Perhaps I'm thinking of this the wrong way, but I want to bundle the Rez API within a framework so that the API can be more easily distributed (rather than having to install it on each machine's python, for example).

An example framework structure:
tk-framework-rez
  python
    vendor
      rez
    rez_helper.py
  framework.py

You'd normally be able to access code via SGTK's import_framework and import_module, however, this method doesn't work because Rez self-references in it's __init__.py by trying to import rez.utils._version.

Maybe it's late and I'm not thinking clearly, but is there a way to do this without having to modifying the import statements within Rez to be relative?


Nico

unread,
May 27, 2021, 1:15:47 AM5/27/21
to rez-c...@googlegroups.com
Any particular reason rez can’t be installed to a shared location on your network, or are you dealing with a distributed workforce and trying to do a remote deployment via shotgun (in which case, how are you deploying the actual Rez packages?)

N

On May 26, 2021, at 6:37 PM, eldrit...@gmail.com <eldrit...@gmail.com> wrote:

Perhaps I'm thinking of this the wrong way, but I want to bundle the Rez API within a framework so that the API can be more easily distributed (rather than having to install it on each machine's python, for example).
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/rez-config/67a0de0b-f9e3-4365-8164-fb08c7cb4ae0n%40googlegroups.com.

eldrit...@gmail.com

unread,
May 27, 2021, 12:26:41 PM5/27/21
to rez-config
Hi Nico,

You've hit the nail on the head. As a policy, we're trying to move away from reliance on shared network storage, so having a way to deploy the Rez API to user's machines is an important goal. Of course, you've identified some of the hypocrisy, since the Rez package repositories still live on shared storage. However, there are other initiatives likewise working on solutions to change how that works.

The other reason I want to deploy this way is that even were Rez living in a shared network location, in order to utilize the Rez API in Shotgun Desktop (e.g. the tk-multi-launchapp) we'd still have to do some subprocess or sys.path manipulations to reach out to the shared storage. Since we're also supporting multiple platforms, it seemed like it should be easier to package up the Rez API and deploy it as a framework of some kind.

Nico Van den Bosch

unread,
May 27, 2021, 2:36:10 PM5/27/21
to rez-c...@googlegroups.com
That clarifies things a bit.    While we haven’t deployed Rez specifically this way, our studio's successfully deployed a number of python modules by first pip installing them into a (relocatable) python virtualenv first and then activating the env within framework.py like so:
def init_framework(self):
self.log_debug("%s: Initializing..." % self)
# This framework ships with additional Python packages
# make these packages available to apps and engines using
# this framework
# Remap the platform name to our names
pname = self.platform_name()
# Virtual env has different structures on Windows
if pname == "windows":
bin_folder = "Scripts"
else:
bin_folder = "bin"
# We just call the virtual env "activate_this.py" script, it
# will tweak Python paths, but keep the "global" environement
# reachable
# Details can be found here :
# http://virtualenv.readthedocs.org/en/latest/virtualenv.html#using-virtualenv-without-bin-python
activate_this_path = os.path.join(os.path.dirname(__file__), "python", "vendors", pname, bin_folder, "activate_this.py")
if not os.path.exists( activate_this_path):
raise ValueError("Activate path %s for platform %s does not exist" % (activate_this_path, platform.system()))
self.log_debug("Activating custom packages with %s" % activate_this_path)
execfile(activate_this_path, dict(__file__=activate_this_path))
Can’t say I’ve tested with Rez specifically, but hopefully that sidesteps the need to modify rez directly.    We may have cause to do something similar for remote users in the near future, so please reports back with any success or failure stories.

Cheers
N

David Lai

unread,
May 27, 2021, 3:18:31 PM5/27/21
to rez-c...@googlegroups.com
Hi all,

Specifically on by passing Rez's absolute import, how about instead of making it as part of vendored sub-module, just put it inside a lib folder and append it into sys.path ?
Like

- tk-framework-rez
    - libs
        (no __init__.py in this folder, append libs into sys.path to access rez)
        - rez
    - python
    - ...

Cheers,
David


Nico Van den Bosch <nico.vand...@gmail.com> 於 2021年5月28日 週五 上午2:36寫道:


--
David Lai  |  Animation Production Pipeline Developer
     GitHub |  github.com/davidlatwe

Reply all
Reply to author
Forward
0 new messages