Proposed fix to #1180 (and maybe #932 & #1104) #1902

Merged
merged 3 commits into from Jul 3, 2014

Projects

None yet

2 participants

@tnotstar

This is a rebased final version of a proposed solution to fix
issues #932, #1104 & #1180. Following changes have been done:

  • Implemented a new class PipXmlrpcTransport using a
    contained PipSession object.

  • Modified the pip/commands/search.py to make use of the
    PipXmlrpcTransport class.

  • Properly initialized options for testing SearchCommand:

    • Changed options_mock to an options object built from parse_args, to properly initialize default options.
@tnotstar tnotstar Proposed fix to #1180 (and maybe #932 & #1104)
This is a rebased final version of a proposed solution to fix
issues #932, #1104 & #1180. Following changes have been done:

* Implemented a new class `PipXmlrpcTransport` using a
  contained `PipSession` object.

* Modified the `pip/commands/search.py` to make use of the
  `PipXmlrpcTransport` class.

* Properly initialized options for testing `SearchCommand`:
  - Changed `options_mock` to an `options` object built from
    `parse_args`, to properly initialize default options.
57f2d47
@dstufft
Python Packaging Authority member

Hey, sorry this took so long to review, I've been debugging a really wonky issue.

This looks pretty good, only thing I'd ask is can you change it so that you have the session in a context manager? like:

with self._build_session(...) as session:
    pass  # Do stuff with the session here

This way the connection pool will get closed explicitly? You can see I've made this change to the other commands in #1882.

@tnotstar tnotstar Close requests session in `search` command
* Added a `with` block to handle `session` life-cycle. As commented
  in #1902
47402e5
@tnotstar

Perfect! I just committed a little patch for it. Now, we can wait for the Travis' report.

@dstufft dstufft commented on an outdated diff Jul 3, 2014
pip/download.py
@@ -695,3 +696,28 @@ def unpack_file_url(link, location, download_dir=None):
# a download dir is specified and not already downloaded
if download_dir and not already_downloaded:
_copy_file(from_path, download_dir, content_type, link)
+
+
+class PipXmlrpcTransport(xmlrpc_client.Transport):
+ """Provide a `xmlrpclib.Transport` implementation via a `PipSession`
+ object.
+ """
+ def __init__(self, index_url, session, use_datetime=False):
+ xmlrpc_client.Transport.__init__(self, use_datetime)
+ index_parts = urlparse.urlparse(index_url)
+ self._scheme = index_parts.scheme
+ session.headers.update({'Content-Type': 'text/xml'})
@dstufft
dstufft Jul 3, 2014

Hmm, I just noticed this. I'd rather not modify the session in this. Can we just pass this header on each self._session.post call? That way sessions don't start acting differently just because you used them in PipXmlrpcTransport``.

@dstufft
Python Packaging Authority member

Real sorry, one more thing I noticed. Also can you add this to changelog? That you've fixed those issues and pip search respects proxies now?

@tnotstar tnotstar Passing headers per-request in PipXmlrpcTransport
* Changed `PipXmlrpcTransport` to pass headers at request scope
* Added summary line to the changelog
0dedf2b
@tnotstar

It's no problem! I think 0dedf2b made the job.

@dstufft
Python Packaging Authority member

Ok this looks pretty good now. Thanks! The tests are failing but they look transient. I kicked them and we'll see if they pass.

@dstufft dstufft merged commit d359d1a into pypa:develop Jul 3, 2014

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@dstufft
Python Packaging Authority member

Yay, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment