AcademySoftwareFoundation / rez

An integrated package configuration, build and deployment system for software
https://rez.readthedocs.io
Apache License 2.0
939 stars 332 forks source link

package_filter parameter on ResolvedContext class shows incorrect expected type #1581

Closed brycegbrazen closed 10 months ago

brycegbrazen commented 10 months ago

In rez.resolved_context for the ResolvedContext class, the expected type of the package_filter parameter in the documentation seems to be incorrect compared to what is actually expected by the code.

The expected type according to the documentation is PackageFilterBase which should mean that I can pass a PackageFilter object for this parameter, however, when I pass a PackageFilter class, I get the following error:

11:44:55 ERROR    ResolvedContextError: Failed to load context from C:\Users\MY_USER\AppData\Local\Temp\rez_context_ta9orw0v\context.rxt: AttributeError: 'str' object has no attribute 'get'

From what I can tell, you must pass a PackageFilterList object instead. If you pass a PackageFilterList instead, then the resolved context works as intended.

Environment

To Reproduce

  1. Ensure the Rez Python API is in your PYTHONPATH
  2. Run a Python interpreter and the following commands:
    
    from rez.package_filter import PackageFilter, Rule
    from rez.resolved_context import ResolvedContext

pkg_filter = PackageFilter() rule = Rule.parse_rule('*-beta') pkg_filter.add_exclusion(rule) rez_ctx = ResolvedContext(['MY_PKG'], package_filter=pkg_filter) rez_ctx.execute_shell()


**Expected behavior**
A successful resolve, with no errors.

**Actual behavior**
A corrupt context was created. I am placed inside the shell, but I cannot run `rez context` as I usually can, as running `rez context` prints out the same error and does not give me any information about the current Rez context.

Running the following commands in the interpreter works as expected. Note that I am using the `PackageFilterList` class instead of `PackageFilter` class.

from rez.package_filter import PackageFilterList, Rule from rez.resolved_context import ResolvedContext

pkg_filter = PackageFilterList() rule = Rule.parse_rule('*-beta') pkg_filter.add_exclusion(rule) rez_ctx = ResolvedContext(['MY_PKG'], package_filter=pkg_filter) rez_ctx.execute_shell()

brycegbrazen commented 10 months ago

Looks like the issue stems from line 1695 in ResolvedContext.

The code is assuming that you are passing a PackageFilterList and doesn't seem handle to decoding a PackageFilter.