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

Allow click versions other than 7.0 #416

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -76,7 +112,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install tox
run: pip install tox
run: tox -e ${{ matrix.tox-env }}

- name: Run tests
run: tox -e py
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
17 changes: 16 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,20 @@ def _update_conf_file(filename, target, project, repository):
click.echo("Saved to %s." % filename)


class _BooleanOrStringParamType(ParamType):

def convert(self, value, param, ctx):
if isinstance(value, bool):
return value
value = str(value)
lowercase_value = value.lower()
if lowercase_value == 'true':
return True
if lowercase_value == 'false':
return False
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 +845,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=_BooleanOrStringParamType())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was failing since click 8.0.1, specifically since pallets/click@ad52b19, which due to default=True was converting string inputs to True as well.

_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
Comment on lines +13 to +16
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate Tox environment to test those “minimum” versions of dependencies, while keeping the rest of the Tox environments testing the latest versions of dependencies.


[testenv:freeze]
install_command =
Expand Down