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

Pin to jsonschema<4 and update config for testing on recent Python versions #385

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: '{build}'
image: Visual Studio 2017
image: Visual Studio 2019

environment:
matrix:
Expand All @@ -10,6 +10,10 @@ environment:
TOXENV: py36
- PYTHON: C:\Python37-x64
TOXENV: py37
- PYTHON: C:\Python38-x64
TOXENV: py38
- PYTHON: C:\Python39-x64
TOXENV: py39

build: off

Expand Down
26 changes: 22 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
name: build
on: push
jobs:
pytest:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pytest:
tests:

runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
python-version:
- '2.7'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: pip install tox
- run: |
tox -e py$(tr -d "." <<<"${{ matrix.python-version }}")
Comment on lines +19 to +24
Copy link
Author

Choose a reason for hiding this comment

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

This will properly install and then test with the right Python versions

Copy link
Collaborator

@macisamuele macisamuele Oct 27, 2021

Choose a reason for hiding this comment

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

Small tip: You could install tox-gh-actions to let the system call the correct tox environment. This will avoid as well the usage of shell-expansions which might be different if tests are run on different OS[1].

You can see it in use in macisamuele/language-formatters-pre-commit-hooks
Example of run here

[1] Actually github actions does support running tests on MacOs and Windows, so it might be nice to centralise testing CI into a single provider (instead of depending on appveyor)


tox:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
tox:
- py27
- py36
- py37
- pre-commit
- mypy
- docs
Expand All @@ -19,6 +37,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: '3.9'
- run: pip install tox
- run: tox -e ${{ matrix.tox }}
4 changes: 2 additions & 2 deletions bravado_core/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def wrapper(value):
return value
return func(value)

return wrapper
return wrapper # type: ignore
Copy link
Author

Choose a reason for hiding this comment

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

Sadly the flak8 installed by pre-commit in Python2 does not support specifically ignoring types. This was # type: ignore[return-value] since wrapper is a callable but it's not being coerced to FuncType by mypy even though it should be equivalent (there's probably something more specific that's going on, but it's not particularly obvious).


return external_wrapper

Expand Down Expand Up @@ -82,4 +82,4 @@ def wrapper(*args, **kwargs):
except RecursiveCallException:
return lambda *new_args, **new_kawrgs: func(*args, **kwargs)(*new_args, **new_kawrgs)

return wrapper
return wrapper # type: ignore
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ warn_redundant_casts = True
disallow_untyped_calls = True
check_untyped_defs = True
disallow_untyped_defs = True
pretty = True
show_error_codes = True
show_error_context = True

# # This is needed to allow gradual typing of the library
# # Remove the exceptions defined below once the module is completely typed
Expand Down
4 changes: 1 addition & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Unit test dependencies
mock
mypy-extensions; python_version>='3.5'
mypy; python_version>='3.5'
pre-commit
pytest
pytest-benchmark[histogram]
pytest-cov
pytest<4.7 # need support for Python 2.7, see https://docs.pytest.org/en/latest/py27-py34-deprecation.html
Copy link
Author

Choose a reason for hiding this comment

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

This breaks for Python 3.10 will automatically be handled by pip for Python 2.7. Mypy however needs pytest<6 but that and the other mypy specific packages have been moved to requirements-typing.txt

14 changes: 14 additions & 0 deletions requirements-typing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# mypy dependencies
mypy-extensions
mypy[python2]
# Restrict pytest to a version which does not publish types which are
# in Python3 format and will break on Python2.
pytest<6
types-enum34
# Restrict types-mock to a version which supports Python2
types-mock==0.1.5
types-python-dateutil
types-pytz
types-PyYAML
types-simplejson
types-six
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

install_requires = [
"jsonref",
"jsonschema[format]>=2.5.1",
"jsonschema[format]>=2.5.1,<4.0.0",
Copy link
Author

Choose a reason for hiding this comment

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

The original point of this PR 😅

"python-dateutil",
"pyyaml",
"simplejson",
Expand Down Expand Up @@ -49,6 +49,9 @@
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
install_requires=install_requires,
package_data={
Expand Down
13 changes: 9 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import simplejson as json
import yaml
from mock import Mock
from six import binary_type
from six import iteritems
from six import iterkeys
from six import text_type
from six.moves.urllib import parse as urlparse
from six.moves.urllib.request import pathname2url
from six.moves.urllib.request import url2pathname
Expand Down Expand Up @@ -302,12 +304,15 @@ def check_object_deepcopy(obj):
)
if id(getattr(obj, attr_name, None)) == id(getattr(obj_copy, attr_name, None))
}
assert not any(
# This is an `any` check, but it will save the offending values and allow pytest to report them
immutable_types = (type(None), bool, binary_type, text_type, tuple)
assert not {
attr_name: (attr_value, type(attr_value))
for attr_name, attr_value in iteritems(attributes_with_same_id)
# If `attr_name: attr_value` is in attributes_with_same_id then attr_value id did not change
# after deepcopy. As immutable types do not create new instances for deepcopy we need to ensure
# that all the occurrences of "same-id" are related to immutable types.
not isinstance(attr_value, (type(None), str, tuple))
for attr_name, attr_value in iteritems(attributes_with_same_id)
)
if not isinstance(attr_value, immutable_types)
}

return obj_copy
11 changes: 7 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ filterwarnings =
ignore:.*will be deprecated in the next major release. Please use the more general entry-point offered in.*:DeprecationWarning

[tox]
envlist = py27, py36, py37, mypy, pre-commit
envlist = py27, py3{6,7,8,9,10}, mypy, pre-commit

[testenv]
deps =
Expand All @@ -12,7 +12,7 @@ commands =
python -m pytest --cov --capture=no --benchmark-skip {posargs:tests}

[testenv:benchmark]
basepython = python3.7
basepython = python3.9
deps =
-rrequirements-dev.txt
commands =
Expand All @@ -23,9 +23,12 @@ commands =
--benchmark-histogram=.benchmarks/benchmark

[testenv:mypy]
basepython = python3.7
basepython = python3.9
deps =
-rrequirements-dev.txt
-rrequirements-typing.txt
commands =
mypy bravado_core tests
mypy bravado_core tests {posargs}

[testenv:docs]
deps =
Expand Down