Skip to content

Commit

Permalink
Merge pull request #18 from trustpilot/version-bumps
Browse files Browse the repository at this point in the history
Version bumps
  • Loading branch information
sneeu authored Aug 1, 2023
2 parents 78f2cdc + b31e92a commit 6e0f48a
Show file tree
Hide file tree
Showing 10 changed files with 927 additions and 1,014 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run tox

on:
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tox
run: tox
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@
# 2.1.0 (2020-12-18)

- Add parse_parameters decorator to support both GET(query params) and POST(body params) requests
- Start deprecated process of parse_query_args
- Start deprecated process of parse_query_args

# 3.0.0 (2023-08-01)

- Bump versions of everything
- Depricate `parse_query_args`
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,4 @@ You need to apply the `parse_parameters` decorator as the first one executed whi

You should always have request as the first argument in your function in order to use `parse_parameters`.

**Note** that `request` arg can be renamed and even type-annotated as long as it is the first arg.

### `parse_query_args` deprecation

`parse_query_args` will be deprecated in future version in favor of `parse_parameters`
Currently it is still usable as a legacy decorator
**Note** that `request` arg can be renamed and even type-annotated as long as it is the first arg.
6 changes: 4 additions & 2 deletions examples/simple.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import datetime

from sanic import Sanic, response
from sanicargs import parse_query_args

from sanicargs import parse_parameters

app = Sanic("test_sanic_app")


@app.route("/me/<id>/birthdate", methods=["GET"])
@parse_query_args
@parse_parameters
async def test_datetime(request, id: str, birthdate: datetime.datetime):
return response.json({"id": id, "birthdate": birthdate.isoformat()})

Expand Down
1,387 changes: 648 additions & 739 deletions poetry.lock

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
[tool.poetry]
name = "sanicargs"
version = "2.1.0"
version = "3.0.0"
description = "Parses query args or body parameters in sanic using type annotations"
readme = "README.md"
keywords = ["sanicargs", "sanic", "query", "args", "type annotations"]
authors = [
"Johannes Valbjørn <[email protected]>",
"Thomas Thiebaud <[email protected]>"
"John Sutherland <[email protected]>",
]
repository = "https://github.com/trustpilot/python-sanicargs"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Natural Language :: English",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

[tool.poetry.dependencies]
python = "^3.6"
sanic = ">=18.12"
ciso8601 = "^2.1.3"
ciso8601 = "^2.3.0"
python = "^3.8"
sanic = "^23.6.0"

[tool.poetry.dev-dependencies]
pytest = "^5.4.1"
pytest-sanic = "^1.6.0"
black = "^19.10b0"
black = "^23.7"
isort = "^5.12.0"
pytest = "^7.4.0"
pytest-asyncio = "^0.21.1"
sanic-testing = "^23.6.0"

[tool.isort]
profile = "black"

[build-system]
requires = ["poetry>=1.1.4"]
Expand Down
37 changes: 8 additions & 29 deletions sanicargs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import datetime
import inspect
import json
from functools import wraps
from logging import getLogger

import ciso8601
import datetime
import json
import warnings
from sanic.exceptions import BadRequest

from sanic import response
from sanic.exceptions import abort
from sanicargs.fields import List

from logging import getLogger

__logger = getLogger("sanicargs")


Expand Down Expand Up @@ -48,34 +46,15 @@ def __parse_list(str_or_list):
}


def parse_query_args(func):
"""parses query args and validates, deserializes them
VERY IMPORTANT!:
to use this decorator it must be used in a Sanic endpoint and used BEFORE the
sanic blueprint decorator like so:
@blueprint.route("/foo/<businessunitid>/bar")
@authorize_business_unit
@parse_query_args
and the signature of the function needs to start with request and the rest of
the parameters need type hints like so:
async def generate_csv(request, query: str, businessunitid: str):
"""
warnings.warn(
"This decorator will be deprecated in the next major release",
DeprecationWarning,
)
return __parse(func, True)


def parse_parameters(func):
"""parses query or body parameters depending on http method, validates and deserializes them
VERY IMPORTANT!:
to use this decorator it must be used in a Sanic endpoint and used BEFORE the
to use this decorator it must be used in a Sanic endpoint and used BEFORE the
sanic blueprint decorator like so:
@blueprint.route("/foo/<businessunitid>/bar")
@authorize_business_unit
@parse_parameters
and the signature of the function needs to start with request and the rest of
and the signature of the function needs to start with request and the rest of
the parameters need type hints like so:
async def generate_csv(request, query: str, businessunitid: str):
"""
Expand Down Expand Up @@ -134,7 +113,7 @@ async def inner(request, *old_args, **route_parameters):
"stacktrace": str(err),
}
)
return abort(400, "Bad or missing value for %s" % name)
raise BadRequest(f"Bad or missing value for {name}")
return await func(request, **kwargs)

return inner
Loading

0 comments on commit 6e0f48a

Please sign in to comment.