Skip to content

Fix module extension detection for python 3.10 - #3663

Merged
henryiii merged 3 commits into
pybind:masterfrom
mbasaglia:python3.10
Jan 31, 2022
Merged

henryiii merged 3 commits into
pybind:masterfrom
mbasaglia:python3.10

Conversation

@mbasaglia

@mbasaglia mbasaglia commented Jan 29, 2022 •

Copy link
Copy Markdown
Contributor

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
Comment thread tools/pybind11NewTools.cmake Outdated
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
Copy Markdown
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

@henryiii henryiii left a comment

Copy link
Copy Markdown
Collaborator

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

rwgk commented Jan 29, 2022

Copy link
Copy Markdown
Collaborator

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