Skip to content

Commit 63445e9

Browse files
committed
Remove pypy in favor of cython
1 parent d60ea56 commit 63445e9

File tree

14 files changed

+65
-133
lines changed

14 files changed

+65
-133
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
**/*_data.json
1313
**/.*_cache
1414
**/*.log
15+
**/*$py.class
16+
**/*.c
17+
**/*.so
18+
**/*.py[cod]
19+
**/*.pdb
20+
**/*.whl
21+
**/*.egg
22+
**/*.egg-info
1523
hidden/
1624
docs/
1725
demo/

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ jobs:
106106
- '3.13'
107107
- '3.12'
108108
- '3.11'
109-
- 'pypy3.11'
110-
- 'pypy3.10'
111109
os:
112110
- ubuntu-latest
113111
- windows-latest
@@ -141,7 +139,7 @@ jobs:
141139
working-directory: backend
142140

143141
- name: Unit Test 🧪
144-
run: python -Wd manage.py test --no-input ${{ !startsWith(matrix.python-version, 'pypy') && '--parallel auto' || '' }} --pythonpath ../common
142+
run: python -Wd manage.py test --no-input --parallel auto --pythonpath ../common
145143
working-directory: backend
146144

147145

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ __pycache__/
44
*$py.class
55

66
# C extensions
7+
*.c
78
*.so
89

910
# Distribution / packaging

.vscode/launch.json

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,6 @@
167167
"order": 4
168168
},
169169
},
170-
{
171-
"name": "Generate Variants using PyPy",
172-
"type": "debugpy",
173-
"python": "pypy",
174-
"request": "launch",
175-
"cwd": "${workspaceFolder}/backend",
176-
"program": "manage.py",
177-
"args": [
178-
"generate_variants"
179-
],
180-
"env": {
181-
"PYTHONPATH": "${workspaceFolder}${/}common",
182-
},
183-
"preLaunchTask": "Prelaunch",
184-
"django": true,
185-
"justMyCode": true,
186-
"presentation": {
187-
"hidden": false,
188-
"group": "Spellbook",
189-
"order": 4
190-
},
191-
},
192170
{
193171
"name": "Profile Generate Variants",
194172
"type": "debugpy",
@@ -210,28 +188,6 @@
210188
"order": 4
211189
},
212190
},
213-
{
214-
"name": "Profile Generate Variants using PyPy",
215-
"type": "debugpy",
216-
"python": "pypy",
217-
"request": "launch",
218-
"cwd": "${workspaceFolder}/backend",
219-
"module": "cProfile",
220-
"args": [
221-
"-o", "${workspaceFolder}/backend/temp/profiles/generate_variants_pypy.prof", "manage.py", "generate_variants"
222-
],
223-
"env": {
224-
"PYTHONPATH": "${workspaceFolder}${/}common",
225-
},
226-
"preLaunchTask": "Prelaunch",
227-
"django": true,
228-
"justMyCode": true,
229-
"presentation": {
230-
"hidden": false,
231-
"group": "Spellbook",
232-
"order": 5
233-
},
234-
},
235191
{
236192
"name": "Export variants",
237193
"type": "debugpy",

backend/Dockerfile

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
##########
2+
# PYTHON #
3+
##########
4+
FROM python:3.12-alpine AS python
5+
6+
17
###########
28
# BUILDER #
39
###########
4-
FROM python:3.12-alpine AS builder
10+
FROM python AS builder
511

612
# set work directory
713
WORKDIR /usr/src/app
@@ -20,22 +26,10 @@ COPY backend/requirements.txt .
2026
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/python/wheels -r requirements.txt
2127

2228

23-
#################
24-
# PYPY BUILDER #
25-
#################
26-
FROM builder AS pypy-builder
27-
28-
RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
29-
apk --update add pypy3@testing
30-
31-
RUN pypy3 -m ensurepip && pypy3 -m pip install --upgrade pip
32-
33-
RUN pypy3 -m pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/pypy/wheels $(grep -ivE "#|cryptography|cffi" requirements.txt)
34-
3529
#########
3630
# BASE #
3731
#########
38-
FROM python:3.12-alpine AS base
32+
FROM python AS base
3933

4034
# create the app user
4135
RUN addgroup -S app && adduser -S app -G app
@@ -74,32 +68,37 @@ ENTRYPOINT ["/bin/sh", "entrypoint.prod.sh"]
7468
RUN echo -e 'gunicorn backend.wsgi:application --bind 0.0.0.0:8000\n' > entrypoint.prod.sh
7569

7670

77-
#########
78-
# PYPY #
79-
#########
80-
FROM base AS pypy
71+
##########
72+
# CYTHON #
73+
##########
74+
FROM builder AS cython
8175

82-
# Switch to user root in order to install pypy
83-
USER root
76+
RUN pip install --upgrade cython setuptools
8477

85-
# install dependencies
86-
RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
87-
apk --update add pypy3@testing && \
88-
ln -s $(which pypy3) $(dirname $(which pypy3))/pypy && \
89-
pypy -m ensurepip && pypy -m pip install --no-cache-dir --upgrade pip
9078

91-
COPY --from=pypy-builder /usr/src/app/pypy/wheels /pypy/wheels
79+
##################
80+
# CYTHON-BUILDER #
81+
##################
9282

93-
RUN pypy -m pip install --no-cache-dir /pypy/wheels/* --no-deps
94-
RUN pypy -m pip install --no-cache-dir psycopg
83+
FROM cython AS cython-builder
84+
85+
COPY backend/ common/ /usr/src/app/
86+
WORKDIR /usr/src/app/
87+
RUN cythonize -i 'spellbook/variants/*.py'
88+
89+
90+
###############
91+
# BASE-CYTHON #
92+
###############
93+
FROM base AS base-cython
94+
95+
COPY --from=cython-builder --parents /usr/src/app/./**/*.so $APP_HOME
9596

