Skip to content

Commit

Permalink
Support Emmett 2.6 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro authored Oct 14, 2024
1 parent ead0873 commit 6207afa
Show file tree
Hide file tree
Showing 30 changed files with 914 additions and 1,562 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/emmett-rest
permissions:
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install and configure Poetry
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true
- name: Publish
python-version: 3.12
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Build distributions
run: |
poetry build
poetry publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
uv build
- name: Publish package to pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
24 changes: 12 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ name: Tests
on:
push:
branches:
- "**"
tags-ignore:
- "**"
- "master"
pull_request:
types: [opened, synchronize]
branches:
- master

jobs:
Linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, '3.10', '3.11']
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13']

services:
postgres:
Expand All @@ -26,18 +28,16 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: gi0baro/[email protected]
with:
virtualenvs-in-project: true
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install dependencies
run: |
poetry install -v
uv sync --dev
- name: Test
run: |
poetry run pytest -v tests
uv run pytest -v tests
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ __pycache__

build/*
dist/*
Emmett_REST.egg-info/*
poetry.lock
*.egg-info/*
uv.lock

tests/databases/*
tests/logs/*
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.DEFAULT_GOAL := all
pysources = emmett_rest tests

.PHONY: format
format:
ruff check --fix $(pysources)
ruff format $(pysources)

.PHONY: lint
lint:
ruff check $(pysources)
ruff format --check $(pysources)

.PHONY: test
test:
pytest -v tests

.PHONY: all
all: format lint test
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

Emmett-REST is a REST extension for [Emmett framework](https://emmett.sh).

[![pip version](https://img.shields.io/pypi/v/emmett-rest.svg?style=flat)](https://pypi.python.org/pypi/Emmett-REST)
![Tests Status](https://github.com/emmett-framework/rest/workflows/Tests/badge.svg)

## In a nutshell

```python
Expand Down
2 changes: 1 addition & 1 deletion emmett_rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ext import REST
from .parsers import Parser, parse_params, parse_params_with_parser
from .rest import RESTModule
from .parsers import Parser, parse_params_with_parser, parse_params
from .serializers import Serializer, serialize
2 changes: 1 addition & 1 deletion emmett_rest/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.5.2"
__version__ = "1.6.0"
117 changes: 53 additions & 64 deletions emmett_rest/ext.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
"""
emmett_rest.ext
---------------
emmett_rest.ext
---------------
Provides REST extension for Emmett
Provides REST extension for Emmett
:copyright: 2017 Giovanni Barillari
:license: BSD-3-Clause
:copyright: 2017 Giovanni Barillari
:license: BSD-3-Clause
"""

from typing import Any, Dict, List, Optional, Type, Union
Expand All @@ -16,66 +16,55 @@
from emmett.orm.models import MetaModel

from .openapi.mod import OpenAPIModule
from .rest import AppModule, RESTModule
from .parsers import Parser
from .rest import AppModule, RESTModule
from .serializers import Serializer
from .wrappers import (
wrap_method_on_obj,
wrap_module_from_app,
wrap_module_from_module,
wrap_module_from_modulegroup
)
from .wrappers import wrap_method_on_obj, wrap_module_from_app, wrap_module_from_module, wrap_module_from_modulegroup


class REST(Extension):
default_config = dict(
default_module_class=RESTModule,
default_serializer=Serializer,
default_parser=Parser,
page_param='page',
pagesize_param='page_size',
sort_param='sort_by',
query_param='where',
min_pagesize=1,
max_pagesize=50,
default_pagesize=20,
default_sort=None,
base_path='/',
id_path='/<int:rid>',
list_envelope='data',
single_envelope=False,
groups_envelope='data',
use_envelope_on_parse=False,
serialize_meta=True,
meta_envelope='meta',
default_enabled_methods=[
'index', 'create', 'read', 'update', 'delete'
],
default_disabled_methods=[],
use_save=True,
use_destroy=True
)
default_config = {
"default_module_class": RESTModule,
"default_serializer": Serializer,
"default_parser": Parser,
"page_param": "page",
"pagesize_param": "page_size",
"sort_param": "sort_by",
"query_param": "where",
"min_pagesize": 1,
"max_pagesize": 50,
"default_pagesize": 20,
"default_sort": None,
"base_path": "/",
"id_path": "/<int:rid>",
"list_envelope": "data",
"single_envelope": False,
"groups_envelope": "data",
"use_envelope_on_parse": False,
"serialize_meta": True,
"meta_envelope": "meta",
"default_enabled_methods": ["index", "create", "read", "update", "delete"],
"default_disabled_methods": [],
"use_save": True,
"use_destroy": True,
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
from .serializers import serialize
from .parsers import parse_params
from .serializers import serialize

self._serialize = serialize
self._parse_params = parse_params

@listen_signal(Signals.before_database)
def _configure_models_attr(self):
MetaModel._inheritable_dict_attrs_.append(
('rest_rw', {'id': (True, False)})
)
MetaModel._inheritable_dict_attrs_.append(("rest_rw", {"id": (True, False)}))

def on_load(self):
setattr(AppModule, 'rest_module', wrap_module_from_module(self))
setattr(AppModuleGroup, 'rest_module', wrap_module_from_modulegroup(self))
self.app.rest_module = wrap_method_on_obj(
wrap_module_from_app(self),
self.app
)
AppModule.rest_module = wrap_module_from_module(self)
AppModuleGroup.rest_module = wrap_module_from_modulegroup(self)
self.app.rest_module = wrap_method_on_obj(wrap_module_from_app(self), self.app)

@property
def module(self):
Expand Down Expand Up @@ -109,7 +98,7 @@ def docs_module(
url_prefix: Optional[str] = None,
hostname: Optional[str] = None,
module_class: Optional[Type[OpenAPIModule]] = None,
**kwargs: Any
**kwargs: Any,
):
module_class = module_class or OpenAPIModule
return module_class.from_app(
Expand All @@ -127,19 +116,19 @@ def docs_module(
pipeline=[],
injectors=[],
opts={
'title': title,
'version': version,
'modules_tree_prefix': modules_tree_prefix,
'description': description,
'tags': tags,
'servers': servers,
'terms_of_service': terms_of_service,
'contact': contact,
'license_info': license_info,
'security_schemes': security_schemes,
'produce_schemas': produce_schemas,
'expose_ui': expose_ui,
'ui_path': ui_path
"title": title,
"version": version,
"modules_tree_prefix": modules_tree_prefix,
"description": description,
"tags": tags,
"servers": servers,
"terms_of_service": terms_of_service,
"contact": contact,
"license_info": license_info,
"security_schemes": security_schemes,
"produce_schemas": produce_schemas,
"expose_ui": expose_ui,
"ui_path": ui_path,
},
**kwargs
**kwargs,
)
Loading

0 comments on commit 6207afa

Please sign in to comment.