Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/on_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- run: |
uv run --locked --group tests tox run -e py,py-async

typing:
name: Type checker [${{ matrix.platform }} | ${{ matrix.python-version }}]
runs-on: ${{ matrix.platform }}
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
platform:
- ubuntu-latest
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
docker-target-build: ["app", "async", "mypyc"]
docker-target-build: ["app", "async"]
exclude:
- platform: ubuntu-latest
python-version: "3.9"
Expand Down
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ coverage.xml
.pytest_cache/
cover/
junit/
prof/

# Integration tests
tests/integration/test-results/

# Translations
*.mo
Expand Down Expand Up @@ -155,10 +159,10 @@ target/
profile_default/
ipython_config.py

# pyenv
# pyenv / uv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down Expand Up @@ -214,4 +218,4 @@ dmypy.json
cython_debug/

# Ruff
.ruff_cache/
.ruff_cache/
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: '.git|.tox|.venv|.vscode|__pycache__|.pytest_cache|.eggs|.mypy_cache|.pytype|htmlcov|junit|htmldoc'
exclude: '.git|.tox|.venv|.vscode|__pycache__|.ruff_cache|.pytest_cache|.eggs|.mypy_cache|.pytype|htmlcov|junit|htmldoc|test-results|prof'
default_stages: [pre-commit]
fail_fast: true
default_language_version:
Expand All @@ -7,7 +7,7 @@ ci:
autoupdate_schedule: weekly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-ast
- id: check-builtin-literals
Expand All @@ -26,11 +26,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.14.0
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.8.0
rev: 0.9.3
hooks:
- id: uv-lock
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ USER ${USERNAME}
WORKDIR ${APP_DIR}/run
COPY --chown=${USERNAME}:${GROUPNAME} .docker/* tests/integration/*.py tests/integration/*.ini ${APP_DIR}/run/
COPY --chown=${USERNAME}:${GROUPNAME} tests/integration/shared/*.py tests/shared/ ${APP_DIR}/run/shared/
CMD ["bash", "-c", "./wait-for-it.sh ${SITE_DOMAIN}:${SITE_PORT} -t 600 -- py.test -n auto -vv --tb=short --junitxml=test-results/junit.xml"]
CMD ["bash", "-c", "./wait-for-it.sh ${SITE_DOMAIN}:${SITE_PORT} -t 600 -- py.test -vv --tb=short --junitxml=test-results/junit.xml"]


FROM baseimage
Expand Down
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean style typing test test-release release env
.PHONY: all clean style typing test test-cov-unit test-examples test-release release env uv-lock

VIRTUALENV_EXISTS := $(shell [ -d .venv ] && echo 1 || echo 0)

Expand All @@ -21,6 +21,25 @@ typing:
test: clean
@uv run tox run

test-cov-unit:
@REPORT="\nUnit Tests:\n"; \
ALLOW_ASYNC=$$(python3 -c "import importlib.util; print(1 if importlib.util.find_spec('asgiref') else 0)"); \
for TEST_FILE in $(shell find tests/unit -name "test_*.py"); do \
TEST_NAME=$$(basename $${TEST_FILE} .py); \
PY_MODULE=$$(echo flask_jsonrpc.$${TEST_FILE} | sed 's|/|.|g' | sed 's|.py$$||' | sed 's|test_||' | sed 's|tests.unit.||' | sed 's|.openrpc.app|.openrpc|' | sed 's|.browse.app|.browse|' | sed 's|.async_app|.app|'); \
if [ $${ALLOW_ASYNC} -eq 0 ] && [[ $${TEST_FILE} == *"async"* ]]; then \
continue; \
fi; \
pytest --cov-reset --cov=$${PY_MODULE} $${TEST_FILE} -vv; \
if [ $$? -ne 0 ]; then \
REPORT+=" + Unit Tests $${TEST_FILE} for $${PY_MODULE} failed (pytest --cov-reset --cov-report=html --cov=$${PY_MODULE} $${TEST_FILE} -vv)\n"; \
else \
REPORT+=" + Unit Tests $${TEST_FILE} for $${PY_MODULE} passed\n"; \
fi; \
done; \
echo $${REPORT}


test-examples: clean
@find examples/ -name "tox.ini" -print0 | xargs -0 -I {} -P 4 uv run tox run -e py,py-async -c {}

Expand All @@ -38,3 +57,10 @@ ifeq ($(VIRTUALENV_EXISTS), 0)
endif
@uv sync --locked
@echo "To activate the virtualenv, run: source .venv/bin/activate"

uv-lock:
@uv lock -U
@for dir in examples/*/; do \
echo "Updating lock file for $$dir"; \
uv lock -U --directory "$$dir"; \
done
11 changes: 7 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ services:
args:
- DOCKER_BUILD_TARGET=app
environment:
- FLASK_SERVER_NAME=app:5000
- FLASK_PREFERRED_URL_SCHEME=https
- FLASK_SERVER_NAME=app.flask-jsonrpc.cenobit.es
user: ${UID:-0}:${GID:-0}
command: >
python -m app
Expand Down Expand Up @@ -100,7 +101,7 @@ services:
- BROWSABLE_API_URL=https://async-app.flask-jsonrpc.cenobit.es/api/browse
user: ${UID:-0}:${GID:-0}
command: >
./wait-for-it.sh async-app.flask-jsonrpc.cenobit.es:80 -t 600 -- py.test -n auto -vv --tb=short --junitxml=test-results/junit.xml
./wait-for-it.sh async-app.flask-jsonrpc.cenobit.es:80 -t 600 -- py.test -vv --tb=short --junitxml=test-results/junit.xml
volumes:
- .pytest_cache/test-results/async-app:/app/test-results
- .pytest_cache/screnshots/async-app:/app/.pytest_cache/screnshots
Expand All @@ -120,7 +121,8 @@ services:
args:
- DOCKER_BUILD_TARGET=app
environment:
- FLASK_SERVER_NAME=async-app:5000
- FLASK_PREFERRED_URL_SCHEME=https
- FLASK_SERVER_NAME=async-app.flask-jsonrpc.cenobit.es
user: ${UID:-0}:${GID:-0}
command: >
python -m async_app
Expand Down Expand Up @@ -191,7 +193,8 @@ services:
args:
- DOCKER_BUILD_TARGET=mypyc-app
environment:
- FLASK_SERVER_NAME=mypyc-app:5000
- FLASK_PREFERRED_URL_SCHEME=https
- FLASK_SERVER_NAME=mypyc-app.flask-jsonrpc.cenobit.es
user: ${UID:-0}:${GID:-0}
command: >
python -m app
Expand Down
33 changes: 26 additions & 7 deletions examples/javascript/tests/api/test_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,46 @@ def test_rpc_describe(client: 'FlaskClient') -> None:
assert data['id'] == 1
assert data['jsonrpc'] == '2.0'
assert data['result']['name'] == 'Flask-JSONRPC'
assert data['result']['version'] == '2.0'
assert data['result']['version'] == '1.0.0'
assert data['result']['servers'] is not None
assert 'url' in data['result']['servers'][0]
assert data['result']['methods'] == {
'Hello.index': {
'options': {'notification': True, 'validate': True},
'name': 'Hello.index',
'notification': True,
'params': [],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'Hello.say': {
'options': {'notification': True, 'validate': True},
'name': 'Hello.say',
'notification': True,
'params': [{'name': 'name', 'type': 'String'}],
'returns': {'type': 'String'},
'returns': {'name': 'default', 'type': 'String'},
'type': 'method',
'validation': True,
},
'rpc.describe': {
'name': 'rpc.describe',
'description': 'Service description for JSON-RPC 2.0',
'options': {},
'notification': False,
'params': [],
'returns': {'type': 'Object'},
'returns': {
'name': 'default',
'properties': {
'description': {'name': 'description', 'type': 'String'},
'id': {'name': 'id', 'type': 'String'},
'methods': {'name': 'methods', 'type': 'Null'},
'name': {'name': 'name', 'type': 'String'},
'servers': {'name': 'servers', 'type': 'Null'},
'title': {'name': 'title', 'type': 'String'},
'version': {'name': 'version', 'type': 'String'},
},
'type': 'Object',
},
'summary': 'RPC Describe',
'type': 'method',
'validation': False,
},
}
21 changes: 18 additions & 3 deletions examples/javascript/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,30 @@ def test_rpc_describe(client: 'FlaskClient') -> None:
assert data['id'] == 1
assert data['jsonrpc'] == '2.0'
assert data['result']['name'] == 'Flask-JSONRPC'
assert data['result']['version'] == '2.0'
assert data['result']['version'] == '1.0.0'
assert data['result']['servers'] is not None
assert 'url' in data['result']['servers'][0]
assert data['result']['methods'] == {
'rpc.describe': {
'name': 'rpc.describe',
'description': 'Service description for JSON-RPC 2.0',
'options': {},
'notification': False,
'params': [],
'returns': {'type': 'Object'},
'returns': {
'name': 'default',
'properties': {
'description': {'name': 'description', 'type': 'String'},
'id': {'name': 'id', 'type': 'String'},
'methods': {'name': 'methods', 'type': 'Null'},
'name': {'name': 'name', 'type': 'String'},
'servers': {'name': 'servers', 'type': 'Null'},
'title': {'name': 'title', 'type': 'String'},
'version': {'name': 'version', 'type': 'String'},
},
'type': 'Object',
},
'summary': 'RPC Describe',
'type': 'method',
'validation': False,
}
}
Loading
Loading