Skip to content

Commit 8b00a98

Browse files
authored
Merge pull request #35 from KingDarBoja/chore-refactoring
Contributing docs and refactor dev packages
2 parents ad392b5 + 3e8545f commit 8b00a98

12 files changed

+191
-67
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.pytest_cache
1212
.tox
1313
.venv
14+
.vscode
1415

1516
/build/
1617
/dist/

.travis.yml

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
language: python
2+
sudo: false
3+
python:
4+
- 2.7
5+
- 3.5
6+
- 3.6
7+
- 3.7
8+
- 3.8
9+
- 3.9-dev
10+
- pypy
11+
- pypy3
212
matrix:
313
include:
4-
- python: "3.7"
5-
env: TOX_ENV=black,flake8,mypy,py37
6-
- python: "3.6"
7-
env: TOX_ENV=py36
8-
- python: "3.5"
9-
env: TOX_ENV=py35
10-
- python: "2.7"
11-
env: TOX_ENV=py27
12-
- python: pypy3
13-
env: TOX_ENV=pypy3
14-
- python: pypy
15-
env: TOX_ENV=pypy
16-
cache:
17-
directories:
18-
- "$HOME/.cache/pip"
19-
- "$TRAVIS_BUILD_DIR/.tox"
20-
install:
21-
- pip install tox codecov
22-
script:
23-
- tox -e $TOX_ENV -- --cov-report term-missing --cov=graphql_server
24-
after_success:
25-
- codecov
14+
- python: 3.6
15+
env: TOXENV=flake8,black,import-order,mypy,manifest
16+
cache: pip
17+
install: pip install tox-travis codecov
18+
script: tox
19+
after_success: codecov
2620
deploy:
2721
provider: pypi
2822
on:

