diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 63cd700d..426279d4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,19 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + include: + - python-version: '3.6' + tox-env: min + - python-version: '3.6' + tox-env: py + - python-version: '3.7' + tox-env: py + - python-version: '3.8' + tox-env: py + - python-version: '3.9' + tox-env: py + - python-version: '3.10' + tox-env: py steps: - uses: actions/checkout@v2 @@ -29,7 +41,7 @@ jobs: run: pip install tox - name: Run tests - run: tox -e py + run: tox -e ${{ matrix.tox-env }} - name: Upload coverage report run: | @@ -43,7 +55,19 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + include: + - python-version: '3.6' + tox-env: min + - python-version: '3.6' + tox-env: py + - python-version: '3.7' + tox-env: py + - python-version: '3.8' + tox-env: py + - python-version: '3.9' + tox-env: py + - python-version: '3.10' + tox-env: py steps: - uses: actions/checkout@v2 @@ -57,7 +81,7 @@ jobs: run: pip install tox - name: Run tests - run: tox -e py + run: tox -e ${{ matrix.tox-env }} tests-windows: name: "Test: py${{ matrix.python-version }}, Windows" @@ -65,7 +89,19 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + include: + - python-version: '3.6' + tox-env: min + - python-version: '3.6' + tox-env: py + - python-version: '3.7' + tox-env: py + - python-version: '3.8' + tox-env: py + - python-version: '3.9' + tox-env: py + - python-version: '3.10' + tox-env: py steps: - uses: actions/checkout@v2 @@ -79,4 +115,4 @@ jobs: run: pip install tox - name: Run tests - run: tox -e py + run: tox -e ${{ matrix.tox-env }} diff --git a/setup.py b/setup.py index f5f856c9..1e2def9a 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ zip_safe=False, python_requires='>=3.6', install_requires=[ - 'click==7.0', + 'click', 'docker', 'pip', 'PyYAML', diff --git a/shub/utils.py b/shub/utils.py index 6b444f85..11665ec3 100644 --- a/shub/utils.py +++ b/shub/utils.py @@ -24,6 +24,7 @@ import pip import requests import yaml +from click import ParamType # https://github.com/scrapinghub/shub/pull/309#pullrequestreview-113977920 try: @@ -785,6 +786,13 @@ def _update_conf_file(filename, target, project, repository): click.echo("Saved to %s." % filename) +class _AnyParamType(ParamType): + name = "any" + + def convert(self, value, param, ctx): + return value + + def create_scrapinghub_yml_wizard(conf, target='default', image=None): """ Ask user for project ID, ensure they have access to that project, and save @@ -830,6 +838,6 @@ def create_scrapinghub_yml_wizard(conf, target='default', image=None): if image or (image is None and _detect_custom_image_project()): repository = click.prompt( "Image repository (leave empty to use Scrapinghub's repository)", - default=True, show_default=False) + default=True, show_default=False, type=_AnyParamType()) _update_conf(conf, target, project, repository) _update_conf_file(closest_sh_yml, target, project, repository) diff --git a/tests/test_config.py b/tests/test_config.py index 8ac649a1..292fc473 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,6 +10,7 @@ import six import yaml from click.testing import CliRunner +from yaml import CLoader as Loader from shub.config import (get_target, get_target_conf, get_version, load_shub_config, ShubConfig, Target, @@ -353,7 +354,7 @@ def test_save_partial(self): """) conf.save('conf.yml') with open('conf.yml', 'r') as f: - self.assertEqual(yaml.load(f), {'project': 123}) + self.assertEqual(yaml.load(f, Loader=Loader), {'project': 123}) conf = self._get_conf_with_yml(""" projects: @@ -363,7 +364,7 @@ def test_save_partial(self): """) conf.save('conf.yml') with open('conf.yml', 'r') as f: - self.assertEqual(yaml.load(f), { + self.assertEqual(yaml.load(f, Loader=Loader), { 'project': 123, 'requirements': {'file': 'reqs.txt'}} ) @@ -373,7 +374,7 @@ def test_save_skip_defaults(self): with CliRunner().isolated_filesystem(): conf.save('conf.yml') with open('conf.yml', 'r') as f: - self.assertEqual(yaml.load(f), None) + self.assertEqual(yaml.load(f, Loader=Loader), None) def test_save_shortcut(self): conf = ShubConfig() @@ -391,7 +392,7 @@ def test_save_shortcut(self): with CliRunner().isolated_filesystem(): conf.save('conf.yml') with open('conf.yml', 'r') as f: - self.assertEqual(yaml.load(f), expected_yml_dict) + self.assertEqual(yaml.load(f, Loader=Loader), expected_yml_dict) def test_save_shortcut_updated(self): OLD_YML = """\ @@ -446,11 +447,11 @@ def test_save_partial_options(self): conf.save('conf.yml', options=['projects']) with open('conf.yml', 'r') as f: self.assertEqual( - yaml.load(f), + yaml.load(f, Loader=Loader), {'project': 12345, 'stack': 'custom-stack'}) conf.save('conf.yml') with open('conf.yml', 'r') as f: - self.assertEqual(yaml.load(f), {'project': 12345}) + self.assertEqual(yaml.load(f, Loader=Loader), {'project': 12345}) def test_normalized_projects(self): expected_projects = { diff --git a/tests/test_login.py b/tests/test_login.py index 2f49c7df..a08ce475 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -6,6 +6,7 @@ import yaml from click.testing import CliRunner +from yaml import CLoader as Loader from shub import login from shub.exceptions import AlreadyLoggedInException @@ -51,7 +52,7 @@ def test_write_key_to_new_file(self): with self.runner.isolated_filesystem() as fs: self._run(fs=fs) with open('.scrapinghub.yml', 'r') as f: - conf = yaml.load(f) + conf = yaml.load(f, Loader=Loader) self.assertEqual(conf['apikeys']['default'], VALID_KEY) def test_write_key_to_existing_file(self): @@ -63,7 +64,7 @@ def test_write_key_to_existing_file(self): files = {'.scrapinghub.yml': VALID_SCRAPINGHUB_YML} self._run(files=files, fs=fs) with open('.scrapinghub.yml', 'r') as f: - conf = yaml.load(f) + conf = yaml.load(f, Loader=Loader) self.assertEqual(conf['apikeys']['default'], VALID_KEY) self.assertEqual(conf['endpoints']['other'], "some_endpoint") @@ -91,7 +92,7 @@ def test_use_suggestion_to_log_in(self): fs=fs, ) with open('.scrapinghub.yml', 'r') as f: - conf = yaml.load(f) + conf = yaml.load(f, Loader=Loader) self.assertEqual(conf['apikeys']['default'], apikey_suggestion) def test_login_attempt_after_login_doesnt_lead_to_an_error(self): diff --git a/tests/test_migrate_eggs.py b/tests/test_migrate_eggs.py index 9c597035..b03c7d55 100644 --- a/tests/test_migrate_eggs.py +++ b/tests/test_migrate_eggs.py @@ -4,6 +4,7 @@ import yaml from click.testing import CliRunner +from yaml import CLoader as Loader from shub.migrate_eggs import main from shub.config import Target @@ -89,7 +90,7 @@ def test_full(self): ) with open('./scrapinghub.yml') as f: - abc = yaml.load(f) + abc = yaml.load(f, Loader=Loader) eggs = abc['requirements'].pop('eggs') eggs = [e.replace('\\', '/') for e in eggs] self.assertEqual( @@ -132,7 +133,7 @@ def test_no_eggs(self): ) with open('./scrapinghub.yml') as f: - abc = yaml.load(f) + abc = yaml.load(f, Loader=Loader) self.assertDictEqual( abc, { @@ -186,7 +187,7 @@ def test_override_reqs_file(self): ) with open('./scrapinghub.yml') as f: - abc = yaml.load(f) + abc = yaml.load(f, Loader=Loader) self.assertDictEqual( abc, { diff --git a/tox.ini b/tox.ini index 913568c1..acb75696 100644 --- a/tox.ini +++ b/tox.ini @@ -6,10 +6,14 @@ basepython = python3 setenv = USING_TOX=1 deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/tests/requirements.txt + -r tests/requirements.txt commands = - pytest --verbose --cov=shub --cov-report=term-missing --cov-report=html --cov-report=xml {posargs:shub tests} + pytest --cov=shub --cov-report=term-missing --cov-report=html --cov-report=xml {posargs:shub tests} + +[testenv:min] +deps = + {[testenv]deps} + -r requirements.txt [testenv:freeze] install_command =