Skip to content
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

Merged
merged 3 commits into from
Jan 31, 2022

Conversation

mbasaglia
Copy link
Contributor

@mbasaglia mbasaglia commented Jan 29, 2022

Description

I was having issues with python 3.10, looks like distutils.sysconfig has been merged into sysconfig (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:

* Fix CMake extension suffix computation on Python 3.10+

@mbasaglia mbasaglia requested a review from henryiii as a code owner January 29, 2022 14:30
@@ -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'))"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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

Copy link
Collaborator

@henryiii henryiii left a 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. ;)

@rwgk rwgk requested a review from Skylion007 January 29, 2022 23:17
@rwgk
Copy link
Collaborator

rwgk commented Jan 29, 2022

LGTM (but it's out of my wheelhouse).

@henryiii henryiii merged commit dc4717b into pybind:master Jan 31, 2022
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jan 31, 2022
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Feb 2, 2022
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.

4 participants