Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 21 Lib/test/test_getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,27 @@ def test_venv_posix(self):
actual = getpath(ns, expected)
self.assertEqual(expected, actual)

def test_venv_posix_without_home_key(self):
ns = MockPosixNamespace(
argv0="/venv/bin/python3",
PREFIX="/usr",
ENV_PATH="/usr/bin",
)
# Setup the bare minimum venv
ns.add_known_xfile("/usr/bin/python3")
ns.add_known_xfile("/venv/bin/python3")
ns.add_known_link("/venv/bin/python3", "/usr/bin/python3")
ns.add_known_file("/venv/pyvenv.cfg", [
# home = key intentionally omitted
])
expected = dict(
executable="/venv/bin/python3",
prefix="/venv",
base_prefix="/usr",
)
actual = getpath(ns, expected)
self.assertEqual(expected, actual)

def test_venv_changed_name_posix(self):
"Test a venv layout on *nix."
ns = MockPosixNamespace(
Expand Down
11 changes: 4 additions & 7 deletions 11 Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,9 @@ def search_up(prefix, *landmarks, test=isfile):
venv_prefix = None
pyvenvcfg = []

# Search for the 'home' key in pyvenv.cfg. Currently, we don't consider the
# presence of a pyvenv.cfg file without a 'home' key to signify the
# existence of a virtual environment — we quietly ignore them.
# XXX: If we don't find a 'home' key, we don't look for another pyvenv.cfg!
# Search for the 'home' key in pyvenv.cfg. If a home key isn't found,
# then it means a venv is active and home is based on the venv's
# executable (if its a symlink, home is where the symlink points).
for line in pyvenvcfg:
key, had_equ, value = line.partition('=')
if had_equ and key.strip().lower() == 'home':
Expand Down Expand Up @@ -412,10 +411,8 @@ def search_up(prefix, *landmarks, test=isfile):
if isfile(candidate):
base_executable = candidate
break
# home key found; stop iterating over lines
break
else:
# We didn't find a 'home' key in pyvenv.cfg (no break), reset venv_prefix.
venv_prefix = None


# ******************************************************************************
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.