Skip to content

Commit

Permalink
Merge pull request #50 from scrapinghub/fix-version-name
Browse files Browse the repository at this point in the history
[MRG+1] Fix version names when setup.py --version returns many lines
  • Loading branch information
José Ricardo committed Sep 3, 2015
2 parents ac0815f + edc56c8 commit aff61ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
8 changes: 6 additions & 2 deletions shub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ def _deploy_dependency_egg(apikey, project_id):
success = "Deployed eggs list at: https://dash.scrapinghub.com/p/%s/eggs"
log(success % project_id)

def _last_line_of(s):
return s.split('\n')[-1]


def _get_dependency_name():
# In some cases, python setup.py --name returns more than one line, so we use the last one to get the name
return run('python setup.py --name').split("\n")[-1]
return _last_line_of(run('python setup.py --name'))


def _get_dependency_version(name):
Expand All @@ -161,7 +164,8 @@ def _get_dependency_version(name):
elif isdir('.bzr'):
return pwd_bzr_version()

return "%s-%s" % (name, run('python setup.py --version'))
version = _last_line_of(run('python setup.py --version'))
return "%s-%s" % (name, version)


def _get_egg_info(name):
Expand Down
36 changes: 36 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
# coding=utf-8


import unittest
from mock import patch
from shub import utils
from click.testing import CliRunner


class UtilsTest(unittest.TestCase):
def setUp(self):
self.runner = CliRunner()

def test_dependency_version_from_setup_is_parsed_properly(self):
def check(cmd):
if cmd == 'python setup.py --version':
return setup_version

setup_version = ('Building lxml version 3.4.4.'
'\nBuilding without Cython.'
'\nUsing build configuration of libxslt 1.1.28'
'\n3.4.4')

with self.runner.isolated_filesystem():
with patch('shub.utils.run', side_effect=check) as mocked_run:
# given
mocked_run.return_value = setup_version
# when
version = utils._get_dependency_version('lxml')
# then
self.assertEquals('lxml-3.4.4', version)


if __name__ == '__main__':
unittest.main()

0 comments on commit aff61ac

Please sign in to comment.