summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2016-03-04 15:03:00 -0500
committerMike Frysinger <vapier@google.com>2016-03-05 21:52:31 +0000
commit4aa4b211c62a8f01abfe1953b4274af69d374ecf (patch)
tree7e0881b72c6401f3b6101de46fecb4f6e4bee1e8
parent203153e7bba61b1b2d782e9e75aef919eab0d54b (diff)
downloadgit-repo-4aa4b211c62a8f01abfe1953b4274af69d374ecf.tar.gz
RepoHook: set __file__ when running the hook
A common design pattern is to use __file__ to find the location of the active python module to assist in output or loading of related assets. The current hook systems runs the pre-upload.py hook in a context w/out that set leading to runtime errors: $ repo upload --cbr . ERROR: Traceback (most recent call last): File ".../repo/project.py", line 481, in _ExecuteHook self._script_fullpath, 'exec'), context) File ".../repohooks/pre-upload.py", line 32, in <module> path = os.path.dirname(os.path.realpath(__file__)) NameError: name '__file__' is not defined Define this variable in this context so code can safely use it. Change-Id: If6331312445fa61d9351b59f83abcc1c99ae6748
-rw-r--r--project.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/project.py b/project.py
index d54e336c..4c5fa9e5 100644
--- a/project.py
+++ b/project.py
@@ -475,7 +475,7 @@ class RepoHook(object):
475 475
476 # Exec, storing global context in the context dict. We catch exceptions 476 # Exec, storing global context in the context dict. We catch exceptions
477 # and convert to a HookError w/ just the failing traceback. 477 # and convert to a HookError w/ just the failing traceback.
478 context = {} 478 context = {'__file__': self._script_fullpath}
479 try: 479 try:
480 exec(compile(open(self._script_fullpath).read(), 480 exec(compile(open(self._script_fullpath).read(),
481 self._script_fullpath, 'exec'), context) 481 self._script_fullpath, 'exec'), context)