diff --git a/shub/deploy.py b/shub/deploy.py index f7ef3836..f3195e66 100644 --- a/shub/deploy.py +++ b/shub/deploy.py @@ -22,8 +22,7 @@ from shub.exceptions import (BadParameterException, NotFoundException, ShubException) from shub.utils import (create_default_setup_py, create_scrapinghub_yml_wizard, - get_config, inside_project, make_deploy_request, - run_python) + inside_project, make_deploy_request, run_python) from shub.image.upload import upload_cmd @@ -158,8 +157,7 @@ def _upload_egg(endpoint, eggpath, project, version, auth, verbose, keep_log, def _build_egg(): if not inside_project(): raise NotFoundException("No Scrapy project found in this location.") - settings = get_config().get('settings', 'default') - create_default_setup_py(settings=settings) + create_default_setup_py() d = tempfile.mkdtemp(prefix="shub-deploy-") run_python(['setup.py', 'clean', '-a', 'bdist_egg', '-d', d]) egg = glob.glob(os.path.join(d, '*.egg'))[0] diff --git a/shub/utils.py b/shub/utils.py index a69ec486..59777409 100644 --- a/shub/utils.py +++ b/shub/utils.py @@ -70,6 +70,8 @@ def create_default_setup_py(**kwargs): with remember_cwd(): os.chdir(os.path.dirname(closest)) if not os.path.exists('setup.py'): + if 'settings' not in kwargs: + kwargs['settings'] = get_config().get('settings', 'default') with open('setup.py', 'w') as f: f.write(_SETUP_PY_TEMPLATE % kwargs) click.echo("Created setup.py at {}".format(os.getcwd())) diff --git a/tests/test_deploy.py b/tests/test_deploy.py index 568f01a2..88a85210 100644 --- a/tests/test_deploy.py +++ b/tests/test_deploy.py @@ -4,16 +4,14 @@ from __future__ import absolute_import import unittest -import os -import pytest from click.testing import CliRunner from mock import patch from shub import deploy -from shub.config import ShubConfig -from shub.exceptions import InvalidAuthException, NotFoundException, \ - ShubException, BadParameterException +from shub.exceptions import (NotFoundException, ShubException, + BadParameterException) +from shub.utils import create_default_setup_py from .utils import AssertInvokeRaisesMixin, mock_conf @@ -106,6 +104,19 @@ def test_custom_deploy_bad_registry(self): self._make_project() self.assertInvokeRaises(BadParameterException, deploy.cli, ('custom3',)) + @patch('shub.deploy.make_deploy_request') + def test_deploy_with_custom_setup_py(self, mock_deploy_req): + with self.runner.isolated_filesystem(): + # This scrapy.cfg contains no "settings" section, so creating a + # default setup.py would fail (because we can't find the settings + # module) + open('scrapy.cfg', 'w').close() + # However, we already have a setup.py... + create_default_setup_py(settings='some_module') + # ... so shub should not fail while trying to create one + result = self.runner.invoke(deploy.cli) + self.assertEqual(result.exit_code, 0) + class DeployFilesTest(unittest.TestCase): def setUp(self):