CONTRIBUTING.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Contributing
2+
3+
Thanks for helping to make graphql-server-core awesome!
4+
5+
We welcome all kinds of contributions:
6+
7+
- Bug fixes
8+
- Documentation improvements
9+
- New features
10+
- Refactoring & tidying
11+
12+
13+
## Getting started
14+
15+
If you have a specific contribution in mind, be sure to check the [issues](https://github.com/graphql-python/graphql-server-core/issues) and [pull requests](https://github.com/graphql-python/graphql-server-core/pulls) in progress - someone could already be working on something similar and you can help out.
16+
17+
18+
## Project setup
19+
20+
### Development with virtualenv (recommended)
21+
22+
After cloning this repo, create a virtualenv:
23+
24+
```console
25+
virtualenv graphql-server-core-dev
26+
```
27+
28+
Activate the virtualenv and install dependencies by running:
29+
30+
```console
31+
python pip install -e ".[test]"
32+
```
33+
34+
If you are using Linux or MacOS, you can make use of Makefile command
35+
`make dev-setup`, which is a shortcut for the above python command.
36+
37+
### Development on Conda
38+
39+
You must create a new env (e.g. `graphql-sc-dev`) with the following command:
40+
41+
```sh
42+
conda create -n graphql-sc-dev python=3.8
43+
```
44+
45+
Then activate the environment with `conda activate graphql-sc-dev`.
46+
47+
Proceed to install all dependencies by running:
48+
49+
```console
50+
pip install -e ".[dev]"
51+
```
52+
53+
And you ready to start development!
54+
55+
## Running tests
56+
57+
After developing, the full test suite can be evaluated by running:
58+
59+
```sh
60+
pytest tests --cov=graphql-server-core -vv
61+
```
62+
63+
If you are using Linux or MacOS, you can make use of Makefile command
64+
`make tests`, which is a shortcut for the above python command.
65+
66+
You can also test on several python environments by using tox.
67+
68+
### Running tox on virtualenv
69+
70+
Install tox:
71+
72+
```console
73+
pip install tox
74+
```
75+
76+
Run `tox` on your virtualenv (do not forget to activate it!)
77+
and that's it!
78+
79+
### Running tox on Conda
80+
81+
In order to run `tox` command on conda, install
82+
[tox-conda](https://github.com/tox-dev/tox-conda):
83+
84+
```sh
85+
conda install -c conda-forge tox-conda
86+
```
87+
88+
This install tox underneath so no need to install it before.
89+
90+
Then uncomment the `requires = tox-conda` line on `tox.ini` file.
91+
92+
Run `tox` and you will see all the environments being created
93+
and all passing tests. :rocket:

MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
include MANIFEST.in
2+
13
include README.md
24
include LICENSE
5+
include CONTRIBUTING.md
6+
7+
include codecov.yml
8+
include tox.ini
9+
10+
graft tests
11+
prune bin
12+
13+
global-exclude *.py[co] __pycache__

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ You can also use one of the existing integrations listed above as
4242
blueprint to build your own integration or GraphQL server implementations.
4343

4444
Please let us know when you have built something new, so we can list it here.
45+
46+
## Contributing
47+
See [CONTRIBUTING.md](CONTRIBUTING.md)

graphql_server/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import six
1515

16-
from promise import promisify, is_thenable
16+
from promise import promisify, is_thenable, Promise
1717

1818
from graphql import get_default_backend
1919
from graphql.error import format_error as default_format_error
@@ -266,6 +266,7 @@ def execute_graphql_request(
266266
backend=None, # type: GraphQLBackend
267267
**kwargs # type: Any
268268
):
269+
# type: (...) -> ExecutionResult
269270
"""Execute a GraphQL request and return an ExecutionResult.
270271
271272
You need to pass the GraphQL schema and the GraphQLParams that you can get
@@ -318,18 +319,20 @@ def get_response(
318319
allow_only_query=False, # type: bool
319320
**kwargs # type: Any
320321
):
321-
# type: (...) -> Optional[ExecutionResult]
322+
# type: (...) -> Optional[Union[ExecutionResult, Promise[ExecutionResult]]]
322323
"""Get an individual execution result as response, with option to catch errors.
323324
324325
This does the same as execute_graphql_request() except that you can catch errors
325326
that belong to an exception class that you need to pass as a parameter.
326327
"""
327-
# noinspection PyBroadException
328+
# Note: PyCharm will display a error due to the triple dot being used on Callable.
328329
execute = (
329-
execute_graphql_request_as_promise
330-
if kwargs.get("return_promise", False)
331-
else execute_graphql_request
332-
)
330+
execute_graphql_request
331+
) # type: Callable[..., Union[Promise[ExecutionResult], ExecutionResult]]
332+
if kwargs.get("return_promise", False):
333+
execute = execute_graphql_request_as_promise
334+
335+
# noinspection PyBroadException
333336
try:
334337
execution_result = execute(schema, params, allow_only_query, **kwargs)
335338
except catch_exc:
@@ -350,11 +353,10 @@ def format_execution_result(
350353
"""
351354
status_code = 200
352355

356+
response = None
353357
if execution_result:
354358
if execution_result.invalid:
355359
status_code = 400
356360
response = execution_result.to_dict(format_error=format_error)
357-
else:
358-
response = None
359361

360362
return FormattedResult(response, status_code)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ max-line-length = 88
66
known_first_party=graphql_server
77

88
[tool:pytest]
9-
norecursedirs = venv .venv .tox .git .cache .mypy_cache .pytest_cache
9+
norecursedirs = venv .venv .tox .git .cache .mypy_cache .pytest_cache
1010

1111
[bdist_wheel]
1212
universal=1

setup.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
from setuptools import setup, find_packages
22

3-
required_packages = ["graphql-core>=2.3,<3", "promise>=2.3,<3"]
4-
tests_require = ["pytest==4.6.9", "pytest-cov==2.8.1"]
3+
install_requires = [
4+
"graphql-core>=2.3,<3",
5+
"promise>=2.3,<3",
6+
]
7+
8+
tests_requires = [
9+
"pytest==4.6.9",
10+
"pytest-cov==2.8.1"
11+
]
12+
13+
dev_requires = [
14+
'flake8==3.7.9',
15+
'isort<4.0.0',
16+
'black==19.10b0',
17+
'mypy==0.761',
18+
'check-manifest>=0.40,<1',
19+
] + tests_requires
520

621
setup(
722
name="graphql-server-core",
@@ -30,9 +45,12 @@
3045
],
3146
keywords="api graphql protocol rest",
3247
packages=find_packages(exclude=["tests"]),
33-
install_requires=required_packages,
34-
tests_require=tests_require,
35-
extras_require={"test": tests_require},
48+
install_requires=install_requires,
49+
tests_require=tests_requires,
50+
extras_require={
51+
'test': tests_requires,
52+
'dev': dev_requires,
53+
},
3654
include_package_data=True,
3755
zip_safe=False,
3856
platforms="any",

tests/test_asyncio.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import asyncio
2-
3-
from promise import Promise
4-
51
from graphql.execution.executors.asyncio import AsyncioExecutor
6-
from graphql.type.definition import (
7-
GraphQLField,
8-
GraphQLNonNull,
9-
GraphQLObjectType,
10-
)
2+
from graphql.type.definition import GraphQLField, GraphQLNonNull, GraphQLObjectType
113
from graphql.type.scalars import GraphQLString
124
from graphql.type.schema import GraphQLSchema
5+
from promise import Promise
6+
7+
import asyncio
138
from graphql_server import RequestParams, run_http_query
149

1510
from .utils import as_dicts

tests/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from graphql.error import GraphQLError
44
from graphql.execution import ExecutionResult
55
from graphql.language.location import SourceLocation
6+
from pytest import raises
67

78
from graphql_server import (
89
HttpQueryError,
@@ -12,7 +13,6 @@
1213
json_encode_pretty,
1314
load_json_body,
1415
)
15-
from pytest import raises
1616

1717

1818
def test_json_encode():

tests/test_query.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import json
22

3-
from pytest import raises
4-
5-
from promise import Promise
6-
73
from graphql.error import GraphQLError, GraphQLSyntaxError
84
from graphql.execution import ExecutionResult
5+
from promise import Promise
6+
from pytest import raises
97

108
from graphql_server import (
119
HttpQueryError,

tox.ini

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
[tox]
2-
envlist = black,flake8,mypy,py{38,37,36,35,py27,py3,py}
3-
skipsdist = true
2+
envlist =
3+
black,flake8,import-order,mypy,manifest,
4+
py{27,35,36,37,38,39-dev,py,py3}
5+
; requires = tox-conda
46

57
[testenv]
8+
passenv = *
69
setenv =
710
PYTHONPATH = {toxinidir}
8-
deps =
9-
.[test]
11+
install_command = python -m pip install --ignore-installed {opts} {packages}
12+
deps = -e.[test]
13+
whitelist_externals =
14+
python
1015
commands =
11-
pytest tests {posargs}
16+
pip install -U setuptools
17+
pytest --cov-report=term-missing --cov=graphql_server tests {posargs}
1218

1319
[testenv:black]
14-
basepython=python3.7
15-
deps = black==19.10b0
20+
basepython=python3.6
21+
deps = -e.[dev]
1622
commands =
1723
black --check graphql_server tests
1824

1925
[testenv:flake8]
20-
basepython=python3.7
21-
deps = flake8==3.7.9
26+
basepython=python3.6
27+
deps = -e.[dev]
2228
commands =
2329
flake8 setup.py graphql_server tests
2430

25-
[testenv:isort]
26-
basepython=python3.7
27-
deps =
28-
isort
29-
graphql-core>=2.3,<3
31+
[testenv:import-order]
32+
basepython=python3.6
33+
deps = -e.[dev]
3034
commands =
3135
isort -rc graphql_server/ tests/
3236

3337
[testenv:mypy]
34-
basepython=python3.7
35-
deps = mypy==0.761
38+
basepython=python3.6
39+
deps = -e.[dev]
3640
commands =
3741
mypy graphql_server tests --ignore-missing-imports
3842

43+
[testenv:manifest]
44+
basepython = python3.6
45+
deps = -e.[dev]
46+
commands =
47+
check-manifest -v

0 commit comments

Comments
 (0)