Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail when the pyc files is missing for the host Python 2 #1741

Merged
merged 1 commit into from
Mar 19, 2020
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
1 change: 1 addition & 0 deletions docs/changelog/1738.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not fail when the pyc files is missing for the host Python 2 - by :user:`gaborbernat`.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def from_stdlib(mappings, name):
src = from_std / name
if src.exists():
return src, to_std, True
return mappings[0] / name, mappings[1], False
# if not exists, fallback to first in list
return mappings[0][0] / name, mappings[0][1], False

@classmethod
def mappings(cls, interpreter):
Expand Down
31 changes: 20 additions & 11 deletions tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,27 +493,36 @@ def _get_sys_path(flag=None):
not (CURRENT.implementation == "CPython" and PY2),
reason="stdlib components without py files only possible on CPython2",
)
def test_pyc_only(tmp_path, mocker, session_app_data):
@pytest.mark.parametrize(
"py, pyc",
list(
product(
[True, False] if Python2.from_stdlib(Python2.mappings(CURRENT), "os.py")[2] else [False],
[True, False] if Python2.from_stdlib(Python2.mappings(CURRENT), "os.pyc")[2] else [False],
)
),
)
def test_py_pyc_missing(tmp_path, mocker, session_app_data, py, pyc):
"""Ensure that creation can succeed if os.pyc exists (even if os.py has been deleted)"""
interpreter = PythonInfo.from_exe(sys.executable, session_app_data)
host_pyc, _, host_pyc_exists = Python2.from_stdlib(Python2.mappings(interpreter), "os.pyc")
if not host_pyc_exists:
pytest.skip("missing system os.pyc at {}".format(host_pyc))
previous = Python2.from_stdlib

def from_stdlib(mappings, name):
path, to, exists = previous(mappings, name)
if name.endswith(".py"):
exists = False
if name.endswith("py"):
exists = py
elif name.endswith("pyc"):
exists = pyc
return path, to, exists

mocker.patch.object(Python2, "from_stdlib", side_effect=from_stdlib)

result = cli_run([ensure_text(str(tmp_path)), "--without-pip", "--activators", ""])
result = cli_run([ensure_text(str(tmp_path)), "--without-pip", "--activators", "", "-vv"])
py_at = Python2.from_stdlib(Python2.mappings(CURRENT), "os.py")[1](result.creator, Path("os.py"))
py = pyc is False or py # if pyc is False we fallback to serve the py, which will exist (as we only mock the check)
assert py_at.exists() is py

assert not (result.creator.stdlib / "os.py").exists()
assert (result.creator.stdlib / "os.pyc").exists()
assert "os.pyc" in result.creator.debug["os"]
pyc_at = Python2.from_stdlib(Python2.mappings(CURRENT), "osc.py")[1](result.creator, Path("os.pyc"))
assert pyc_at.exists() is pyc


def test_zip_importer_can_import_setuptools(tmp_path):
Expand Down