Skip to content

Commit 2a732f3

Browse files
author
ajohns
committed
-minor update to give @early funcs access to pkg data;
-docstring update
1 parent 5531557 commit 2a732f3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/rez/rezconfig.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
# This package will import the code from */src/rezutils/utils.py* (or more
102102
# specifically, its copy of this sourcefile) and will bind it to the name *utils*.
103103
#
104-
# For further information, see [here](Package-Definition-Guide#using-shared-code).
104+
# For further information, see
105+
# [here](Package-Definition-Guide#sharing-code-across-package-definition-files).
105106
#
106107
package_definition_python_path = None
107108

@@ -360,7 +361,8 @@
360361
# If you define this function, it will be called as the *preprocess function*
361362
# on every package that does not provide its own, as part of the build process.
362363
# The given function must be made available by setting the value of
363-
# *package_definition_build_python_paths* appropriately.
364+
# [package_definition_build_python_paths](#package_definition_build_python_paths)
365+
# appropriately.
364366
#
365367
# For example, consider the settings:
366368
#

src/rez/serialise.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from rez.vendor.enum import Enum
1414
from rez.vendor import yaml
1515
from contextlib import contextmanager
16-
from inspect import isfunction
16+
from inspect import isfunction, getargspec
1717
from StringIO import StringIO
1818
import sys
1919
import os
@@ -170,7 +170,7 @@ def load_py(stream, filepath=None):
170170
return result
171171

172172

173-
def process_python_objects(value, filepath=None):
173+
def process_python_objects(data, filepath=None):
174174

175175
def _process(value):
176176
if isinstance(value, dict):
@@ -182,7 +182,17 @@ def _process(value):
182182
if hasattr(value, "_early"):
183183
# run the function now, and replace with return value
184184
with add_sys_paths(config.package_definition_build_python_paths):
185-
value_ = value()
185+
func = value
186+
187+
spec = getargspec(func)
188+
args = spec.args or []
189+
if len(args) not in (0, 1):
190+
raise ResourceError("@early decorated function must "
191+
"take zero or one args only")
192+
if args:
193+
value_ = func(data)
194+
else:
195+
value_ = func()
186196

187197
# process again in case this is a function returning a function
188198
return _process(value_)
@@ -204,7 +214,7 @@ def _process(value):
204214
else:
205215
return value
206216

207-
return _process(value)
217+
return _process(data)
208218

209219

210220
def load_yaml(stream, **kwargs):

0 commit comments

Comments
 (0)