Skip to content
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

Fix bug in cached dependency resolution with exact resolvable #365

Merged
merged 3 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pex/bin/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def configure_clp_pex_resolution(parser, builder):
'--cache-ttl',
dest='cache_ttl',
type=int,
default=None,
default=3600,
help='The cache TTL to use for inexact requirement specifications.')

group.add_option(
Expand Down
24 changes: 9 additions & 15 deletions pex/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,15 @@ def __init__(self, cache, cache_ttl, *args, **kw):

# Short-circuiting package iterator.
def package_iterator(self, resolvable, existing=None):
packages = []
if self.__cache_ttl or resolvable.exact:
iterator = Iterator(fetchers=[Fetcher([self.__cache])])
packages = self.filter_packages_by_interpreter(
resolvable.compatible(iterator),
self._interpreter,
self._platform
)

if packages:
if resolvable.exact:
return packages

if self.__cache_ttl:
packages = self.filter_packages_by_ttl(packages, self.__cache_ttl)
iterator = Iterator(fetchers=[Fetcher([self.__cache])])
packages = self.filter_packages_by_interpreter(
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably kill the packages = [] above btw.

resolvable.compatible(iterator),
self._interpreter,
self._platform
)

if packages and self.__cache_ttl:
packages = self.filter_packages_by_ttl(packages, self.__cache_ttl)

return itertools.chain(
packages,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os
import time

import pytest
from twitter.common.contextutil import temporary_dir
Expand Down Expand Up @@ -70,6 +71,15 @@ def test_cached_dependency_pinned_unpinned_resolution_multi_run():
dists = resolve(['project', 'project==1.1.0'], fetchers=fetchers, cache=cd, cache_ttl=1000)
assert len(dists) == 1
assert dists[0].version == '1.1.0'
# Third run, if exact resolvable and inexact resolvable, and cache_ttl is expired, exact
# resolvable should pull from pypi as well since inexact will and the resulting
# resolvable_set.merge() would fail.
Crawler.reset_cache()
time.sleep(1)
dists = resolve(['project', 'project==1.1.0'], fetchers=fetchers, cache=cd,
cache_ttl=1)
assert len(dists) == 1
assert dists[0].version == '1.1.0'


def test_resolve_prereleases():
Expand Down