• [gentoo-dev] [RFC] dev-python/namespace-* retirement plan

    From =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?=@21:1/5 to All on Sat Apr 9 17:30:01 2022
    Hi, everyone.

    TL;DR I think I came up with a feasible plan towards cleanly removing dev-python/namespace-* packages that aren't technically needed anymore
    with modern versions of Python.


    What are namespace packages? Let's take "zope" as an example.
    Normally, various subpackages like "zope.interface" and
    "zope.configuration" would have all to be present in a single directory,
    that is inside the "zope" package. However, if "zope" is made a
    namespace package, its subpackages can be loaded from different
    locations. Notably, in order to test zope.configuration prior to
    installing it, we load it from build tree but its dependency
    zope.interface from system site-packages.

    Historically, for this to work, the "zope/__init__.py" had to specify
    some magic incantations.  On Gentoo, we've added dev-python/namespace-*
    that installed these magical "__init__.py" files and made all
    subpackages (e.g. dev-python/zope-*) depend on it.

    However, Python 3.3 introduced PEP 420 implicit namespaces that made
    magical incantations unnecessary -- if "zope" didn't include
    "__init__.py", it was implicitly treated as a namespace. Unfortunately,
    there were some interoperability issues between the two kinds of magical incantations and implicit namespaces. So while we were able to retire pkgutil-style namespaces, setuptools-style namespaces remained.

    I think we can change that now.


    I've done some experiments, particularly with dev-python/zope-interface
    and dev-python/zope-configuration. If nobody finds a problem with this solution, I think we can aim to bump all packages relying on namespaces
    and retire them in 1-2 months.

    The rough idea is to remove RDEP on dev-python/namespace-* from
    the package, and updating python_test to use a temporary pkgutil-style incantation (yes, for setuptools-style packages), e.g.:

    ```
    python_compile() {
    distutils-r1_python_compile
    find "${BUILD_DIR}" -name '*.pth' -delete || die
    }

    python_test() {
    cd "${BUILD_DIR}/install$(python_get_sitedir)" || die
    # this is needed to keep the tests working while
    # dev-python/namespace-zope is still installed
    cat > zope/__init__.py <<-EOF || die
    __path__ = __import__('pkgutil').extend_path(__path__, __name__)
    EOF
    eunittest
    rm zope/__init__.py || die
    }
    ```

    With this hack, I've been able to get the tests to work with all
    the possible scenarios, i.e.:

    a. with and without the package in question installed,

    b. with and without dev-python/namespace-* installed.

    The second point means that we can transition gradually. Once all
    packages with namespace-* dep are gone, we can lastrite that package
    and add blockers to trigger cleanup from user systems. We'll have to
    keep the test hack for some more time but I don't think that's a deal
    breaker.


    WDYT?

    --
    Best regards,
    Michał Górny

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)