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

Sending also "count" in resource queries when there's no "follow". Fixes #374 #375

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ matrix:
language: generic
env:
- TOX_ENV=py27
- PYTHON_VERSION='2.7'
- PYTHON_VERSION='2.7.9'
- os: osx
language: generic
env:
Expand All @@ -40,7 +40,8 @@ branches:
before_install: |
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
# From https://pythonhosted.org/CodeChat/.travis.yml.html
brew install pyenv-virtualenv
# Homebrew currently fails after updating. See also: https://discuss.circleci.com/t/brew-install-fails-while-updating/32992/4
HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv-virtualenv
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# See https://github.com/travis-ci/travis-ci/issues/4834, but
Expand Down
6 changes: 4 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
click
docker-py
PyYAML
requests
#PyYAML
#requests
retrying
six
tqdm

scrapinghub>=2.0.3

pip<19.3

# address known vulnerabilities
requests>=2.20.0 # CVE-2018-18074
pyyaml>=4.2b1 # CVE-2017-18342
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ six==1.10.0
tqdm==4.11.2
urllib3==1.25.3 # via requests
websocket-client==0.37.0 # via docker-py

# The following packages are considered to be unsafe in a requirements file:
# pip==19.2.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
install_requires=[
'click',
'docker-py',
'pip',
'pip<19.3',
'PyYAML',
'retrying',
'requests',
Expand Down
4 changes: 3 additions & 1 deletion shub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def job_resource_iter(job, resource, output_json=False, follow=True,
follow = False
resource_iter = resource.iter_json if output_json else resource.iter_values
if not follow:
for item in resource_iter(startafter=last_item_key):
for item in resource_iter(startafter=last_item_key, count=tail):
yield item
return
while True:
Expand Down Expand Up @@ -637,6 +637,8 @@ def download_from_pypi(dest, pkg=None, reqfile=None, extra_args=None):
no_wheel = ['--no-binary=:all:']
if pip_version >= LooseVersion('8'):
cmd = 'download'
if pip_version >= LooseVersion('19.3'):
raise NotImplementedError('Expecting pip<19.3')
with patch_sys_executable():
pip_main([cmd, '-d', dest, '--no-deps'] + no_wheel + extra_args +
target)
Expand Down
12 changes: 10 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def test_job_resource_iter(self, mock_sleep):
job = MagicMock(spec=['key', 'metadata', 'resource'])
job.key = 'jobkey'
job.metadata = {'state': 'running'}
job.resource.stats.return_value = {'totals': {'input_values': 0}}

def make_items(iterable):
return [json.dumps({'_key': x}) for x in iterable]
Expand Down Expand Up @@ -252,14 +253,16 @@ def jri_result(follow, tail=None):
output_json=True,
))

job.resource.iter_json = magic_iter
job.resource.iter_json = Mock(wraps=magic_iter)

magic_iter.stage = 0
self.assertEqual(jri_result(False), make_items([1, 2, 3]))
self.assertIsNone(job.resource.iter_json.call_args[1].get('count'))
self.assertFalse(mock_sleep.called)

magic_iter.stage = 0
self.assertEqual(jri_result(True), make_items([1, 2, 3, 4, 5, 6]))
self.assertEqual(jri_result(True, tail=6), make_items([1, 2, 3, 4, 5, 6]))
self.assertIsNone(job.resource.iter_json.call_args[1].get('count'))
self.assertTrue(mock_sleep.called)

magic_iter.stage = 0
Expand All @@ -269,6 +272,7 @@ def jri_result(follow, tail=None):
magic_iter.stage = 2
job.resource.stats.return_value = {'totals': {'input_values': 1000}}
self.assertEqual(jri_result(True, tail=3), [])
self.assertEqual(job.resource.iter_json.call_args[1].get('count'), 3)

@patch('shub.utils.requests.get', autospec=True)
def test_latest_github_release(self, mock_get):
Expand Down Expand Up @@ -371,6 +375,10 @@ def _call(*args, **kwargs):
pipargs = _call('tmpdir', reqfile='req.txt')
self.assertEqual(pipargs.index('-r') + 1, pipargs.index('req.txt'))

# pip>=19.3 shall be unsupported for now
mock_pip.__version__ = '19.3'
self.assertRaises(NotImplementedError, _call, ['tmpdir'], {'pkg': 'shub'})

# Replace deprecated commands in newer versions
mock_pip.__version__ = '7.1.2.dev0'
pipargs = _call('tmpdir', pkg='shub')
Expand Down