diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a710a5ff --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/.travis.yml b/.travis.yml index dd80108a..33704975 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 91a5349f..2effbe3b 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/setup.cfg b/setup.cfg index d8d54e3f..4e863d7a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py index 7a6941b8..cfbae111 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -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, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..b6b6ab1c --- /dev/null +++ b/tox.ini @@ -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}