diff --git a/news/5265.bugfix.rst b/news/5265.bugfix.rst new file mode 100644 index 0000000000..18bdde5422 --- /dev/null +++ b/news/5265.bugfix.rst @@ -0,0 +1 @@ +Revise pip import patch to include only ``pipenv`` from site-packages and removed ``--ignore-installed`` argument from pip install in order to fix regressions with ``--use-site-packages``. diff --git a/pipenv/core.py b/pipenv/core.py index c0e82fa770..5408d6e305 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1529,7 +1529,6 @@ def pip_install( project_python(project, system=allow_global), _get_runnable_pip(), "install", - "--ignore-installed", ] pip_args = get_pip_args( project, diff --git a/pipenv/patched/pip/__main__.py b/pipenv/patched/pip/__main__.py index 03b90ffda6..b424ab2037 100644 --- a/pipenv/patched/pip/__main__.py +++ b/pipenv/patched/pip/__main__.py @@ -26,7 +26,13 @@ warnings.filterwarnings( "ignore", category=DeprecationWarning, module=".*packaging\\.version" ) - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))) + import importlib.util + import sys + spec = importlib.util.spec_from_file_location( + "pipenv", location=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "__init__.py")) + pipenv = importlib.util.module_from_spec(spec) + sys.modules["pipenv"] = pipenv + spec.loader.exec_module(pipenv) from pipenv.patched.pip._internal.cli.main import main as _main sys.exit(_main()) diff --git a/tasks/vendoring/patches/patched/_post_pip_import.patch b/tasks/vendoring/patches/patched/_post_pip_import.patch index 5657d89e05..aced2cf21e 100644 --- a/tasks/vendoring/patches/patched/_post_pip_import.patch +++ b/tasks/vendoring/patches/patched/_post_pip_import.patch @@ -1,12 +1,18 @@ diff --git a/pipenv/patched/pip/__main__.py b/pipenv/patched/pip/__main__.py -index 204a8ca2..546caab1 100644 +index 24d42002b..b424ab203 100644 --- a/pipenv/patched/pip/__main__.py +++ b/pipenv/patched/pip/__main__.py -@@ -26,6 +26,7 @@ if __name__ == "__main__": +@@ -26,6 +26,13 @@ if __name__ == "__main__": warnings.filterwarnings( "ignore", category=DeprecationWarning, module=".*packaging\\.version" ) -+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))) ++ import importlib.util ++ import sys ++ spec = importlib.util.spec_from_file_location( ++ "pipenv", location=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "__init__.py")) ++ pipenv = importlib.util.module_from_spec(spec) ++ sys.modules["pipenv"] = pipenv ++ spec.loader.exec_module(pipenv) from pipenv.patched.pip._internal.cli.main import main as _main sys.exit(_main())