Bug 264703

Summary: [AutoInstall] unable to install zope.interface on Python < 3.9
Product: WebKit Reporter: Sam Sneddon [:gsnedders] <gsnedders>
Component: Tools / TestsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: jbedard, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=263485
https://bugs.webkit.org/show_bug.cgi?id=263589

Description Sam Sneddon [:gsnedders] 2023-11-12 06:01:13 PST
After deleting Tools/Scripts/libraries/autoinstalled/python-2-x86_64:

Downloading setuptools-44.1.1...
Installed setuptools-44.1.1!
Downloading wheel-0.35.1...
Installed wheel-0.35.1!
Downloading pyparsing-2.4.7...
Installed pyparsing-2.4.7!
Downloading packaging-20.4.0...
Installed packaging-20.4.0!
Downloading setuptools-scm-5.0.2...
Installed setuptools-scm-5.0.2!
Downloading urllib3-1.26.17...
Installed urllib3-1.26.17!
Downloading requests-2.26.0...
Installed requests-2.26.0!
Downloading chardet-3.0.4...
Installed chardet-3.0.4!
Downloading certifi-2021.10.8...
Installed certifi-2021.10.8!
Downloading idna-2.10.0...
Installed idna-2.10.0!
Downloading PySocks-1.7.1...
Installed PySocks-1.7.1!
Downloading mechanize-0.4.5...
Installed mechanize-0.4.5!
Downloading pyfakefs-3.7.2...
Installed pyfakefs-3.7.2!
Downloading pycodestyle-2.5.0...
Installed pycodestyle-2.5.0!
Downloading mock-3.0.5...
Installed mock-3.0.5!
Downloading atomicwrites-1.1.5...
Installed atomicwrites-1.1.5!
Downloading py-1.11.0...
Installed py-1.11.0!
Downloading funcsigs-1.0.2...
Installed funcsigs-1.0.2!
Downloading beautifulsoup4-4.9.3...
Installed beautifulsoup4-4.9.3!
Downloading zope-interface-5.1.0...
Failed to install zope-interface-5.1.0!
...
INTERNALERROR>   File "/Volumes/gsnedders/projects/Safari/OpenSource/Tools/Scripts/webkitpy/conftest.py", line 112, in pytest_collection_finish
INTERNALERROR>     AutoInstall.install_everything()
INTERNALERROR>   File "/Volumes/gsnedders/projects/Safari/OpenSource/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py", line 687, in install_everything
INTERNALERROR>     package.install()
INTERNALERROR>   File "/Volumes/gsnedders/projects/Safari/OpenSource/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py", line 416, in install
INTERNALERROR>     raise OSError('Cannot install {}, could not find setup.py'.format(self.name))
INTERNALERROR> OSError: Cannot install zope.interface, could not find setup.py

Will do some brief investigation on Monday.
Comment 1 Radar WebKit Bug Importer 2023-11-12 06:01:24 PST
<rdar://problem/118297071>
Comment 2 Sam Sneddon [:gsnedders] 2023-11-13 05:02:09 PST
This seems practically identical to bug 263485?

There https://github.com/WebKit/WebKit/pull/19384 eventually got closed in preference for using aliases.

That said, I _still_ don't understand how aliases actually solve this. Their only behaviour is:

        for alias in package.aliases:
            cls.packages[alias].append(package)
        cls.packages[package.name].append(package)

i.e., packages get registered under both their own name and their aliases.

So zope.interface gets registered for both "zope" and "zope.interface".

I think this might practically only be a problem when the AutoInstaller is manually invoked (either with AutoInstall.install("zope.interface") or AutoInstall.install_everything()).

I suspect this is potentially just a problem based on install order? And maybe we just haven't hit this on Python 3 due to hash randomization? Or it could be some import machinary change.
Comment 3 Sam Sneddon [:gsnedders] 2023-11-13 05:13:57 PST
Ah, this does also fail on Python 3, just only when there are wheels, and that's only Python 3.8 and earlier (c.f. https://pypi.org/project/zope.interface/5.1.0/#files).

The following fails on Python 3.8 and earlier, and it doesn't matter when it's explicitly installed or imported:

```
import tempfile
import shutil

from webkitcorepy.autoinstall import AutoInstall, Package, Version

tmpdirname = tempfile.mkdtemp()

try:
    AutoInstall.set_directory(tmpdirname)

    zope_interface = Package(
        "zope.interface", Version(5, 1, 0), aliases=["zope"], pypi_name="zope-interface"
    )
    AutoInstall.register(zope_interface)
    AutoInstall.install(zope_interface)
finally:
    shutil.rmtree(tmpdirname)
```
Comment 4 Sam Sneddon [:gsnedders] 2023-11-16 10:16:01 PST
Effectively fixed by bug 264755.

*** This bug has been marked as a duplicate of bug 264755 ***