Skip to content

Commit

Permalink
Fix Travis integration, set up tox and pre-commit
Browse files Browse the repository at this point in the history
Merge pull request #188 from jnak/travis-tox
  • Loading branch information
jnak authored Mar 29, 2019
2 parents d00d9a0 + 3106c6e commit 8a2f020
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 65 deletions.
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default_language_version:
python: python3.7
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: c8bad492e1b1d65d9126dba3fe3bd49a5a52b9d6 # v2.1.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
# TDOO Enable in separate PR
# - id: end-of-file-fixer
# exclude: ^docs/.*$
# - id: trailing-whitespace
# exclude: README.md
# - repo: git://github.com/PyCQA/flake8
# rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7
# hooks:
# - id: flake8
77 changes: 41 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
- 3.6
before_install:
install:
- |
if [ "$TEST_TYPE" = build ]; then
pip install pytest==3.0.2 pytest-cov pytest-benchmark coveralls six mock sqlalchemy_utils
pip install -e .
python setup.py develop
elif [ "$TEST_TYPE" = lint ]; then
pip install flake8
fi
script:
- |
if [ "$TEST_TYPE" = lint ]; then
echo "Checking Python code lint."
flake8 graphene_sqlalchemy
exit
elif [ "$TEST_TYPE" = build ]; then
py.test --cov=graphene_sqlalchemy graphene_sqlalchemy examples
fi
after_success:
- |
if [ "$TEST_TYPE" = build ]; then
coveralls
fi
env:
matrix:
- TEST_TYPE=build
matrix:
fast_finish: true
include:
- python: '2.7'
env: TEST_TYPE=lint
# Python 2.7
# TODO Fix enum and add back tests for py27
# See https://github.com/graphql-python/graphene-sqlalchemy/pull/177
# - env: TOXENV=py27
# python: 2.7
# Python 3.5
- env: TOXENV=py34
python: 3.4
# Python 3.5
- env: TOXENV=py35
python: 3.5
# Python 3.6
- env: TOXENV=py36
python: 3.6
# Python 3.7
- env: TOXENV=py37
python: 3.7
dist: xenial
# SQLAlchemy 1.1
- env: TOXENV=py37-sql11
python: 3.7
dist: xenial
# SQLAlchemy 1.2
- env: TOXENV=py37-sql12
python: 3.7
dist: xenial
# SQLAlchemy 1.3
- env: TOXENV=py37-sql13
python: 3.7
dist: xenial
# Pre-commit
- env: TOXENV=pre-commit
python: 3.7
dist: xenial
install: pip install .[dev]
script: tox
after_success: coveralls
cache:
directories:
- $HOME/.cache/pip
- $HOME/.cache/pre-commit
deploy:
provider: pypi
user: syrusakbary
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,24 @@ To learn more check out the following [examples](examples/):

## Contributing

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

```sh
python setup.py install
pip install -e ".[dev]"
pre-commit install
```

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

```sh
python setup.py test # Use --pytest-args="-v -s" for verbose mode
tox -e py37 # Python 3.7, SQLAlchemy < 2.0
tox -e py37 -- -v -s # Verbose output
tox -e py37 -- -k test_query # Only test_query.py
```

Our linters will run automatically when committing via git hooks but you can also run them manually:

```sh
tox -e pre-commit
```
21 changes: 1 addition & 20 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,9 @@
exclude = setup.py,docs/*,examples/*,tests
max-line-length = 120

[coverage:run]
omit = */tests/*

# TODO Add isort as a pre-commit hook
[isort]
known_first_party=graphene,graphene_sqlalchemy

[tool:pytest]
testpaths = graphene_sqlalchemy/
addopts =
-s
; --cov graphene-sqlalchemy
norecursedirs =
__pycache__
*.egg-info
.cache
.git
.tox
appdir
docs
filterwarnings =
error
ignore::DeprecationWarning

[bdist_wheel]
universal=1
26 changes: 21 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1))
)

tests_require = [
"pytest==4.3.1",
"mock==2.0.0",
"pytest-cov==2.6.1",
"sqlalchemy_utils==0.33.9",
]

setup(
name="graphene-sqlalchemy",
Expand Down Expand Up @@ -37,10 +43,20 @@
keywords="api graphql protocol rest relay graphene",
packages=find_packages(exclude=["tests"]),
install_requires=[
"six>=1.10.0",
"graphene>=2.1.3",
"SQLAlchemy",
"singledispatch>=3.4.0.3",
# To keep things simple, we only support newer versions of Graphene
"graphene>=2.1.3,<3",
# Tests fail with 1.0.19
"SQLAlchemy>=1.1,<2",
"six>=1.10.0,<2",
"singledispatch>=3.4.0.3,<4",
],
tests_require=["pytest>=2.7.2", "mock", "sqlalchemy_utils"],
extras_require={
"dev": [
"tox==3.7.0", # Should be kept in sync with tox.ini
"coveralls==1.7.0",
"pre-commit==1.14.4",
],
"test": tests_require,
},
tests_require=tests_require,
)
20 changes: 20 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tox]
envlist = pre-commit,py{34,35,36,37}-sql{11,12,13}
skipsdist = true
minversion = 3.7.0

[testenv]
deps =
.[test]
sql11: sqlalchemy>=1.1,<1.2
sql12: sqlalchemy>=1.2,<1.3
sql13: sqlalchemy>=1.3,<1.4
commands =
pytest graphene_sqlalchemy --cov=graphene_sqlalchemy {posargs}

[testenv:pre-commit]
basepython=python3.7
deps =
.[dev]
commands =
pre-commit {posargs:run --all-files}

0 comments on commit 8a2f020

Please sign in to comment.