96-
# Switch back to the app user
97-
USER app
9897

9998
#########
10099
# DEMO #
101100
#########
102-
FROM pypy AS demo
101+
FROM base-cython AS demo
103102

104103
RUN echo -e 'set -e\n\
105104
python manage.py collectstatic --no-input --clear\n\
@@ -113,7 +112,7 @@ gunicorn backend.wsgi:application --bind 0.0.0.0:8000\n' > entrypoint.prod.sh
113112
##############
114113
# PRODUCTION #
115114
##############
116-
FROM pypy AS production
115+
FROM base-cython AS production
117116

118117
ADD backend/nginx/production.conf /etc/nginx/nginx.conf
119118

backend/backend/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import os
1313
from pathlib import Path
1414
from datetime import timedelta
15-
from common.pypy_utils import PYPY_AVAILABLE as check_pypy
1615
from constants import SORTED_COLORS
1716

1817
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -30,8 +29,6 @@
3029

3130
STATIC_BULK_FOLDER = Path('./temp/bulk')
3231

33-
PYPY_AVAILABLE = check_pypy
34-
3532
VERSION = os.getenv('VERSION', 'dev')
3633

3734
ALLOWED_HOSTS = ['*']

backend/common/pypy_utils.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

backend/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ sqlparse==0.5.0
121121
# via django
122122
typing-extensions==4.15.0
123123
# via referencing
124+
tzdata==2025.3
125+
# via django
124126
uritemplate==4.2.0
125127
# via drf-spectacular
126128
urllib3==2.6.3

backend/spellbook/models/utils.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22
import unicodedata
3-
from platform import python_implementation
43
from typing import Callable, Generator, Iterable
54
from collections import defaultdict
65
from ..regexs import MANA_SYMBOL, ORACLE_SYMBOL, ORACLE_SYMBOL_EXTENDED
@@ -302,23 +301,11 @@ def remove_random_from_order_by(order_by: Iterable[str | F | OrderBy]) -> Genera
302301
def __default_batch_size() -> int:
303302
'''Returns an appropriate batch size for the current database connection.'''
304303
otherwise = 100
305-
match python_implementation():
306-
case 'PyPy':
307-
match connection.vendor:
308-
case 'sqlite':
309-
return 1000
310-
case 'postgresql':
311-
return 45
312-
case _:
313-
return otherwise
314-
case 'CPython':
315-
match connection.vendor:
316-
case 'sqlite':
317-
return 1000
318-
case 'postgresql':
319-
return 275
320-
case _:
321-
return otherwise
304+
match connection.vendor:
305+
case 'sqlite':
306+
return 1000
307+
case 'postgresql':
308+
return 275
322309
case _:
323310
return otherwise
324311

backend/spellbook/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
def launch_command_async(command: str, args: list[str] = []):
1515
manage_py_path = pathlib.Path(__file__).parent.parent / 'manage.py'
16-
avoid_pypy = command in ['runserver', 'shell', 'export_variants']
17-
interpreter = 'pypy' if not avoid_pypy and settings.PYPY_AVAILABLE else 'python'
16+
interpreter = 'python'
1817
args = [interpreter, manage_py_path.resolve(), command] + args
1918
if sys.platform == "win32":
2019
subprocess.Popen(

0 commit comments

Comments
 (0)