-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Add blacklist handling for skipping requirements in pex resolver #457
Merged
kwlzn
merged 4 commits into
pex-tool:master
from
CMLivingston:clivingston/pkg-blacklist-for-resolver
Apr 12, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,10 +151,11 @@ def filter_packages_by_interpreter(cls, packages, interpreter, platform): | |
return [package for package in packages | ||
if package.compatible(interpreter.identity, platform)] | ||
|
||
def __init__(self, allow_prereleases=None, interpreter=None, platform=None): | ||
def __init__(self, allow_prereleases=None, interpreter=None, platform=None, pkg_blacklist=None): | ||
self._interpreter = interpreter or PythonInterpreter.get() | ||
self._platform = platform or Platform.current() | ||
self._allow_prereleases = allow_prereleases | ||
self._blacklist = pkg_blacklist.copy() if pkg_blacklist else {} | ||
|
||
def package_iterator(self, resolvable, existing=None): | ||
if existing: | ||
|
@@ -180,6 +181,12 @@ def build(self, package, options): | |
'Could not get distribution for %s on platform %s.' % (package, self._platform)) | ||
return dist | ||
|
||
def _resolvable_is_blacklisted(self, resolvable_name): | ||
return ( | ||
resolvable_name in self._blacklist and | ||
self._interpreter.identity.matches(self._blacklist[resolvable_name]) | ||
) | ||
|
||
def resolve(self, resolvables, resolvable_set=None): | ||
resolvables = [(resolvable, None) for resolvable in resolvables] | ||
resolvable_set = resolvable_set or _ResolvableSet() | ||
|
@@ -193,7 +200,11 @@ def resolve(self, resolvables, resolvable_set=None): | |
if resolvable in processed_resolvables: | ||
continue | ||
packages = self.package_iterator(resolvable, existing=resolvable_set.get(resolvable.name)) | ||
resolvable_set.merge(resolvable, packages, parent) | ||
|
||
# TODO: Remove blacklist strategy in favor of smart requirement handling | ||
# https://github.com/pantsbuild/pex/issues/456 | ||
if not self._resolvable_is_blacklisted(resolvable.name): | ||
resolvable_set.merge(resolvable, packages, parent) | ||
processed_resolvables.add(resolvable) | ||
|
||
built_packages = {} | ||
|
@@ -299,7 +310,8 @@ def resolve(requirements, | |
precedence=None, | ||
cache=None, | ||
cache_ttl=None, | ||
allow_prereleases=None): | ||
allow_prereleases=None, | ||
pkg_blacklist=None): | ||
"""Produce all distributions needed to (recursively) meet `requirements` | ||
|
||
:param requirements: An iterator of Requirement-like things, either | ||
|
@@ -329,6 +341,14 @@ def resolve(requirements, | |
``context``. | ||
:keyword allow_prereleases: (optional) Include pre-release and development versions. If | ||
unspecified only stable versions will be resolved, unless explicitly included. | ||
:keyword pkg_blacklist: (optional) A blacklist dict (str->str) that maps package name to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would love to have a better documentation on why a package needed to be blacklisted |
||
an interpreter constraint. If a package name is in the blacklist and its interpreter | ||
constraint matches the target interpreter, skip the requirement. This is needed to ensure | ||
that universal requirement resolves for a target interpreter version do not error out on | ||
interpreter specific requirements such as backport libs like `functools32`. | ||
For example, a valid blacklist is {'functools32': 'CPython>3'}. | ||
NOTE: this keyword is a temporary fix and will be reverted in favor of a long term solution | ||
tracked by: https://github.com/pantsbuild/pex/issues/456 | ||
:returns: List of :class:`pkg_resources.Distribution` instances meeting ``requirements``. | ||
:raises Unsatisfiable: If ``requirements`` is not transitively satisfiable. | ||
:raises Untranslateable: If no compatible distributions could be acquired for | ||
|
@@ -367,11 +387,13 @@ def resolve(requirements, | |
cache_ttl, | ||
allow_prereleases=allow_prereleases, | ||
interpreter=interpreter, | ||
platform=platform) | ||
platform=platform, | ||
pkg_blacklist=pkg_blacklist) | ||
else: | ||
resolver = Resolver(allow_prereleases=allow_prereleases, | ||
interpreter=interpreter, | ||
platform=platform) | ||
platform=platform, | ||
pkg_blacklist=pkg_blacklist) | ||
|
||
return resolver.resolve(resolvables_from_iterable(requirements, builder)) | ||
|
||
|
@@ -384,7 +406,8 @@ def resolve_multi(requirements, | |
precedence=None, | ||
cache=None, | ||
cache_ttl=None, | ||
allow_prereleases=None): | ||
allow_prereleases=None, | ||
pkg_blacklist=None): | ||
"""A generator function that produces all distributions needed to meet `requirements` | ||
for multiple interpreters and/or platforms. | ||
|
||
|
@@ -415,6 +438,14 @@ def resolve_multi(requirements, | |
``context``. | ||
:keyword allow_prereleases: (optional) Include pre-release and development versions. If | ||
unspecified only stable versions will be resolved, unless explicitly included. | ||
:keyword pkg_blacklist: (optional) A blacklist dict (str->str) that maps package name to | ||
an interpreter constraint. If a package name is in the blacklist and its interpreter | ||
constraint matches the target interpreter, skip the requirement. This is needed to ensure | ||
that universal requirement resolves for a target interpreter version do not error out on | ||
interpreter specific requirements such as backport libs like `functools32`. | ||
For example, a valid blacklist is {'functools32': 'CPython>3'}. | ||
NOTE: this keyword is a temporary fix and will be reverted in favor of a long term solution | ||
tracked by: https://github.com/pantsbuild/pex/issues/456 | ||
:yields: All :class:`pkg_resources.Distribution` instances meeting ``requirements``. | ||
:raises Unsatisfiable: If ``requirements`` is not transitively satisfiable. | ||
:raises Untranslateable: If no compatible distributions could be acquired for | ||
|
@@ -435,7 +466,8 @@ def resolve_multi(requirements, | |
precedence, | ||
cache, | ||
cache_ttl, | ||
allow_prereleases): | ||
allow_prereleases, | ||
pkg_blacklist=pkg_blacklist): | ||
if resolvable not in seen: | ||
seen.add(resolvable) | ||
yield resolvable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this TODO is good, but it'd be great to make the temporary nature of this change more evident in the docstring(s) below where developers are more likely to look. Would be good to include the ticket in there as well.