Skip to content

Commit

Permalink
Update to Python 3.10 (FAForever#962)
Browse files Browse the repository at this point in the history
* Update pipenv version

* Update to Python 3.10

* Update hypothesis to latest version
  • Loading branch information
Askaholic authored May 7, 2023
1 parent 43157e8 commit 592c575
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.10'

- name: Install dependencies with pipenv
run: |
pip install pipenv
pip install pipenv==2023.4.20
pipenv sync
pipenv run pip install pdoc3
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.10'

- name: Install dependencies
run: pip install isort
Expand All @@ -30,6 +30,11 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- uses: TrueBrain/actions-flake8@v2
with:
flake8_version: 6.0.0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.10'

- name: Run flyway db migrations
env:
Expand All @@ -81,7 +81,7 @@ jobs:

- name: Install dependencies with pipenv
run: |
pip install pipenv
pip install pipenv==2023.4.20
pipenv sync --dev
pipenv run pip install pytest-github-actions-annotate-failures
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project to build on Windows using the WSL.*
You will need the following software installed on your system:
- [Docker](https://docs.docker.com/engine/)
- [Docker Compose](https://github.com/docker/compose)
- [Python 3.9](https://www.python.org/downloads/)
- [Python 3.10](https://www.python.org/downloads/)
- [Pipenv](https://github.com/pypa/pipenv/)

Once you have Docker installed, make sure to add yourself to the `docker` group
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
###############
# Build image #
###############
FROM python:3.9-slim as builder
FROM python:3.10-slim as builder

# Need git for installing aiomysql
RUN apt-get update
RUN apt-get install -y --no-install-recommends git

RUN pip install pipenv==2023.2.18
RUN pip install pipenv==2023.4.20

WORKDIR /code/

Expand All @@ -22,7 +22,7 @@ RUN PIPENV_VENV_IN_PROJECT=1 pipenv run pip install .
#################
# Runtime image #
#################
FROM python:3.9-slim
FROM python:3.10-slim

ARG GITHUB_REF
ENV VERSION=$GITHUB_REF
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ twilio = ">=7.0.0"
uvloop = {version = "*", markers = "sys_platform != 'win32'"}

[dev-packages]
hypothesis = "<=6.47.1" # Later versions add a prerelease dependency. See https://github.com/pypa/pipenv/issues/1760
hypothesis = "*" # Versions between 6.47.1 and 6.56.4 added a prerelease dependency. See https://github.com/pypa/pipenv/issues/1760
pdoc3 = "*"
pytest = "*"
pytest-asyncio = "*"
Expand All @@ -38,4 +38,4 @@ pytest-mock = "*"
vulture = "*"

[requires]
python_version = "3.9"
python_version = "3.10"
33 changes: 8 additions & 25 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/ada42f6e09a341a88f3dae262a43e86e)](https://www.codacy.com/gh/FAForever/server/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=FAForever/server&amp;utm_campaign=Badge_Grade)
[![docs](https://img.shields.io/badge/docs-latest-purple)](https://faforever.github.io/server/)
[![license](https://img.shields.io/badge/license-GPLv3-blue)](license.txt)
![python](https://img.shields.io/badge/python-3.9-3776AB)
![python](https://img.shields.io/badge/python-3.10-3776AB)

This is the source code for the
[Forged Alliance Forever](https://www.faforever.com/) lobby server.
Expand Down
45 changes: 20 additions & 25 deletions tests/utils/hypothesis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import contextlib
import inspect
import itertools
from inspect import Parameter, Signature

import pytest
from hypothesis.internal.reflection import (
define_function_signature,
get_signature,
impersonate
)

Expand All @@ -18,13 +19,13 @@ def autocontext(*auto_args):
that requires the `request` fixture won't work.
"""
def decorate_test(test):
original_argspec = inspect.getfullargspec(test)
argspec = new_argspec(original_argspec, auto_args)
original_signature = get_signature(test)
signature = new_signature(original_signature, auto_args)

if asyncio.iscoroutinefunction(test):
@pytest.mark.asyncio
@impersonate(test)
@define_function_signature(test.__name__, test.__doc__, argspec)
@define_function_signature(test.__name__, test.__doc__, signature)
async def wrapped_test(*args, **kwargs):
# Tell pytest to omit the body of this function from tracebacks
__tracebackhide__ = True
Expand Down Expand Up @@ -54,7 +55,7 @@ async def wrapped_test(*args, **kwargs):
return wrapped_test
else:
@impersonate(test)
@define_function_signature(test.__name__, test.__doc__, argspec)
@define_function_signature(test.__name__, test.__doc__, signature)
def wrapped_test(*args, **kwargs):
# Tell pytest to omit the body of this function from tracebacks
__tracebackhide__ = True
Expand All @@ -77,25 +78,19 @@ def wrapped_test(*args, **kwargs):
return decorate_test


def new_argspec(original_argspec, auto_args):
"""Make an updated argspec for the wrapped test."""
replaced_args = {
original_arg: auto_arg
for original_arg, auto_arg in zip(
original_argspec.args[:len(auto_args)],
auto_args
)
}
new_args = tuple(itertools.chain(
auto_args,
original_argspec.args[len(auto_args):]
def new_signature(original_signature: Signature, auto_args):
"""Make an updated signature for the wrapped test."""
# Replace the parameter names in the original signature with the names
# of the fixtures given to @autocontext(...) so that pytest will inject the
# right fixtures.
new_parameters = tuple(itertools.chain(
[
Parameter(name, Parameter.POSITIONAL_OR_KEYWORD)
for name in auto_args
],
list(original_signature.parameters.values())[len(auto_args):]
))
annots = {
replaced_args.get(k) or k: v
for k, v in original_argspec.annotations.items()
}
annots["return"] = None
return original_argspec._replace(
args=new_args,
annotations=annots
return original_signature.replace(
parameters=new_parameters,
return_annotation=None
)

0 comments on commit 592c575

Please sign in to comment.