pypa / virtualenv

Virtual Python Environment builder
https://virtualenv.pypa.io
MIT License
4.8k stars 1.03k forks source link

Better handle devendorized environment #881

Closed warsaw closed 5 years ago

warsaw commented 8 years ago

In Debian, we unbundle pip._vendor, which causes a problem in virtualenv 15.0.0's SCRIPT. Here's the code from virtualenv.py (see https://github.com/pypa/virtualenv/blob/15.0.0/virtualenv.py#L854-L860)

@@ -851,7 +870,8 @@ def install_wheel(project_names, py_executable, search_dirs=None,

         import pip

-        cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
+        #cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
+        cert_data = None
         if cert_data is not None:
             cert_file = tempfile.NamedTemporaryFile(delete=False)
             cert_file.write(cert_data)

The problem is that the call to pkgutil.get_data() raises an OSError instead of, as the Python documentation states, it should return None. I've seen both errno 11 and errno 0 come from this call. To make things even weirder, I can't reproduce it outside of the environment that SCRIPT is run in.

In any case, I report this here to see if there's anything you can do to remove the need for the above patch, which I'm going to apply to Debian's virtualenv 15.0.0

dstufft commented 8 years ago

Probably we should just do:

try:
    cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
except Exception:
    cert_data = None
if cert_data is not None:
    cert_file = tempfile.NamedTemporaryFile(delete=False)
    cert_file.write(cert_data)

That will hide any errors. We risk silencing an error if someone has debundled pip, but not cacert.pem from requests, but it will "fail closed" and gracefully. Overall I don't think the risk is very high of that, and we should ideally be as fault tolerant as we can here.

warsaw commented 8 years ago

:+1:

I guess if you wanted to narrow it down, you could just catch OSError. Or you could log the exception. Or we could figure out why Python's pkgutil docs are lying :)

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.