Skip to content

Commit

Permalink
Add support for overriding built-in bind modules (AcademySoftwareFoun…
Browse files Browse the repository at this point in the history
…dation#1619)

* Issue AcademySoftwareFoundation#1557 - Add support for overriding built-in bind modules.

Signed-off-by: Michael Nowakowski <[email protected]>

* Add copyrights

Signed-off-by: Jean-Christophe Morin <[email protected]>

* Add test for get_bind_modules

Signed-off-by: Jean-Christophe Morin <[email protected]>

---------

Signed-off-by: Michael Nowakowski <[email protected]>
Signed-off-by: Jean-Christophe Morin <[email protected]>
Co-authored-by: Jean-Christophe Morin <[email protected]>
Signed-off-by: Jose Enriquez <[email protected]>
  • Loading branch information
2 people authored and Jose Enriquez committed Feb 14, 2024
1 parent dccddda commit ad2b3bf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/rez/data/tests/bind/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions src/rez/data/tests/bind/os.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Custom bind module override
"""
8 changes: 4 additions & 4 deletions src/rez/package_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def get_bind_modules(verbose=False):
"""Get available bind modules.
Returns:
dict: Map of (name, filepath) listing all bind modules.
dict[str, str]: Map of (name, filepath) listing all bind modules.
"""
builtin_path = os.path.join(module_root_path, "bind")
searchpaths = config.bind_module_path + [builtin_path]
searchpaths = [builtin_path] + config.bind_module_path
bindnames = {}

for path in searchpaths:
Expand Down Expand Up @@ -85,14 +85,14 @@ def bind_package(name, path=None, version_range=None, no_deps=False,
Args:
name (str): Package name.
path (str): Package path to install into; local packages path if None.
version_range (`VersionRange`): If provided, only bind the software if
version_range (rez.vendor.version.version.VersionRange): If provided, only bind the software if
it falls within this version range.
no_deps (bool): If True, don't bind dependencies.
bind_args (list of str): Command line options.
quiet (bool): If True, suppress superfluous output.
Returns:
List of `Variant`: The variant(s) that were installed as a result of
list[rez.packages.Variant]: The variant(s) that were installed as a result of
binding this package.
"""
pending = set([name])
Expand Down
49 changes: 49 additions & 0 deletions src/rez/tests/test_bind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the Rez Project


"""
test package_bind module
"""
import os
import unittest
from rez import package_bind
from rez.tests.util import TestBase


class TestPackageBind(TestBase):
def test_get_bind_modules(self):
"""Test get_bind_modules returns the expected modules"""
self.assertEqual(
sorted(package_bind.get_bind_modules().keys()),
[
"PyQt",
"PySide",
"arch",
"cmake",
"gcc",
"hello_world",
"os",
"pip",
"platform",
"python",
"rez",
"rezgui",
"setuptools",
"sip",
]
)

def test_os_module_override(self):
"""Test that bind_module_path can override built-in bind modules"""
self.update_settings({
"bind_module_path": [self.data_path("bind")]
})

os_module_path = os.path.join(self.data_path("bind"), "os.py")
os_bind_module = package_bind.find_bind_module("os")
self.assertEqual(os_bind_module, os_module_path)


if __name__ == '__main__':
unittest.main()

0 comments on commit ad2b3bf

Please sign in to comment.