Skip to content

Commit 174ed5f

Browse files
author
Julien Nakache
committed
fix ci, set up tox, set up pre-commit, various cleanups
1 parent d00d9a0 commit 174ed5f

File tree

18 files changed

+131
-81
lines changed

18 files changed

+131
-81
lines changed

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
default_language_version:
2+
python: python3.7
3+
repos:
4+
- repo: git://github.com/pre-commit/pre-commit-hooks
5+
rev: c8bad492e1b1d65d9126dba3fe3bd49a5a52b9d6 # v2.1.0
6+
hooks:
7+
- id: check-merge-conflict
8+
- id: check-yaml
9+
- id: debug-statements
10+
- id: end-of-file-fixer
11+
exclude: ^docs/.*$
12+
# TODO Enable in its own PR
13+
# - id: trailing-whitespace
14+
# exclude: README.md
15+
- repo: git://github.com/PyCQA/flake8
16+
rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7
17+
hooks:
18+
- id: flake8

.travis.yml

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
language: python
2-
sudo: false
3-
python:
4-
- 2.7
5-
- 3.4
6-
- 3.5
7-
- 3.6
8-
before_install:
9-
install:
10-
- |
11-
if [ "$TEST_TYPE" = build ]; then
12-
pip install pytest==3.0.2 pytest-cov pytest-benchmark coveralls six mock sqlalchemy_utils
13-
pip install -e .
14-
python setup.py develop
15-
elif [ "$TEST_TYPE" = lint ]; then
16-
pip install flake8
17-
fi
18-
script:
19-
- |
20-
if [ "$TEST_TYPE" = lint ]; then
21-
echo "Checking Python code lint."
22-
flake8 graphene_sqlalchemy
23-
exit
24-
elif [ "$TEST_TYPE" = build ]; then
25-
py.test --cov=graphene_sqlalchemy graphene_sqlalchemy examples
26-
fi
27-
after_success:
28-
- |
29-
if [ "$TEST_TYPE" = build ]; then
30-
coveralls
31-
fi
32-
env:
33-
matrix:
34-
- TEST_TYPE=build
352
matrix:
36-
fast_finish: true
373
include:
38-
- python: '2.7'
39-
env: TEST_TYPE=lint
4+
# Python 2.7
5+
# TODO Fix enum and add back tests for py27
6+
# See https://github.com/graphql-python/graphene-sqlalchemy/pull/177
7+
# - env: TOXENV=py27
8+
# python: 2.7
9+
# Python 3.5
10+
- env: TOXENV=py34
11+
python: 3.4
12+
# Python 3.5
13+
- env: TOXENV=py35
14+
python: 3.5
15+
# Python 3.6
16+
- env: TOXENV=py36
17+
python: 3.6
18+
# Python 3.7
19+
- env: TOXENV=py37
20+
python: 3.7
21+
dist: xenial
22+
# SQLAlchemy 1.1
23+
- env: TOXENV=py37-sql11
24+
python: 3.7
25+
dist: xenial
26+
# SQLAlchemy 1.2
27+
- env: TOXENV=py37-sql12
28+
python: 3.7
29+
dist: xenial
30+
# SQLAlchemy 1.3
31+
- env: TOXENV=py37-sql13
32+
python: 3.7
33+
dist: xenial
34+
# Pre-commit
35+
- env: TOXENV=pre-commit
36+
python: 3.7
37+
dist: xenial
38+
install: pip install .[dev]
39+
script: tox
40+
after_success: coveralls
41+
cache:
42+
directories:
43+
- $HOME/.cache/pip
44+
- $HOME/.cache/pre-commit
4045
deploy:
4146
provider: pypi
4247
user: syrusakbary

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,24 @@ To learn more check out the following [examples](examples/):
112112

113113
## Contributing
114114

115-
After cloning this repo, ensure dependencies are installed by running:
115+
Set up our development dependencies:
116116

117117
```sh
118-
python setup.py install
118+
pip install -e ".[dev]"
119+
pre-commit install
119120
```
120121

