Skip to content

Update Tox, Add MyPy, .pre-commit configurations #18

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

Closed
wants to merge 13 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = */tests/*
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,rst,ini}]
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
known_third_party = aniso8601,graphql,graphql_relay,promise,pytest,pytz,pyutils,setuptools,six,snapshottest,sphinx_graphene_theme
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: check-merge-conflict
- id: check-json
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: ^docs/.*$
- id: pretty-format-json
args:
- --autofix
- id: trailing-whitespace
exclude: README.md
- repo: https://github.com/asottile/pyupgrade
rev: v1.12.0
hooks:
- id: pyupgrade
- repo: https://github.com/ambv/black
rev: 18.9b0
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 3.7.7
hooks:
- id: flake8
exclude: tests/schema.py
43 changes: 24 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
language: python
sudo: false
matrix:
include:
- python: pypy
env: TOX_ENV=pypy
- python: '2.7'
env: TOX_ENV=py27
- python: '3.4'
env: TOX_ENV=py34
- python: '3.5'
env: TOX_ENV=py35
- python: '3.6'
env: TOX_ENV=py36,import-order,flake8,mypy
- env: TOXENV=py27
python: 2.7
- env: TOXENV=py34
python: 3.4
- env: TOXENV=py35
python: 3.5
- env: TOXENV=py36
python: 3.6
- env: TOXENV=py37
python: 3.7
dist: xenial
sudo: true
- env: TOXENV=pypy
python: pypy-5.7.1
- env: TOXENV=pre-commit
python: 3.6
- env: TOXENV=mypy
python: 3.6
install:
- pip install coveralls tox
script: tox
after_success: coveralls
cache:
directories:
- $HOME/.cache/pip
- $TRAVIS_BUILD_DIR/.tox
install:
- pip install tox coveralls
script:
- tox -e $TOX_ENV -- --cov=graphql_server
after_success:
- coveralls
- $HOME/.cache/pip
- $HOME/.cache/pre-commit
deploy:
provider: pypi
user: syrusakbary
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
5 changes: 5 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]
ignore_missing_imports = True

[mypy-tests.*]
ignore_errors = True
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ max-line-length = 160
[isort]
known_first_party=graphql_server

[pytest]
norecursedirs = venv .tox .cache
[coverage:run]
omit = */tests/*

[bdist_wheel]
universal=1
18 changes: 16 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
from setuptools import setup, find_packages

required_packages = ["graphql-core>=2.1", "promise"]
tests_require = [
"pytest",
"pytest-benchmark",
"pytest-cov",
"pytest-mock",
"snapshottest",

Choose a reason for hiding this comment

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

are all of these really required to run tests? In the before diff there was only pytest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not all of them, but we weren't running coverage before. (coverage is at 66pct with the current config, which seems low for a graphql python lib)

"coveralls",
"promise",
"six",
"mock",
"pytz",
"iso8601",
]

setup(
name="graphql-server-core",
Expand All @@ -22,13 +35,14 @@
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: Implementation :: PyPy",
"License :: OSI Approved :: MIT License",
],
keywords="api graphql protocol rest",
keywords="api graphql protocol rest python graphene",
packages=find_packages(exclude=["tests"]),
install_requires=required_packages,
tests_require=["pytest>=2.7.3"],
tests_require=tests_require,
include_package_data=True,
zip_safe=False,
platforms="any",
Expand Down
43 changes: 23 additions & 20 deletions tests/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType
from graphql.type.definition import (
GraphQLArgument,
GraphQLField,
GraphQLNonNull,
GraphQLObjectType,
)
from graphql.type.scalars import GraphQLString
from graphql.type.schema import GraphQLSchema

Expand All @@ -8,31 +13,29 @@ def resolve_raises(*_):


QueryRootType = GraphQLObjectType(
name='QueryRoot',
name="QueryRoot",
fields={
'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
'request': GraphQLField(GraphQLNonNull(GraphQLString),
resolver=lambda obj, info: context.args.get('q')),
'context': GraphQLField(GraphQLNonNull(GraphQLString),
resolver=lambda obj, info: context),
'test': GraphQLField(
"thrower": GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
"request": GraphQLField(
GraphQLNonNull(GraphQLString),
resolver=lambda obj, info: context.args.get("q"),
), # noqa: F821
"context": GraphQLField(
GraphQLNonNull(GraphQLString), resolver=lambda obj, info: context
), # noqa
"test": GraphQLField(
type=GraphQLString,
args={
'who': GraphQLArgument(GraphQLString)
},
resolver=lambda obj, info, who='World': 'Hello %s' % who
)
}
args={"who": GraphQLArgument(GraphQLString)},
resolver=lambda obj, info, who="World": "Hello %s" % who,
),
},
)

MutationRootType = GraphQLObjectType(
name='MutationRoot',
name="MutationRoot",
fields={
'writeTest': GraphQLField(
type=QueryRootType,
resolver=lambda *_: QueryRootType
)
}
"writeTest": GraphQLField(type=QueryRootType, resolver=lambda *_: QueryRootType)
},
)

schema = GraphQLSchema(QueryRootType, MutationRootType)
Loading