wrapt icon indicating copy to clipboard operation
wrapt copied to clipboard

`discover_post_import_hooks()` fails when `setuptools` is not installed

Open GSVarsha opened this issue 4 months ago • 16 comments

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

GSVarsha avatar Jul 27 '25 14:07 GSVarsha

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.

GrahamDumpleton avatar Jul 27 '25 23:07 GrahamDumpleton

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'

GSVarsha avatar Jul 29 '25 12:07 GSVarsha

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+

GSVarsha avatar Jul 30 '25 09:07 GSVarsha

Hi @GrahamDumpleton, when can we expect a new version of the wrapt module?

GSVarsha avatar Aug 11 '25 05:08 GSVarsha

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.

GrahamDumpleton avatar Aug 11 '25 05:08 GrahamDumpleton

Try:

wrapt==2.0.0rc1

from PyPi and let me know if works or if you have issues. Thanks.

GrahamDumpleton avatar Aug 11 '25 09:08 GrahamDumpleton

Hi @GrahamDumpleton, I uninstalled setuptools and tried installing wrapt-2.0.0rc1 and it works well for us.

GSVarsha avatar Aug 12 '25 08:08 GSVarsha

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.

GrahamDumpleton avatar Aug 12 '25 08:08 GrahamDumpleton

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.

GrahamDumpleton avatar Aug 12 '25 21:08 GrahamDumpleton

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?

GSVarsha avatar Aug 25 '25 07:08 GSVarsha

Yes, patch version (1.17.4). Problem was I got completely distracted with other stuff so forgot about. 😩

GrahamDumpleton avatar Aug 26 '25 01:08 GrahamDumpleton

Hi @GrahamDumpleton, could you please let me know when we can expect a new release?

GSVarsha avatar Sep 15 '25 06:09 GSVarsha

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/

GrahamDumpleton avatar Sep 15 '25 09:09 GrahamDumpleton

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!

GSVarsha avatar Oct 10 '25 09:10 GSVarsha

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.

GrahamDumpleton avatar Oct 10 '25 11:10 GrahamDumpleton

Version 2.0.0 has been released.

GrahamDumpleton avatar Oct 20 '25 02:10 GrahamDumpleton