121-
After developing, the full test suite can be evaluated by running:
122+
We use `tox` to test this library against different versions of `python` and `SQLAlchemy`.
123+
While developping locally, it is usually fine to run the tests against the most recent versions:
122124

123125
```sh
124-
python setup.py test # Use --pytest-args="-v -s" for verbose mode
126+
tox -e py37 # Python 3.7, SQLAlchemy < 2.0
127+
tox -e py37 -- -v -s # Verbose output
128+
tox -e py37 -- -k test_query # Only test_query.py
129+
```
130+
131+
Our linters will run automatically when committing via git hooks but you can also run them manually:
132+
133+
```sh
134+
tox -e pre-commit
125135
```

examples/nameko_sqlalchemy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ Now the following command will setup the database, and start the server:
5151

5252
Now head on over to postman and send POST request to:
5353
[http://127.0.0.1:5000/graphql](http://127.0.0.1:5000/graphql)
54-
and run some queries!
54+
and run some queries!

examples/nameko_sqlalchemy/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def parse_body(self,request):
3333
elif content_type in ('application/x-www-form-urlencoded', 'multipart/form-data'):
3434
return request.form
3535

36-
return {}
36+
return {}

examples/nameko_sqlalchemy/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
WEB_SERVER_ADDRESS: '0.0.0.0:5000'
1+
WEB_SERVER_ADDRESS: '0.0.0.0:5000'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
graphene[sqlalchemy]
22
SQLAlchemy==1.0.11
33
nameko
4-
graphql-server-core
4+
graphql-server-core

examples/nameko_sqlalchemy/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
echo "Starting application service server"
33
# Run Service
4-
nameko run --config config.yml service
4+
nameko run --config config.yml service

examples/nameko_sqlalchemy/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class DepartmentService:
88

99
@http('POST', '/graphql')
1010
def query(self, request):
11-
return App().query(request)
11+
return App().query(request)

graphene_sqlalchemy/tests/test_converter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Test(Base):
168168
)
169169

170170
graphene_type = convert_sqlalchemy_column(Test.column)
171-
assert graphene_type.kwargs["required"] == False
171+
assert not graphene_type.kwargs["required"]
172172

173173

174174
def test_should_scalar_list_convert_list():
@@ -343,4 +343,3 @@ def __init__(self, col1, col2):
343343
)
344344

345345
assert "Don't know how to convert the composite field" in str(excinfo.value)
346-

graphene_sqlalchemy/tests/test_query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,3 @@ def makeNodes(nodeList):
555555
assert set(node["node"]["name"] for node in value["edges"]) == set(
556556
node["node"]["name"] for node in expectedNoSort[key]["edges"]
557557
)
558-

graphene_sqlalchemy/tests/test_reflected.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ def test_objecttype_registered():
1818
assert issubclass(Reflected, ObjectType)
1919
assert Reflected._meta.model == ReflectedEditor
2020
assert list(Reflected._meta.fields.keys()) == ["editor_id", "name"]
21-

graphene_sqlalchemy/tests/test_schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ class Meta:
4747
model = Reporter
4848
only_fields = ("id", "email")
4949
assert list(Reporter2._meta.fields.keys()) == ["id", "email"]
50-

graphene_sqlalchemy/tests/test_types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import OrderedDict
22
from graphene import Field, Int, Interface, ObjectType
33
from graphene.relay import Node, is_node, Connection
4-
import six
4+
import six # noqa: F401
55
from promise import Promise
66

77
from ..registry import Registry
@@ -176,7 +176,9 @@ class TestConnection(Connection):
176176
class Meta:
177177
node = ReporterWithCustomOptions
178178

179-
resolver = lambda *args, **kwargs: Promise.resolve([])
179+
def resolver(*args, **kwargs):
180+
return Promise.resolve([])
181+
180182
result = SQLAlchemyConnectionField.connection_resolver(
181183
resolver, TestConnection, ReporterWithCustomOptions, None, None
182184
)

