Patch the find method from pkg_resources.WorkingSet.#684
Patch the find method from pkg_resources.WorkingSet.#684mauritsvanrees merged 3 commits intomasterfrom
Conversation
|
Hm, 49.0.0 and 59.8.0 seem to be too old for this approach – time to drop support for them? |
I have pushed a commit that fixes the AttributeError. When setuptools is older than 61, do not apply the patch. Of course then on older versions you may run into problems exactly because the patch is not there. For me it would be fine to drop support for |
Let this use the code from `setuptools` 75.8.2, if the currently used version is older. This is better at finding installed distributions. Fixes #683
The new version of the method would give an error there:
```
Traceback (most recent call last):
File "/home/runner/work/buildout/buildout/dev.py", line 27, in <module>
import zc.buildout.easy_install
File "/home/runner/work/buildout/buildout/src/zc/buildout/easy_install.py", line 1007, in <module>
buildout_and_setuptools_dists = list(install(['zc.buildout'], None,
File "/home/runner/work/buildout/buildout/src/zc/buildout/easy_install.py", line 1005, in install
return installer.install(specs, working_set)
File "/home/runner/work/buildout/buildout/src/zc/buildout/easy_install.py", line 758, in install
dist = env.best_match(req, ws)
File "/home/runner/work/buildout/buildout/venvs/python3.10/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1045, in best_match
dist = working_set.find(req)
File "/home/runner/work/buildout/buildout/src/zc/buildout/patches.py", line 355, in find
self.normalized_to_canonical_keys.get(req.key),
AttributeError: 'WorkingSet' object has no attribute 'normalized_to_canonical_keys'
```
See for example this test run with `setuptools` 59.8.0:
https://github.com/buildout/buildout/actions/runs/13680434937/job/38251141064?pr=684#step:5:207
They fail on Python 3.9. Which is strange, because the latest setuptools version supports Python 3.9, so why does it not fail there? See [this test run](https://github.com/buildout/buildout/actions/runs/13680729029/job/38252752156?pr=684#step:5:210): ``` Now calling 'python dev.py' to create 'bin/buildout' script in main directory. Traceback (most recent call last): File "/home/runner/work/buildout/buildout/dev.py", line 27, in <module> import zc.buildout.easy_install File "/home/runner/work/buildout/buildout/src/zc/buildout/__init__.py", line 38, in <module> import zc.buildout.patches # NOQA File "/home/runner/work/buildout/buildout/src/zc/buildout/patches.py", line 386, in <module> patch_pkg_resources_working_set_find() File "/home/runner/work/buildout/buildout/src/zc/buildout/patches.py", line 354, in patch_pkg_resources_working_set_find def find(self, req: Requirement) -> Distribution | None: TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' ```
c9e97d0 to
1bf8b3d
Compare
|
The tests failed on Python 3.9 due to a problem with type hints. So I have removed the type hints. No sense in spending time on this. I have rebased on master. |
|
It's green! Please review. |
dataflake
left a comment
There was a problem hiding this comment.
I don't have much knowledge about setuptools internals, but if this works and the tests are green...
|
I have released this in 4.1.3. |
|
Hallelujah it works... |
Let this use the code from
setuptools75.8.2, if the currently used version is older. This is better at finding installed distributions.Fixes #683