Skip to content

Commit

Permalink
Merge pull request #13 from kevinconway/pop-empty-list
Browse files Browse the repository at this point in the history
Fix issues related to .pth rewrite addition
  • Loading branch information
kevinconway authored Aug 28, 2019
2 parents 53cb9cc + c903eb3 commit 19f64d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="venvctrl",
version="0.4.0",
version="0.4.1",
url="https://github.com/kevinconway/venvctrl",
description="API for virtual environments.",
author="Kevin Conway",
Expand Down
34 changes: 17 additions & 17 deletions tests/test_virtual_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ def test_relocate_long_shebang(venv):
)


def test_relocate_no_original_path(venv):
"""Test that the original path is not found in files."""
def test_relocate_no_original_path_pth(venv):
"""Test that the original path is not found in .pth files."""
path = "/testpath"
original_path = venv.abspath
f = open(venv.bin.abspath + "/something.pth", "w")
f.write(original_path)
f.close()
venv.relocate(path)
dirs = list(venv.dirs)
files = list(venv.files)
while dirs or files:
for file_ in files:
with open(file_.abspath, "r") as source:
try:
lines = source.readlines()
except UnicodeDecodeError:
# Skip any non-text files. Binary files are out of
# scope for this test.
continue
for line in lines:
assert original_path not in line, file_.abspath
next_dir = dirs.pop()
files = list(next_dir.files)
dirs = [venv]
while dirs:
current = dirs.pop()
dirs.extend(current.dirs)
for file_ in current.files:
if file_.abspath.endswith(".pth"):
with open(file_.abspath, "r") as source:
try:
lines = source.readlines()
except UnicodeDecodeError:
# Skip any non-text files. Binary files are out of
# scope for this test.
continue
for line in lines:
assert original_path not in line, file_.abspath
11 changes: 5 additions & 6 deletions venvctrl/venv/relocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def relocate(self, destination):
# site-packages, bundled within an egg directory, or both.
original_path = self.path
original_abspath = self.abspath
dirs = list(self.dirs)
files = list(self.files)
while dirs or files:
for file_ in files:
dirs = [self]
while dirs:
current = dirs.pop()
dirs.extend(current.dirs)
for file_ in current.files:
if file_.abspath.endswith(".pth"):
content = ""
with open(file_.abspath, "r") as source:
Expand All @@ -72,8 +73,6 @@ def relocate(self, destination):
content = content.replace(original_path, destination)
with open(file_.abspath, "w") as source:
source.write(content)
next_dir = dirs.pop()
files = list(next_dir.files)

def move(self, destination):
"""Reconfigure and move the virtual environment to another path.
Expand Down

0 comments on commit 19f64d7

Please sign in to comment.