Skip to content

Commit

Permalink
Merge pull request #56 from davidlatwe/patch_entry_for_edit
Browse files Browse the repository at this point in the history
patch entry-point for edit-in-production
  • Loading branch information
davidlatwe authored Dec 25, 2021
2 parents 0dbb0f9 + 6a79495 commit 4a69c20
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
27 changes: 27 additions & 0 deletions docs/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,30 @@ requires = [
For faster deploy, dependency packages can be installed in here, and will be shared across all revisions in one container (all revisions that use same `name` of shared lib).

This works by creating a `.pth` file that contains the absolute path of shared lib in Rez venv and only that venv. So this will not be shared with the extension that has `isolation` set to true.


## Production Install

Rezup installs Rez and the tooling by following Rez installation script's "production-install" schema :

1. Install Rez in a fresh Python virtual environment.
2. Command line entry-points (bin tools) are all patched with Python interpreter flag `-E`.
3. All bin tools get stored in a sub-directory of regular Python bin tools install location (`{venv}/bin/rez` or `{venv}/Scripts/rez` on Windows).

See Rez Wiki [Why Not Pip For Production?](https://github.com/nerdvegas/rez/wiki/Installation#why-not-pip-for-production) section for a bit more detail.

But if Rez gets installed in *edit-mode*, it will fail to compute the location of those production-installed bin tools and not able to provide features like nesting resolved contexts or running some specific rez tests.

Rezup covers this situation by using custom entry-point script. If Rez is going to be installed in edit-mode, all bin tools will be generated with the custom script, which will pre-cache the location of bin tools when the session starts if, the environment variable `REZUP_EDIT_IN_PRODUCTION` exists and is not empty (see [davidlatwe/rezup#56](https://github.com/davidlatwe/rezup/pull/56) for implementation detail).

You may put that env var in e.g. `rezup.dev.toml` like this:

```toml
[env]
REZUP_EDIT_IN_PRODUCTION = "1"

[rez]
name = "rez"
url = "/path/to/source/rez"
edit = true
```
1 change: 1 addition & 0 deletions docs/environ.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
|REZUP_PROMPT|For customizing shell prompt, optional. See [Command](../command#shell-prompt).|
|REZUP_CONTAINER|Auto set, for customizing shell prompt. See [Command](../command#shell-prompt).|
|REZUP_USING_REMOTE|Auto set, indicating where the container was sourced from.|
|REZUP_EDIT_IN_PRODUCTION|Enable production privilege for Rez that was installed in edit mode.|
|REZUP_TEST_KEEP_TMP|Preserve temp dirs in tests.|
26 changes: 19 additions & 7 deletions src/rezup/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ def __init__(self, revision):
self._default_venv = None
self._rez_as_libs = None
self._rez_version = None
self._rez_in_edit = None

def installed_rez_version(self):
return self._rez_version
Expand All @@ -888,6 +889,7 @@ def install_rez(self, tool):
venv_session = self.create_venv(tool)
self._default_venv = venv_session
self._rez_as_libs = tool
self._rez_in_edit = tool.edit

self.install_package(tool, venv_session, patch_scripts=True)

Expand Down Expand Up @@ -956,13 +958,6 @@ def mark_as_rez_production_install(self, tool, venv_session):
f.write(rez_version)
self._rez_version = rez_version

if tool.edit:
egg_info = os.path.join(tool.url, "src", "rez.egg-info")
egg_link = os.path.join(egg_info, ".rez_production_entry")
if os.path.isdir(egg_info):
with open(egg_link, "w") as f:
f.write(str(rez_bin))

def create_production_scripts(self, tool, venv_session):
"""Create Rez production used binary scripts
Expand Down Expand Up @@ -1026,6 +1021,23 @@ def create_production_scripts(self, tool, venv_session):
# See https://bitbucket.org/pypa/distlib/issue/32/
maker.set_mode = True

if self._rez_in_edit:
# Allow pre-caching rez_bin_path on script entry if environ var
# `REZUP_EDIT_IN_PRODUCTION` is set with non-empty value.
# See https://github.com/davidlatwe/rezup/pull/56
maker.script_template = r'''# -*- coding: utf-8 -*-
import re
import os
import sys
from %(module)s import %(import_name)s
if os.getenv("REZUP_EDIT_IN_PRODUCTION"):
from rez.system import system
setattr(system, 'rez_bin_path', r'{rez_bin_path}')
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(%(func)s())
'''.format(rez_bin_path=str(prod_bin_path))

scripts = maker.make_multiple(
specifications=specifications.values(),
options=dict(interpreter_args=list(tool.flags))
Expand Down

0 comments on commit 4a69c20

Please sign in to comment.