From 935ad1b4cd085988dc40f4f57b73f37aaf9b9ad1 Mon Sep 17 00:00:00 2001 From: ajohns Date: Sat, 8 May 2021 14:14:24 +1000 Subject: [PATCH] added bundle support for a post_commands.py file --- src/rez/resolved_context.py | 32 ++++++++++++++++++++++++++++++-- src/rez/utils/_version.py | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py index f945524d1..9f21440d0 100644 --- a/src/rez/resolved_context.py +++ b/src/rez/resolved_context.py @@ -1408,11 +1408,14 @@ def execute_shell(self, shell=None, parent_environ=None, rcfile=None, self._execute(executor) + executor.env.REZ_SHELL_INIT_TIMESTAMP = str(int(time.time())) + executor.env.REZ_SHELL_INTERACTIVE = "1" if command is None else "0" + if post_actions_callback: + header_comment(executor, "post-actions-callback") post_actions_callback(executor) - executor.env.REZ_SHELL_INIT_TIMESTAMP = str(int(time.time())) - executor.env.REZ_SHELL_INTERACTIVE = "1" if command is None else "0" + self._execute_bundle_post_actions_callback(executor) # write out the native context file context_code = executor.get_output() @@ -1693,6 +1696,31 @@ def _print_version(value): return r + def _execute_bundle_post_actions_callback(self, executor): + """ + In bundles, you can drop a 'post_commands.py' file (rex) alongside the + 'bundle.yaml' file, and it will be sourced after all package commands. + """ + if not self.load_path: + return + + with self._detect_bundle(self.load_path): + bundle_dir = self._get_bundle_path() + + if not bundle_dir: + return + + rex_filepath = os.path.join(bundle_dir, "post_commands.py") + if not os.path.exists(rex_filepath): + return + + # load the rex code an execute it within the executor + with open(rex_filepath) as f: + rex_py = f.read() + + header_comment(executor, "bundle post-commands") + executor.execute_code(rex_py) + @classmethod @contextmanager def _detect_bundle(cls, path): diff --git a/src/rez/utils/_version.py b/src/rez/utils/_version.py index 19659aac6..8b1418459 100644 --- a/src/rez/utils/_version.py +++ b/src/rez/utils/_version.py @@ -1,7 +1,7 @@ # Update this value to version up Rez. Do not place anything else in this file. -_rez_version = "2.86.1" +_rez_version = "2.87.0" # Copyright 2013-2016 Allan Johns.