Skip to content

Commit

Permalink
-minor update to give @early funcs access to pkg data;
Browse files Browse the repository at this point in the history
-docstring update
  • Loading branch information
ajohns committed Feb 25, 2017
1 parent 5531557 commit 2a732f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/rez/rezconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
# This package will import the code from */src/rezutils/utils.py* (or more
# specifically, its copy of this sourcefile) and will bind it to the name *utils*.
#
# For further information, see [here](Package-Definition-Guide#using-shared-code).
# For further information, see
# [here](Package-Definition-Guide#sharing-code-across-package-definition-files).
#
package_definition_python_path = None

Expand Down Expand Up @@ -360,7 +361,8 @@
# If you define this function, it will be called as the *preprocess function*
# on every package that does not provide its own, as part of the build process.
# The given function must be made available by setting the value of
# *package_definition_build_python_paths* appropriately.
# [package_definition_build_python_paths](#package_definition_build_python_paths)
# appropriately.
#
# For example, consider the settings:
#
Expand Down
18 changes: 14 additions & 4 deletions src/rez/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rez.vendor.enum import Enum
from rez.vendor import yaml
from contextlib import contextmanager
from inspect import isfunction
from inspect import isfunction, getargspec
from StringIO import StringIO
import sys
import os
Expand Down Expand Up @@ -170,7 +170,7 @@ def load_py(stream, filepath=None):
return result


def process_python_objects(value, filepath=None):
def process_python_objects(data, filepath=None):

def _process(value):
if isinstance(value, dict):
Expand All @@ -182,7 +182,17 @@ def _process(value):
if hasattr(value, "_early"):
# run the function now, and replace with return value
with add_sys_paths(config.package_definition_build_python_paths):
value_ = value()
func = value

spec = getargspec(func)
args = spec.args or []
if len(args) not in (0, 1):
raise ResourceError("@early decorated function must "
"take zero or one args only")
if args:
value_ = func(data)
else:
value_ = func()

# process again in case this is a function returning a function
return _process(value_)
Expand All @@ -204,7 +214,7 @@ def _process(value):
else:
return value

return _process(value)
return _process(data)


def load_yaml(stream, **kwargs):
Expand Down

0 comments on commit 2a732f3

Please sign in to comment.