Skip to content

Commit

Permalink
Merge pull request #727 from maxnbk/maxnbk/feat-py3-modernize-functio…
Browse files Browse the repository at this point in the history
…ns-attrs

modernize function manipulations and attrs
  • Loading branch information
nerdvegas authored Sep 6, 2019
2 parents 761ab5b + 9f76961 commit 75d884f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/rez/build_process_.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def run_hooks(self, hook_event, **kwargs):
debug_print("Running %s hook '%s'...",
hook_event.label, hook.name())
try:
func = getattr(hook, hook_event.func_name)
func = getattr(hook, hook_event.__name__)
func(user=getpass.getuser(), **kwargs)
except ReleaseHookCancellingError as e:
raise ReleaseError(
Expand Down
2 changes: 1 addition & 1 deletion src/rez/release_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ReleaseHookEvent(Enum):
def __init__(self, label, noun, func_name):
self.label = label
self.noun = noun
self.func_name = func_name
self.__name__ = func_name


# Copyright 2013-2016 Allan Johns.
Expand Down
12 changes: 6 additions & 6 deletions src/rez/rex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,12 +1228,12 @@ def execute_function(self, func, *nargs, **kwargs):
"""
# makes a copy of the func
import types
fn = types.FunctionType(func.func_code,
func.func_globals.copy(),
name=func.func_name,
argdefs=func.func_defaults,
closure=func.func_closure)
fn.func_globals.update(self.globals)
fn = types.FunctionType(func.__code__,
func.__globals__.copy(),
name=func.__name__,
argdefs=func.__defaults__,
closure=func.__closure__)
fn.__globals__.update(self.globals)

error_class = Exception if config.catch_rex_errors else None

Expand Down
14 changes: 7 additions & 7 deletions src/rez/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ def _process(value):

# make a copy of the func with its own globals, and add 'this'
import types
fn = types.FunctionType(func.func_code,
func.func_globals.copy(),
name=func.func_name,
argdefs=func.func_defaults,
closure=func.func_closure)
fn = types.FunctionType(func.__code__,
func.__globals__.copy(),
name=func.__name__,
argdefs=func.__defaults__,
closure=func.__closure__)

# apply globals
fn.func_globals["this"] = EarlyThis(data)
fn.func_globals.update(get_objects())
fn.__globals__["this"] = EarlyThis(data)
fn.__globals__.update(get_objects())

# execute the function
spec = getargspec(func)
Expand Down

0 comments on commit 75d884f

Please sign in to comment.