Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for overriding built-in bind modules #1619

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()