Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Pip 6.0+ compatibility fixes #66

Merged
merged 4 commits into from
Jan 5, 2015
Merged
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
20 changes: 17 additions & 3 deletions peep.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def activate(specifier):
except ImportError:
from pip.util import url_to_filename as url_to_path # 0.6.2
from pip.index import PackageFinder, Link
from pip.log import logger
try:
from pip.log import logger
except ImportError:
from pip import logger # 6.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was a typo, but then discovered they jumped from 1.5.6 to 6.0. Yay versioning!

from pip.req import parse_requirements


Expand Down Expand Up @@ -231,6 +234,7 @@ class EmptyOptions(object):
"""
default_vcs = None
skip_requirements_regex = None
isolated_mode = False


def memoize(func):
Expand Down Expand Up @@ -727,8 +731,18 @@ def downloaded_reqs_from_path(path, argv):
:arg argv: The commandline args, starting after the subcommand

"""
return [DownloadedReq(req, argv) for req in
parse_requirements(path, options=EmptyOptions())]
try:
return [DownloadedReq(req, argv) for req in
parse_requirements(path, options=EmptyOptions())]
except TypeError:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be safer to try the import and catch the ImportError rather than catching TypeError for such a broad piece of code. We could even build a kwargs dict then, avoiding the repeated list comp. Thank you for the fix!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm assuming the import succeeds if and only if session is a required arg. If not, then never mind.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I believe you could import PipSession from pip.download before session became a required kwarg, I'm just not sure exactly what version of pip parse_requirements began accepting the session kwarg, so it seemed safer to use the original call that we knew worked up to pip 1.5.6 and only pass in a session if it complains with the TypeError.

# session is a required kwarg as of pip 6.0 and will raise
# a TypeError if missing. It needs to be a PipSession instance,
# but in older versions we can't import it from pip.download
# (nor do we need it at all) so we only import it in this except block
from pip.download import PipSession
return [DownloadedReq(req, argv) for req in
parse_requirements(path, options=EmptyOptions(),
session=PipSession())]


def peep_install(argv):
Expand Down