AcademySoftwareFoundation / rez

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

Upgrading from 2.112.0, rez.packages experiences an error in 2.114.0 #1861

Closed celeste-ramirez-srt closed 1 month ago

celeste-ramirez-srt commented 1 month ago

In the effort to upgrade our version of Rez to the most recent, I'm encountering an issue where rez-env is working fine, but as soon as we try to import rez.packages to be used in our custom GUI, python complains about an IMPORT_ERROR, an incomplete module and claims there are circular imports. Stacktrace below. I have upgraded from 2.112.0 to 2.114.1, then to 3.0.0 and 3.2.0, before going back down to 2.113.0 and 2.114.0. In all attempts except for 2.113.0, I got the same behavior.

Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rez.packages
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\packages.py", line 5, in <module>
    from rez.package_repository import package_repository_manager
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\package_repository.py", line 5, in <module>
    from rez.utils.resources import ResourcePool, ResourceHandle
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\utils\resources.py", line 38, in <module>
    from rez.config import config
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\config.py", line 1042, in <module>
    config.data
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\config.py", line 663, in data
    d[key] = getattr(self, key)
             ^^^^^^^^^^^^^^^^^^
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\utils\data_utils.py", line 244, in __get__
    result = self.func(instance)
             ^^^^^^^^^^^^^^^^^^^
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\utils\data_utils.py", line 671, in getter
    return self._validate_key(key, attr, key_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\config.py", line 733, in _validate_key
    return key_schema.validate(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\config.py", line 74, in validate
    data = self.schema.validate(data)
           ^^^^^^^^^^^
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\utils\data_utils.py", line 291, in __get__
    result = self.func(owner)
             ^^^^^^^^^^^^^^^^
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\config.py", line 308, in schema
    from rez.solver import VariantSelectMode
  File "d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\solver.py", line 17, in <module>
    from rez.packages import iter_packages
ImportError: cannot import name 'iter_packages' from partially initialized module 'rez.packages' (most likely due to a circular import) (d:\pipeline\rez\packages\rez\rez\3.0.0\platform-windows\arch-64bit\python\rez\packages.py)

Environment

To Reproduce In Rez 2.114.0:

  1. Open a command prompt
  2. Enter the Python interpreter
  3. Type import rez and see that Rez imports fine
  4. Type import rez.packages and see the traceback.

Expected behavior I expected the import to succeed so the module could be used in our GUI.

Actual behavior The module fails to import due to what Python says is a circular import. I am not sure how to verify that. Given that it fails every time on the reading of config values, I was very careful when updating the rezconfig file to the new version, but it is possible that I've missed something there. I am happy to provide my rezconfig if that will be useful.

Regression My last functional version of Rez is 2.113.0.

maxnbk commented 1 month ago

So, I'm on Windows, and I attempted to reproduce the issue with an incredibly minimal config, and failed to do so. (rez.packages imported fine, I'm on rez 3.2.0 with python-3.10 for reference).

Following the stack trace more carefully, it does feel or seem like the issue is more closely tied to the actual rez config in use, given that the error occurred seemingly during schema validation when creating the config singleton.

Could you share your (appropriately anonymized if necessary) config?

celeste-ramirez-srt commented 1 month ago

If anyone else comes through with a similar stacktrace, here is what fixed this for me. I backed up our existing rezconfig.py, then I copied the exact rezconfig.py file from source into the location in the REZ_CONFIG_FILE env var. I then changed these values using the backup. I can now import the rez.packages module just fine. Somehow, merging the two files with a text diff seemed to cause these issues.