mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Let's fully unload pip
This commit is contained in:
parent
0b6f848082
commit
0b01f21f00
1 changed files with 13 additions and 21 deletions
|
@ -22,6 +22,7 @@ requisite to a pkg.installed state for the package which provides pip
|
|||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import re
|
||||
import types
|
||||
import logging
|
||||
try:
|
||||
import pkg_resources
|
||||
|
@ -60,34 +61,25 @@ if HAS_PIP is True:
|
|||
HAS_PIP = False
|
||||
# Remove references to the loaded pip module above so reloading works
|
||||
import sys
|
||||
pip_related_entries = [
|
||||
(k, v) for (k, v) in sys.modules.items()
|
||||
or getattr(v, '__module__', '').startswith('pip.')
|
||||
or (isinstance(v, types.ModuleType) and v.__name__.startswith('pip.'))
|
||||
]
|
||||
for name, entry in pip_related_entries:
|
||||
sys.modules.pop(name)
|
||||
del entry
|
||||
|
||||
del pip
|
||||
if 'pip' in sys.modules:
|
||||
del sys.modules['pip']
|
||||
sys_modules_pip = sys.modules.pop('pip', None)
|
||||
if sys_modules_pip is not None:
|
||||
del sys_modules_pip
|
||||
|
||||
try:
|
||||
from pip.exceptions import InstallationError
|
||||
except ImportError:
|
||||
InstallationError = ValueError
|
||||
|
||||
# pylint: disable=unused-import
|
||||
# When reloading, some functions are ofen lost from sys.modules. Try to prevent that.
|
||||
try:
|
||||
# Pip 9.0.x
|
||||
from pip.download import is_url, path_to_url, is_archive_file
|
||||
from pip.utils import is_installable_dir
|
||||
from pip.req.req_install import _strip_extras
|
||||
except ImportError:
|
||||
try:
|
||||
# Pip 10.x
|
||||
from pip._internal.req.req_install import _strip_extras
|
||||
except ImportError:
|
||||
# Pip >= 18.x
|
||||
from pip._internal.req.constructors import _strip_extras
|
||||
# Pip >= 10.x
|
||||
from pip._internal.download import is_url, path_to_url, is_archive_file
|
||||
from pip._internal.utils.misc import is_installable_dir
|
||||
# pylint: enable=unused-import
|
||||
|
||||
# pylint: enable=import-error
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
Loading…
Add table
Reference in a new issue