Repository: pypa/pip

Issue:
Optionally load C dependencies based on platform
PR for #4098.

I'm not thrilled importing from `pip.compat` to detect windows since it requires a `del` statement to leave no trace. Could of course duplicate the same logic to avoid the import + del, but that seems even worse.


Discussion:
Changes to `_vendor` files should either be upstreamed to the vendored project (in this case requests) or use patches in https://github.com/pypa/pip/tree/master/tasks/vendoring.
@xavfernandez The instructions for updating vendor patches seem incomplete. First, the `pathlib` package needs to be installed in addition to `invoke`. After that I'm still getting an error when running `invoke vendoring.update` as show below. Please advise.

```
[vendoring.update] Rewriting all imports related to vendored libs
Traceback (most recent call last):
  File "/Users/xxx/.virtualenvs/pip/bin/invoke", line 11, in <module>
    sys.exit(program.run())
  File "/Users/xxx/.virtualenvs/pip/lib/python2.7/site-packages/invoke/program.py", line 274, in run
    self.execute()
  File "/Users/xxx/.virtualenvs/pip/lib/python2.7/site-packages/invoke/program.py", line 389, in execute
    executor.execute(*self.tasks)
  File "/Users/xxx/.virtualenvs/pip/lib/python2.7/site-packages/invoke/executor.py", line 113, in execute
    result = call.task(*args, **call.kwargs)
  File "/Users/xxx/.virtualenvs/pip/lib/python2.7/site-packages/invoke/tasks.py", line 111, in __call__
    result = self.body(*args, **kwargs)
  File "/Users/xxx/projects/pip/tasks/vendoring/__init__.py", line 128, in main
    vendor(ctx, vendor_dir)
  File "/Users/xxx/projects/pip/tasks/vendoring/__init__.py", line 111, in vendor
    rewrite_file_imports(item, vendored_libs)
  File "/Users/xxx/projects/pip/tasks/vendoring/__init__.py", line 58, in rewrite_file_imports
    text = item.read_text()
AttributeError: 'PosixPath' object has no attribute 'read_text'
```
@dstufft (or anyone else) What are your thoughts on this PR?
> @xavfernandez The instructions for updating vendor patches seem incomplete. First, the pathlib package needs to be installed in addition to invoke.

The `vendoring.update` task is expected to be run with python 3.5
@xavfernandez Anything outstanding on this?
This will need rebasing after #4342 
Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the ``master`` branch into this pull request or rebase this pull request against ``master`` then it will eligible for code review and hopefully merging!

Resolving patch:
diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py
--- a/src/pip/_internal/download.py
+++ b/src/pip/_internal/download.py
@@ -27,8 +27,10 @@
 from pip._vendor.six.moves.urllib import parse as urllib_parse
 from pip._vendor.six.moves.urllib import request as urllib_request
 from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
+from pip._vendor.urllib3.util import IS_PYOPENSSL
 
 import pip
+from pip._internal.compat import WINDOWS
 from pip._internal.exceptions import HashMismatch, InstallationError
 from pip._internal.locations import write_delete_marker_file
 from pip._internal.models import PyPI
@@ -48,9 +50,10 @@
 
 try:
     import ssl  # noqa
-    HAS_TLS = True
 except ImportError:
-    HAS_TLS = False
+    ssl = None
+
+HAS_TLS = (ssl is not None) or IS_PYOPENSSL
 
 __all__ = ['get_file_content',
            'is_url', 'url_to_path', 'path_to_url',
diff --git a/src/pip/_vendor/requests/__init__.py b/src/pip/_vendor/requests/__init__.py
--- a/src/pip/_vendor/requests/__init__.py
+++ b/src/pip/_vendor/requests/__init__.py
@@ -80,13 +80,13 @@ def check_compatibility(urllib3_version, chardet_version):
                   RequestsDependencyWarning)
 
 # Attempt to enable urllib3's SNI support, if possible
-# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this
-#       prevents upgrading cryptography.
-# try:
-#     from pip._vendor.urllib3.contrib import pyopenssl
-#     pyopenssl.inject_into_urllib3()
-# except ImportError:
-#     pass
+from pip._internal.compat import WINDOWS
+if not WINDOWS:
+    try:
+        from pip._vendor.urllib3.contrib import pyopenssl
+        pyopenssl.inject_into_urllib3()
+    except ImportError:
+        pass
 
 # urllib3's DependencyWarnings should be silenced.
 from pip._vendor.urllib3.exceptions import DependencyWarning


Test patch: