Skip to content

Commit

Permalink
Update dependencies, add nox-poetry (#294)
Browse files Browse the repository at this point in the history
* Update dependencies, add nox-poetry

* Rebase, fix tests

* Update pre-commit

* Add wheel package for windows tests
  • Loading branch information
KundaPanda authored May 3, 2022
1 parent cbc0f1a commit 63f8de0
Show file tree
Hide file tree
Showing 8 changed files with 658 additions and 949 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pip==22.0.3
pip==22.0.4
nox==2022.1.7
poetry==1.1.13
virtualenv==20.13.1
virtualenv==20.14.1
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
uses: actions/checkout@v3.0.2

- name: Run Labeler
uses: crazy-max/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
uses: actions/checkout@v3.0.2
with:
fetch-depth: 2

- name: Set up Python
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v3.1.2
with:
python-version: "3.9"

Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
pypi_token: ${{ secrets.PYPI_TOKEN }}

- name: Publish the release notes
uses: release-drafter/release-drafter@v5.18.1
uses: release-drafter/release-drafter@v5.19.0
with:
publish: ${{ steps.check-version.outputs.tag != '' }}
tag: ${{ steps.check-version.outputs.tag }}
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,27 @@ jobs:
restore-keys: |
${{ runner.os }}-nox-
- name: Check out the repository
uses: actions/checkout@v2.4.0
uses: actions/checkout@v3.0.2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v3.1.2
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Wheel
run: |
pip install --constraint=.github/workflows/constraints.txt wheel
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
- name: Install Nox and nox-poetry
run: |
pip install --constraint=.github/workflows/constraints.txt nox
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Install strawberry-django-jwt
run: |
Expand Down Expand Up @@ -87,7 +90,7 @@ jobs:
nox --force-color --python=${{ matrix.python-version }}
- name: Upload coverage data
if: always() && startsWith(matrix.session, 'tests')
uses: "actions/upload-artifact@v2.3.1"
uses: actions/upload-artifact@v3.0.0
with:
name: coverage-data
path: ".coverage.*"
Expand All @@ -97,7 +100,7 @@ jobs:
needs: tests
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
uses: actions/checkout@v3.0.2

- name: Set up Python 3.9
uses: actions/[email protected]
Expand All @@ -108,19 +111,22 @@ jobs:
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Wheel
run: |
pip install --constraint=.github/workflows/constraints.txt wheel
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
- name: Install Nox and nox-poetry
run: |
pip install --constraint=.github/workflows/constraints.txt nox
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Install strawberry-django-jwt
run: |
pip install .
- name: Download coverage data
uses: actions/download-artifact@v2.1.0
uses: actions/download-artifact@v3.0.0
with:
name: coverage-data

Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/ambv/black
rev: "21.6b0"
rev: "22.3.0"
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/pycqa/flake8
rev: "3.9.2"
rev: "4.0.1"
hooks:
- id: flake8
- repo: local
Expand Down Expand Up @@ -36,7 +36,7 @@ repos:
language: system
types: [text]
stages: [commit, push, manual]
- repo: https://github.com/prettier/pre-commit
rev: 57f39166b5a5a504d6808b87ab98d41ebf095b46
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
hooks:
- id: prettier
104 changes: 38 additions & 66 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from textwrap import dedent

import nox
from nox import Session
from nox import session
from nox_poetry import Session, session
from nox_poetry.core import Session_install

package = "strawberry_django_jwt"
python_versions = ["3.10", "3.9", "3.8", "3.7"]
Expand All @@ -13,7 +13,7 @@
("3.7", "4.0"),
("3.10", "3.1"),
]
pyjwt_versions = ["1.7.1", "2.1.0"]
pyjwt_versions = ["1.7.1", "latest"]
strawberry_graphql_versions = ["0.69.0", "latest"]
nox.needs_version = ">= 2021.6.6"
nox.options.sessions = ("tests",)
Expand Down Expand Up @@ -69,6 +69,23 @@ def activate_virtualenv_in_precommit_hooks(session_: Session) -> None:
hook.write_text("\n".join(lines))


def install(session_, package_, version):
if version == "latest":
Session_install(session_, package, "-U")
else:
Session_install(session_, f"{package_}=={version}")


# noinspection PyUnresolvedReferences,PyProtectedMember
def export_requirements_without_extras(session_: Session) -> Path:
"""Ugly workaround to install only certain dev dependencies without extras"""
extras = session_.poetry.poetry.config._config.get("extras", {}) # type: ignore
session_.poetry.poetry.config._config["extras"] = {} # type: ignore
requirements = session_.poetry.export_requirements()
session_.poetry.poetry.config._config["extras"] = extras # type: ignore
return requirements


@session(name="pre-commit", python="3.9")
def pre_commit(session_: Session) -> None:
"""Lint using pre-commit."""
Expand All @@ -88,34 +105,17 @@ def pre_commit(session_: Session) -> None:
@session(python="3.9")
def safety(session_: Session) -> None:
"""Scan dependencies for insecure packages."""
requirements = Path("requirements.txt")
session_.run(
"poetry",
"export",
f"-o{requirements}",
"--dev",
"--without-hashes",
external=True,
)
session_.install(f"-r{requirements}")
requirements = session_.poetry.export_requirements()
session_.install("safety")
session_.run("safety", "check", "--full-report", f"--file={requirements}")
requirements.unlink()


@session(python="3.9")
def mypy(session_: Session) -> None:
"""Type-check using mypy."""
args = session_.posargs or ["strawberry_django_jwt", "tests"]
requirements = Path("requirements.txt")
session_.run(
"poetry",
"export",
f"-o{requirements}",
"--dev",
"--without-hashes",
external=True,
)
session_.install(f"-r{requirements}")
requirements = export_requirements_without_extras(session_)
session_.install("-r", str(requirements))
session_.run("mypy", *args)
if not session_.posargs:
session_.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
Expand All @@ -127,19 +127,10 @@ def tests(session_: Session, django: str) -> None:
"""Run the test suite."""
if (session_.python, django) in invalid_sessions:
session_.skip()
requirements = Path("requirements.txt")
session_.run(
"poetry",
"export",
f"-o{requirements}",
"--dev",
"--without-hashes",
external=True,
)
session_.install(f"-r{requirements}")
session_.install(f"django=={django}")
session_.run("python", "-m", "pytest")
requirements.unlink()
session_.install(".")
requirements = export_requirements_without_extras(session_)
session_.install("-r", str(requirements))
install(session_, "django", django)

try:
session_.run("coverage", "run", "--parallel", "-m", "pytest", *session_.posargs)
Expand All @@ -151,19 +142,10 @@ def tests(session_: Session, django: str) -> None:
@session(python="3.9")
@nox.parametrize("pyjwt", pyjwt_versions)
def tests_pyjwt(session_: Session, pyjwt: str) -> None:
requirements = Path("requirements.txt")
session_.run(
"poetry",
"export",
f"-o{requirements}",
"--dev",
"--without-hashes",
external=True,
)
session_.install(f"-r{requirements}")
session_.install(f"pyjwt=={pyjwt}")
session_.run("python", "-m", "pytest")
requirements.unlink()
session_.install(".")
requirements = export_requirements_without_extras(session_)
session_.install("-r", str(requirements))
install(session_, "pyjwt", pyjwt)

try:
session_.run("coverage", "run", "--parallel", "-m", "pytest", *session_.posargs)
Expand All @@ -175,22 +157,12 @@ def tests_pyjwt(session_: Session, pyjwt: str) -> None:
@session(python="3.9")
@nox.parametrize("strawberry", strawberry_graphql_versions)
def tests_strawberry_graphql(session_: Session, strawberry: str) -> None:
requirements = Path("requirements.txt")
session_.run(
"poetry",
"export",
f"-o{requirements}",
"--dev",
"--without-hashes",
external=True,
)
session_.install(f"-r{requirements}")
if strawberry == "latest":
session_.install("strawberry-graphql", "-U")
else:
session_.install(f"strawberry-graphql=={strawberry}")
session_.run("python", "-m", "pytest")
requirements.unlink()
session_.install(".")
requirements = export_requirements_without_extras(session_)
session_.install("-r", str(requirements))
install(session_, "strawberry-graphql", strawberry)
if strawberry == "0.69.0":
install(session_, "graphql-core", "3.1.7")

try:
session_.run("coverage", "run", "--parallel", "-m", "pytest", *session_.posargs)
Expand Down
Loading

0 comments on commit 63f8de0

Please sign in to comment.