-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix module extension detection for python 3.10 #3663
Conversation
tools/pybind11NewTools.cmake
Outdated
@@ -110,7 +110,7 @@ if(NOT DEFINED PYTHON_MODULE_EXTENSION) | |||
execute_process( | |||
COMMAND | |||
"${${_Python}_EXECUTABLE}" "-c" | |||
"from distutils import sysconfig as s;print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" | |||
"import sys; s = __import__('distutils.sysconfig').sysconfig if sys.version_info < (3, 10) else __import__('sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"import sys; s = __import__('distutils.sysconfig').sysconfig if sys.version_info < (3, 10) else __import__('sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" | |
"import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" |
https://docs.python.org/3/library/importlib.html#importlib.import_module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't delete the changelog entry from the PR template, we build the changelog from that.
Looks great to me! Nice to see distutils disappearing. ;)
LGTM (but it's out of my wheelhouse). |
Description
I was having issues with python 3.10, looks like
distutils.sysconfig
has been merged intosysconfig
(https://docs.python.org/3/distutils/apiref.html#module-distutils.sysconfig) so this adds a condition to import sysconfig on python >= 3.10.Probably not the most "pythonic" code but I kept it as a 1 liner.
Suggested changelog entry: