`discover_post_import_hooks()` fails when `setuptools` is not installed
In Python 3.12 and later, since setuptools is not included in standard library, discover_post_import_hooks() fails when setuptools is not installed in the environment.
It took so much time to find that this is the actual problem because the function just returns bluntly and dynamic import at runtime with autowrapt simply didn't work ☹️.
Would be interesting to migrate to importlib.metadata/ importlib.resources or add setuptools as a dependency or in the worst case, add a warning message before the return statement.
I can definitely help/work on one of these suggestions if you need an extra set of hands. Happy to discuss which direction might be best 😄 .
https://github.com/GrahamDumpleton/wrapt/blob/557b9dc90cac0812e06a7efefe7516c465eb6aa6/src/wrapt/importer.py#L94
Since wrapt now only supports Python 3.8+, and importlib.metadata was added in Python 3.8, if that is compatible with how setuptools used to work, then we could just switch to using it instead of setuptools.
Is it compatible? Or do we need to support both with a direction for people to start using whatever alternative configuration mechanism is used for the latter and deprecate setuptools way of doing things.
Hi @GrahamDumpleton , thanks for the quick reply!
I've forked the repo and made the changes since I wasn't able to push any new branches here. Could you please review my PR https://github.com/GrahamDumpleton/wrapt/pull/292 ? I'm open to any suggestions and happy to discuss further.
Things I've considered:
Although importlib.metadata was introduced in python 3.8, we get the below error in python < 3.10
entry_points() got an unexpected keyword argument 'group'
Is it compatible? Or do we need to support both with a direction for people to start using whatever alternative configuration mechanism is used for the latter and deprecate setuptools way of doing things.
Hello @GrahamDumpleton yes, it is compatible. I think as you mentioned earlier, we could completely switch to importlib.metadata since wrapt now only supports Python 3.8+
Hi @GrahamDumpleton, when can we expect a new version of the wrapt module?
I had pointed a few people at develop branch and asked if could try installing from GitHub but have got no answers from anyone. So was going to make a dev release on PyPi and post on social sites to ask people if can test. Would prefer to get some confirmation is okay by some people in real use before proper release.
Try:
wrapt==2.0.0rc1
from PyPi and let me know if works or if you have issues. Thanks.
Hi @GrahamDumpleton, I uninstalled setuptools and tried installing wrapt-2.0.0rc1 and it works well for us.
Just be aware that there will be a 2.0.0rc2 at some point and type hint support will likely change a bit. Letting you know in case you starting do anything with type hints, as will need to change some things later. In other words perhaps not rely on type hints with that version.
I am not happy with some things in 2.0.0 so may be a while before it is released, so I will back port the changes for import hooks and release a 1.17.4 release with them.
I am not happy with some things in 2.0.0 so may be a while before it is released, so I will back port the changes for import hooks and release a 1.17.4 release with them.
Hi @GrahamDumpleton . so this would be a patch version and not a minor or major one?
Yes, patch version (1.17.4). Problem was I got completely distracted with other stuff so forgot about. 😩
Hi @GrahamDumpleton, could you please let me know when we can expect a new release?
This change will only be in version 2.0.0 now. For update on 2.0.0 see:
- https://grahamdumpleton.me/posts/2025/09/status-of-wrapt/
Hello @GrahamDumpleton,
At this point it seems to be safe to release a 2.0.0 final version, so I will be aiming to double check everything over the coming week and get the new version released in time for Python 3.14
Can we expect a new wrapt release sometime soon? TIA!
Version 2.0.0rc4 is available. It is stable and no notable issues with it. There will be a 2.0.0rc5 though which addresses a really strange corner case which almost certain no one would encounter in practice. I don't know when 2.0.0 final will be as the changes for 2.0.0rc5 still need to be made.
Version 2.0.0 has been released.