Skip to content

Conversation

czerouni
Copy link

@czerouni czerouni commented Aug 22, 2025

Fixes #2003
Fixes #1766

Signed-off-by: Craig Zerouni [email protected]
I was running rez depends on a number of packages, and some of them would crash Rez with the message:

AttributeError: 'str' object has no attribute 'conflict'

This happens in package_search.py where you have this loop:

for req in requires:
    if not req.conflict:
        lookup[req.name].add(package_name_)

The problem is that some requirements in that list are not of type PackageRequest, but instead are simply type str. This happens if in the package.py file of the package being queried there is a private_build_requires configured as a late-binding function. Eg, a package with this this pbr will not crash Rez

private_build_requires = ["foo"]

but this one will

@late()
def private_build_requires():
    return ["foo"]

I initially assumed this was a bug in the way these are handled, except that in the file resolved_context.py I see this comment:

Args:
    package_requests (list[typing.Union[str, PackageRequest]]): request

which leads me to think that requests of type str are expected. In which case, the fix is simple, as per this PR.

@czerouni czerouni requested a review from a team as a code owner August 22, 2025 00:53
Copy link

linux-foundation-easycla bot commented Aug 22, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: JeanChristopheMorinPerso / name: Jean-Christophe Morin (2917d2b)
  • ✅ login: czerouni / name: Craig Zerouni (55fe9f5, 20839b7)

@JeanChristopheMorinPerso
Copy link
Member

Hey @czerouni , thanks for this PR. I took a quick look and I feel like this can be fixed in a cleaner way. I think we could add build_requires and private_build_requires to

rez/src/rez/packages.py

Lines 74 to 76 in fca0b86

late_bind_schemas = {
"requires": late_requires_schema
}

I tested quickly locally with a recipe like this:

name = "test_package"

version = "1.0.1"

description = "Something `rez-env`-ing this"

@late()
def private_build_requires():
    return ["os-arch"]

build_command = "python -c 'print(1)'"

def commands():
    env.ASD.append('~asdasdads')

and this snippet seems to be working:

>>> import rez.packages
>>> package = rez.packages.get_latest_package('test_package')
>>> variant = list(package.iter_variants())[0]
>>> print(variant.get_requires(private_build_requires=True))
[PackageRequest('os-arch')]

Could you give this a go and see if the tests pass?

@czerouni
Copy link
Author

czerouni commented Sep 15, 2025

Hi. I'm sorry, I am not understanding what you mean. These lines

late_bind_schemas = {
    "requires": late_requires_schema
}

are already in src/rez/packages.py, so I am not sure what change you are suggesting.

@JeanChristopheMorinPerso
Copy link
Member

JeanChristopheMorinPerso commented Sep 15, 2025

I mean this:

 late_bind_schemas = {
-    "requires": late_requires_schema
+    "requires": late_requires_schema,
+    "build_requires": late_requires_schema,
+    "private_build_requires": late_requires_schema,
 }

@czerouni
Copy link
Author

Yes, that seems to accomplish the same thing. Do you want me to close this PR? Or maybe change it to your fix?

@JeanChristopheMorinPerso
Copy link
Member

You can push a commit on this branch and keep the same PR

…and private_build_requires

Signed-off-by: Craig Zerouni <[email protected]>
@czerouni
Copy link
Author

All set!

Copy link

codecov bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.01%. Comparing base (cd8476f) to head (2917d2b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2004   +/-   ##
=======================================
  Coverage   60.01%   60.01%           
=======================================
  Files         163      163           
  Lines       20098    20098           
  Branches     3494     3494           
=======================================
  Hits        12062    12062           
+ Misses       7224     7217    -7     
- Partials      812      819    +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@czerouni
Copy link
Author

Is this expected or is it related to my changes?

@JeanChristopheMorinPerso
Copy link
Member

Everything looks good to me. The codecov report was created because I ran the CI. The macOS jobs failed, but it's not related to your changes. We need to fix the CI jobs on macOS.

@czerouni
Copy link
Author

Great, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rez depends -p will crash in some situations build_requires with @late can not run rez env -b to create build env
2 participants