[Fix] editable install in python>=3.13#1673
Conversation
python>=3.13
|
@HAOCHENYE This one ready to be reviewed. |
|
This PR fails at some pytest unit due to Network connecting issue or me not having multi-GPUs to test 😂, including:
And pytest runs on
|
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a Python 3.13+ compatibility issue in the get_version() function caused by PEP 667 changes to how exec() interacts with local namespaces. The fix explicitly provides a dictionary as the global namespace to exec() and retrieves the version from that dictionary, ensuring the code works correctly across Python versions.
Key Changes:
- Modified
get_version()to use an explicit dictionary forexec()namespace instead of relying onlocals() - Changed version retrieval from
locals()['__version__']to direct dictionary access
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Leave this PR for review last. I'm considering replacing setuptools with hatch as mmengine's new build system. |
This is a sub-PR of #1665.
This PR fixes a compatibility issue in
get_version()caused by relying onexec()to modify the local namespace.The current implementation executes a version file with
exec(...)and then attempts to retrieve__version__fromlocals(). While this may appear to work inPython ≤3.12, it breaks inPython 3.13+due to changes introduced by PEP 667, which standardizes execution context behavior and preventsexec()from mutating a function’s local scope.To ensure correctness and forward compatibility, this PR explicitly passes a dedicated dictionary as the global namespace to
exec(), and safely reads__version__from that namespace.Noted that
setup.pyis deprecated and we should includepyproject.tomlaccording to the latest PyPA, and PEP 621.