pip icon indicating copy to clipboard operation
pip copied to clipboard

pip should properly uninstall pkgutil namespace packages

Open pradyunsg opened this issue 7 years ago • 5 comments

pip currently uninstalls __init__.py for pkgutil namespace packages, even when there are multiple packages that are installed for the same namespace; breaking it.

An example test-case for this is there in #4504.

pradyunsg avatar Aug 23 '17 08:08 pradyunsg

I want to put this into the 10.0 milestone but I'd like to know what @pypa/pip-committers think about that first though.

pradyunsg avatar Aug 23 '17 08:08 pradyunsg

We need reference counting on the __init__.py files. I think probably we can simply remove it ONLY if there are no other references to __init__.py in RECORDs other than the one which we are uninstalling

ghost avatar Aug 23 '17 21:08 ghost

from pip.operations.freeze import freeze
from pip.commands.show import search_packages_info

installed_distributions = list(freeze())

# Remove distributions to be uninstalled

            for info in search_packages_info(installed_distributions):
                files = info['files']
                root = info['location']
                for file in files:
                    full_path = os.path.abspath(
                        os.path.join(root, file))
                    # Remove full_path from all req_uninstall

ghost avatar Aug 23 '17 21:08 ghost

Was there some discussion about this issue in some other place? @pradyunsg seemed keen to get this implemented, but it seems nothing happened for a while and now it's considered a "feature request" rather than a bug. Is there any workaround for the issue?

aflag avatar Jul 01 '22 14:07 aflag

With Python 2 reaching EOL I don’t see much benefit working on pkgutil namespace support now. Feel free to work on it if you want to (the change can likely be accepted), but don’t expect anyone else to be particularly motivated about this.

uranusjr avatar Jul 04 '22 07:07 uranusjr