graphene_sqlalchemy/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from collections import OrderedDict
22

3+
import sqlalchemy
34
from sqlalchemy.inspection import inspect as sqlalchemyinspect
45
from sqlalchemy.ext.hybrid import hybrid_property
56
from sqlalchemy.orm.exc import NoResultFound
67

8+
import graphene
79
from graphene import Field # , annotate, ResolveInfo
810
from graphene.relay import Connection, Node
911
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
@@ -80,9 +82,9 @@ def construct_fields(model, registry, only_fields, exclude_fields):
8082

8183

8284
class SQLAlchemyObjectTypeOptions(ObjectTypeOptions):
83-
model = None # type: Model
84-
registry = None # type: Registry
85-
connection = None # type: Type[Connection]
85+
model = None # type: sqlalchemy.Model
86+
registry = None # type: sqlalchemy.Registry
87+
connection = None # type: graphene.Type[Connection]
8688
id = None # type: str
8789

8890

setup.cfg

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,9 @@
22
exclude = setup.py,docs/*,examples/*,tests
33
max-line-length = 120
44

5-
[coverage:run]
6-
omit = */tests/*
7-
5+
# TODO Add isort as a pre-commit hook
86
[isort]
97
known_first_party=graphene,graphene_sqlalchemy
108

11-
[tool:pytest]
12-
testpaths = graphene_sqlalchemy/
13-
addopts =
14-
-s
15-
; --cov graphene-sqlalchemy
16-
norecursedirs =
17-
__pycache__
18-
*.egg-info
19-
.cache
20-
.git
21-
.tox
22-
appdir
23-
docs
24-
filterwarnings =
25-
error
26-
ignore::DeprecationWarning
27-
289
[bdist_wheel]
2910
universal=1

setup.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1))
1111
)
1212

13+
tests_require = [
14+
"pytest==4.3.1",
15+
"mock==2.0.0",
16+
"pytest-cov==2.6.1",
17+
"sqlalchemy_utils==0.33.9",
18+
]
1319

1420
setup(
1521
name="graphene-sqlalchemy",
@@ -37,10 +43,20 @@
3743
keywords="api graphql protocol rest relay graphene",
3844
packages=find_packages(exclude=["tests"]),
3945
install_requires=[
40-
"six>=1.10.0",
41-
"graphene>=2.1.3",
42-
"SQLAlchemy",
43-
"singledispatch>=3.4.0.3",
46+
# To keep things simple, we only support newer versions of Graphene
47+
"graphene>=2.1.3,<3",
48+
# Tests fail with 1.0.19
49+
"SQLAlchemy>=1.1,<2",
50+
"six>=1.10.0,<2",
51+
"singledispatch>=3.4.0.3,<4",
4452
],
45-
tests_require=["pytest>=2.7.2", "mock", "sqlalchemy_utils"],
53+
extras_require={
54+
"dev": [
55+
"tox==3.7.0", # Should be kept in sync with tox.ini
56+
"coveralls==1.7.0",
57+
"pre-commit==1.14.4",
58+
],
59+
"test": tests_require,
60+
},
61+
tests_require=tests_require,
4662
)

tox.ini

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[tox]
2+
envlist = pre-commit,py{34,35,36,37}-sql{11,12,13}
3+
skipsdist = true
4+
minversion = 3.7.0
5+
6+
[testenv]
7+
deps =
8+
.[test]
9+
sql11: sqlalchemy>=1.1,<1.2
10+
sql12: sqlalchemy>=1.2,<1.3
11+
sql13: sqlalchemy>=1.3,<1.4
12+
commands =
13+
pytest graphene_sqlalchemy --cov=graphene_sqlalchemy {posargs}
14+
15+
[testenv:pre-commit]
16+
basepython=python3.7
17+
deps =
18+
.[dev]
19+
commands =
20+
pre-commit {posargs:run --all-files}

0 commit comments

Comments
 (0)