Skip to content

Commit

Permalink
Allow click versions other than 7.0 (#416)
Browse files Browse the repository at this point in the history
* Allow click versions other than 7.0

* Fix copy-paste error

* Simplify param processing

* _AnyParamType: set name
  • Loading branch information
Gallaecio authored Jun 14, 2022
1 parent 42a6015 commit aea38d7
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 23 deletions.
48 changes: 42 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -57,15 +81,27 @@ 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"
runs-on: windows-latest
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
Expand All @@ -79,4 +115,4 @@ jobs:
run: pip install tox

- name: Run tests
run: tox -e py
run: tox -e ${{ matrix.tox-env }}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
zip_safe=False,
python_requires='>=3.6',
install_requires=[
'click==7.0',
'click',
'docker',
'pip',
'PyYAML',
Expand Down
10 changes: 9 additions & 1 deletion shub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pip
import requests
import yaml
from click import ParamType

# https://github.com/scrapinghub/shub/pull/309#pullrequestreview-113977920
try:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
13 changes: 7 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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'}}
)
Expand All @@ -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()
Expand All @@ -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 = """\
Expand Down Expand Up @@ -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 = {
Expand Down
7 changes: 4 additions & 3 deletions tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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")

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_migrate_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down
10 changes: 7 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit aea38d7

Please sign in to comment.