Commit cdd7c77e by Arun Babu Neelicattu

pip: remove orphaned nspkg.pth files manually

Relates-to: #2238
parent a0904f95
...@@ -113,6 +113,11 @@ class PipInstaller(BaseInstaller): ...@@ -113,6 +113,11 @@ class PipInstaller(BaseInstaller):
raise raise
# This is a workaround for https://github.com/pypa/pip/issues/4176
nspkg_pth_file = self._env.site_packages / "{}-nspkg.pth".format(package.name)
if nspkg_pth_file.exists():
nspkg_pth_file.unlink()
# If we have a VCS package, remove its source directory # If we have a VCS package, remove its source directory
if package.source_type == "git": if package.source_type == "git":
src_dir = self._env.path / "src" / package.name src_dir = self._env.path / "src" / package.name
......
from setuptools import setup, find_packages
setup(
name="namespace_package_one",
version="1.0.0",
description="",
long_description="",
author="Python Poetry",
author_email="noreply@python-poetry.org",
license="MIT",
packages=find_packages(),
namespace_packages=["namespace_package"],
zip_safe=False,
)
import shutil
import pytest import pytest
from poetry.installation.pip_installer import PipInstaller from poetry.installation.pip_installer import PipInstaller
...@@ -152,3 +154,42 @@ def test_requirement_git_develop_true(installer, package_git): ...@@ -152,3 +154,42 @@ def test_requirement_git_develop_true(installer, package_git):
expected = ["-e", "git+git@github.com:demo/demo.git@master#egg=demo"] expected = ["-e", "git+git@github.com:demo/demo.git@master#egg=demo"]
assert expected == result assert expected == result
def test_uninstall_git_package_nspkg_pth_cleanup(mocker, tmp_venv, pool):
# this test scenario requires a real installation using the pip installer
installer = PipInstaller(tmp_venv, NullIO(), pool)
# use a namepspace package
package = Package("namespace-package-one", "1.0.0")
package.source_type = "git"
package.source_url = "https://github.com/demo/namespace-package-one.git"
package.source_reference = "master"
package.develop = True
# we do this here because the virtual env might not be usable if failure case is triggered
pth_file_candidate = tmp_venv.site_packages / "{}-nspkg.pth".format(package.name)
# in order to reproduce the scenario where the git source is removed prior to proper
# clean up of nspkg.pth file, we need to make sure the fixture is copied and not
# symlinked into the git src directory
def copy_only(source, dest):
if dest.exists():
dest.unlink()
if source.is_dir():
shutil.copytree(str(source), str(dest))
else:
shutil.copyfile(str(source), str(dest))
mocker.patch("tests.helpers.copy_or_symlink", new=copy_only)
# install package and then remove it
installer.install(package)
installer.remove(package)
assert not Path(pth_file_candidate).exists()
# any command in the virtual environment should trigger the error message
output = tmp_venv.run("python", "-m", "site")
assert "Error processing line 1 of {}".format(pth_file_candidate) not in output
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment