Skip to content

Commit

Permalink
Introducing 'testing' object
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Macagno <[email protected]>
  • Loading branch information
fabal committed May 2, 2024
1 parent eafe8f6 commit 110cac2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docs/source/package_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,20 @@ Following is a list of the objects and functions available.
if building:
env.FOO_INCLUDE_PATH = "{root}/include"
.. py:attribute:: testing
:type: bool

This boolean variable is ``True`` if a test is occurring (typically done via the :ref:`rez-test` tool),
and ``False`` otherwise.

Typically a package will use this variable to set environment variables that are only relevant during test
execution.

.. code-block:: python
if testing:
env.FOO_TEST_DATA_PATH = "{root}/tests/data"
.. py:function:: command(arg: str)
Run an arbitrary shell command.
Expand Down
1 change: 1 addition & 0 deletions docs/source/package_definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ is ``True``:
* **context**: the :class:`~rez.resolved_context.ResolvedContext` instance this package belongs to;
* **system**: see :attr:`system`;
* **building**: see :attr:`building`;
* **testing**: see :attr:`testing`;
* **request**: see :attr:`request`;
* **implicits**: see :attr:`implicits`.

Expand Down
1 change: 1 addition & 0 deletions src/rez/package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ def _get_context(self, requires, quiet=False):
package_paths=self.package_paths,
buf=(f if quiet else None),
timestamp=self.timestamp,
testing=True,
**self.context_kwargs
)

Expand Down
7 changes: 6 additions & 1 deletion src/rez/resolved_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __call__(self, state):
return SolverCallbackReturn.keep_going, ''

def __init__(self, package_requests, verbosity=0, timestamp=None,
building=False, caching=None, package_paths=None,
building=False, testing=False, caching=None, package_paths=None,
package_filter=None, package_orderers=None, max_fails=-1,
add_implicit_packages=True, time_limit=-1, callback=None,
package_load_callback=None, buf=None, suppress_passive=False,
Expand All @@ -176,6 +176,7 @@ def __init__(self, package_requests, verbosity=0, timestamp=None,
timestamp (float): Ignore packages released after this epoch time. Packages
released at exactly this time will not be ignored.
building (bool): True if we're resolving for a build.
testing (bool): True if we're resolving for a test (rez-test).
caching (bool): If True, cache(s) may be used to speed the resolve. If
False, caches will not be used. If None, :data:`resolve_caching`
is used.
Expand Down Expand Up @@ -212,6 +213,7 @@ def __init__(self, package_requests, verbosity=0, timestamp=None,
self.requested_timestamp = timestamp
self.timestamp = self.requested_timestamp or int(time.time())
self.building = building
self.testing = testing
self.implicit_packages = []
self.caching = config.resolve_caching if caching is None else caching
self.verbosity = verbosity
Expand Down Expand Up @@ -1548,6 +1550,7 @@ def _add(field):
timestamp=self.timestamp,
requested_timestamp=self.requested_timestamp,
building=self.building,
testing=self.testing,
caching=self.caching,
implicit_packages=list(map(str, self.implicit_packages)),
package_requests=list(map(str, self._package_requests)),
Expand Down Expand Up @@ -1621,6 +1624,7 @@ def _print_version(value):

r.timestamp = d["timestamp"]
r.building = d["building"]
r.testing = d["testing"]
r.caching = d["caching"]
r.implicit_packages = [PackageRequest(x) for x in d["implicit_packages"]]
r._package_requests = [PackageRequest(x) for x in d["package_requests"]]
Expand Down Expand Up @@ -1946,6 +1950,7 @@ def _get_pre_resolve_bindings(self):
self.pre_resolve_bindings = {
"system": system,
"building": self.building,
"testing": self.testing,
"request": RequirementsBinding(self._package_requests),
"implicits": RequirementsBinding(self.implicit_packages),
"intersects": intersects
Expand Down
7 changes: 5 additions & 2 deletions src/rez/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Resolver(object):
"""
def __init__(self, context, package_requests, package_paths, package_filter=None,
package_orderers=None, timestamp=0, callback=None, building=False,
verbosity=False, buf=None, package_load_callback=None, caching=True,
suppress_passive=False, print_stats=False):
testing=False, verbosity=False, buf=None, package_load_callback=None,
caching=True, suppress_passive=False, print_stats=False):
"""Create a Resolver.
Args:
Expand All @@ -52,6 +52,7 @@ def __init__(self, context, package_requests, package_paths, package_filter=None
prior to each package being loaded. It is passed a single
`Package` object.
building: True if we're resolving for a build.
testing: True if we're resolving for a rez (rez-test).
caching: If True, cache(s) may be used to speed the resolve. If
False, caches will not be used.
print_stats (bool): If true, print advanced solver stats at the end.
Expand All @@ -64,6 +65,7 @@ def __init__(self, context, package_requests, package_paths, package_filter=None
self.package_orderers = package_orderers
self.package_load_callback = package_load_callback
self.building = building
self.testing = testing
self.verbosity = verbosity
self.caching = caching
self.buf = buf
Expand Down Expand Up @@ -384,6 +386,7 @@ def _memcache_key(self, timestamped=False):
self.package_filter_hash,
self.package_orderers_hash,
self.building,
self.testing,
config.prune_failed_graph]

if timestamped and self.timestamp:
Expand Down
1 change: 1 addition & 0 deletions src/rez/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def _load_file(filepath, format_, update_data_callback, original_filepath=None):
# Default variables to avoid not-defined errors in early-bound attribs
default_objects = {
"building": False,
"testing": False,
"build_variant_index": 0,
"build_variant_requires": []
}
Expand Down

0 comments on commit 110cac2

Please sign in to comment.