From 46bb1202e497b4b5db7e91f2916f45bb22cebb1f Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Fri, 16 Jul 2021 16:56:15 +0100 Subject: [PATCH] Add github actions to run linting and tests (#1349) --- .github/workflows/deploy.yml | 26 ++++++++++++++++++ .github/workflows/lint.yml | 26 ++++++++++++++++++ .github/workflows/tests.yml | 26 ++++++++++++++++++ .pre-commit-config.yaml | 4 +-- graphene/relay/tests/test_connection_query.py | 6 ++--- graphene/types/mutation.py | 2 +- graphene/types/tests/test_query.py | 2 +- setup.py | 3 +++ tests_asyncio/test_relay_connection.py | 6 ++--- tox.ini | 27 +++++++++++-------- 10 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..07c0766f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,26 @@ +name: 🚀 Deploy to PyPI + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Build wheel and source tarball + run: | + pip install wheel + python setup.py sdist bdist_wheel + - name: Publish a Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@v1.1.0 + with: + user: __token__ + password: ${{ secrets.pypi_password }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..a137a617 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,26 @@ +name: Lint + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + - name: Run lint 💅 + run: tox + env: + TOXENV: pre-commit + - name: Run mypy + run: tox + env: + TOXENV: mypy diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..5d2973ce --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,26 @@ +name: Tests + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: ["2.7", "3.6", "3.7", "3.8", "3.9"] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox tox-gh-actions + - name: Test with tox + run: tox + env: + TOXENV: ${{ matrix.toxenv }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 93ab2e6d..d49badef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,11 +18,11 @@ repos: hooks: - id: pyupgrade - repo: https://github.com/ambv/black - rev: 18.9b0 + rev: 21.6b0 hooks: - id: black language_version: python3 - repo: https://github.com/PyCQA/flake8 - rev: 3.7.7 + rev: 3.9.2 hooks: - id: flake8 diff --git a/graphene/relay/tests/test_connection_query.py b/graphene/relay/tests/test_connection_query.py index be6ee8c7..2e7a1531 100644 --- a/graphene/relay/tests/test_connection_query.py +++ b/graphene/relay/tests/test_connection_query.py @@ -54,10 +54,10 @@ for i, letter in enumerate(letter_chars): def edges(selected_letters): return [ { - "node": {"id": base64("Letter:%s" % l.id), "letter": l.letter}, - "cursor": base64("arrayconnection:%s" % l.id), + "node": {"id": base64("Letter:%s" % letter.id), "letter": letter.letter}, + "cursor": base64("arrayconnection:%s" % letter.id), } - for l in [letters[i] for i in selected_letters] + for letter in [letters[i] for i in selected_letters] ] diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index c96162e4..31c32284 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -135,7 +135,7 @@ class Mutation(ObjectType): def Field( cls, name=None, description=None, deprecation_reason=None, required=False ): - """ Mount instance of mutation Field. """ + """Mount instance of mutation Field.""" return Field( cls._meta.output, args=cls._meta.arguments, diff --git a/graphene/types/tests/test_query.py b/graphene/types/tests/test_query.py index 8681e462..0885e22b 100644 --- a/graphene/types/tests/test_query.py +++ b/graphene/types/tests/test_query.py @@ -399,7 +399,7 @@ def test_big_list_of_containers_multiple_fields_query_benchmark(benchmark): def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark( - benchmark + benchmark, ): class Container(ObjectType): x = Int() diff --git a/setup.py b/setup.py index 75d92f79..e6e650ea 100644 --- a/setup.py +++ b/setup.py @@ -49,6 +49,9 @@ tests_require = [ "pytest-benchmark", "pytest-cov", "pytest-mock", + # pinning fastdiff dep (required by snapshottest) because later versions + # require wasmer 1.0.0 which is not compatible with Python 2.7 + "fastdiff==0.2.0", "snapshottest", "coveralls", "promise", diff --git a/tests_asyncio/test_relay_connection.py b/tests_asyncio/test_relay_connection.py index ec86fef6..edac6fc9 100644 --- a/tests_asyncio/test_relay_connection.py +++ b/tests_asyncio/test_relay_connection.py @@ -56,10 +56,10 @@ for i, letter in enumerate(letter_chars): def edges(selected_letters): return [ { - "node": {"id": base64("Letter:%s" % l.id), "letter": l.letter}, - "cursor": base64("arrayconnection:%s" % l.id), + "node": {"id": base64("Letter:%s" % letter.id), "letter": letter.letter}, + "cursor": base64("arrayconnection:%s" % letter.id), } - for l in [letters[i] for i in selected_letters] + for letter in [letters[i] for i in selected_letters] ] diff --git a/tox.ini b/tox.ini index a519cb1e..4e1cc9dc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,20 +1,27 @@ [tox] -envlist = flake8,py27,py34,py35,py36,py37,pre-commit,pypy,mypy -skipsdist = true +envlist = py{27,36,37,38,39},flake8,pre-commit,mypy + +[gh-actions] +python = + 2.7: py27 + 3.6: py36 + 3.7: py37 + 3.8: py38 + 3.9: py39 [testenv] +passenv = * +usedevelop = True deps = - .[test] - py{35,36,37}: pytest-asyncio + -e.[test] + py{36,37,38,39}: pytest-asyncio setenv = PYTHONPATH = .:{envdir} commands = - py{27,py}: py.test --cov=graphene graphene examples {posargs} - py{35}: py.test --cov=graphene graphene examples tests_asyncio {posargs} - py{36,37}: py.test --cov=graphene graphene examples tests_asyncio tests_py36 {posargs} + py{27}: py.test --cov=graphene graphene examples {posargs} + py{36,37,38,39}: py.test --cov=graphene graphene examples tests_asyncio tests_py36 {posargs} [testenv:pre-commit] -basepython=python3.7 deps = pre-commit>0.12.0 setenv = @@ -23,9 +30,9 @@ commands = pre-commit {posargs:run --all-files} [testenv:mypy] -basepython=python3.7 deps = mypy + types-six commands = mypy graphene @@ -34,5 +41,3 @@ deps = flake8 commands = pip install -e . flake8 graphene - -[pytest]