Skip to content

Commit

Permalink
Issue #177: Add a baseline for Rust path resolution bindings (#270)
Browse files Browse the repository at this point in the history
* add route map extension

* change maturin to dev dependency

* rust ext: make Node::is_asgi default to false

* rust ext: remove unused dependency

* Build rust project with poetry

* Move cargo stuff entirely within the extensions/rust dir

* Move rust extension out of starlite folder

* Correct import

* Include rust source in sdist build

* Working extension poetry build

* Rename build.py

* Ignore build directory

* fix .gitignore order

* rust ext: refactor and rename route map module; added resolve_asgi_app()

* reinstall lock file

* rust ext: remove some uses of `Python::acquire_gil()`

* rust ext: don't return `PyResult` for infallible operations

* rust ext: hide plain route methods from python interface

* rust ext: add route collection parameter to `add_routes`

* rust ext: use `IntoPy` trait method for `Node` instead of `as_pydict`

* rust ext: refactor parameters for `configure_route_map_node`

* rust ext: remove outdated comment

* rust_ext: change uses of `cur` to `cur_node`

* rust ext: fix typo in route map comments

* rust ext: downgrade add_node_to_route_map return value to shared ref

* rust_ext: port build_route_middleware_stack into extension util, removing starlite instance dependence

* rust ext: add minimal test

* Enhancement: Brotli compression middleware (#252)

* FEATURE: Added Compression Middleware
- Existing Gzip Middleware
- Brotli with an optional Gzip fallback.

* 1.5.4

* updated pyproject.toml to exclude lines form coverage report

* Add tests for `Starlite.construct_route_map`

* Address flake8 validation rules

* Removes `uuid4()` from within parametrized test cases.

Vscode test discovery caches the test case names including parametrized values.
This makes having `uuid4()` calls in the parametrized test cases an issue as vscode shows test case failures when it cannot find test cases that it has previously resolved.
As the change doesn't affect the utility of the test, it is better to fix the case for vscode users so we don't get the same issue reported in the future.

* Addresses cognitive complexity of `DTOFactory.__call__()` by breaking nested logic out into helper methods.

Changes no logic, test cov still 100% and existing tests pass.

For #203

* updated dependencies

* Issue 187 layered parameters (#261)

* feat: added parameters to all app layers

* feat: refactored handler layer resolution logic

* chore: cleanup signature modelling

* feat: add layered parameters to kwargs model

* fix test coverage

* skipped failing test in py 3.7

* update OA params

* updated implementation to use ModelField insteam of FieldInfo

* add openapi parameter tests

* add docs

* 1.6.0

* 1.6.1

* Fix route-map path existence test logic (#275) (#277)

* added after_response (#279)

* added after_response

* addressed review comments

* Issue 188: resolve exceptions swallowing args (#281)

* updated exception init

* add tests

* 1.6.2

* chore: updated maintainer list (#285)

* docs: add cofin as a contributor for maintenance (#286)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Issue #255: allow single element query param in sequence types (#262)

* Array handling in query params

* Refactor array handling

Co-authored-by: Joseph Daniel <jdn@logpoint.com>

* docs: add josepdaniel as a contributor for code (#290)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Updates instructions to install `testing` extra.

* LifecycleHook improvements.

- Adds `LifecycleHook` for eager evaluation of sync vs async callables and centralisation of handler resolution. Generic on handler response.
- Adds aliases `AfterRequestHook`, `AfterResponseHook`, `BeforeRequestHook` that are strongly typed to appropriate handler response type.
- Adds support for lifecycle hooks that are instance methods by overwriting handlers assigned to class variables on `Controller` only if they are originally functions. Closes #284

* Enhancement: Tortoise-ORM Plugin (#283)

* added tortoise to dev dependencies

* added base plugin implementation

* add tests

* updated plugin implementation

* cleanup dependencies

* updated implementation

* fixed issues

* resolved issues

* add openapi support

* fix tests

* updated tests

* add docs

* fix linter issues

* updated tests

* 1.7.0

* Split `openapi.create_paramter_for_handler` into several methods to reduce complexity (#292)

* Split `openapi.create_paramter_for_handler` into several methods to reduce complexity

* Make `openapi.create_paramter_for_handler`'s helper functions public

* Revise misleading `openapi.get_recursive_handler_parameters` docstrings

* Adds `exceptions.utils.create_exception_response()`.

- makes `starlite.exceptions` a sub-package with same api as module it replaces.
- adds `starlite.exceptions.utils` module to house the response generation helper function.

* Supress warning generated from Tortoise ORM DTO test case.

Warning: `RuntimeWarning: coroutine 'TortoiseORMPlugin.to_dict' was never awaited`

The warning is expected for the underlying code logic and test case, so safe to supress.

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

* Fixes `!!! important` block and adds `<!-- prettier-ignore -->`.

* `orjson` use in `WebSocket.{receive,send}_json()`

Implementations are functionally the same as upstream except for orjson usage and we raise our own exceptions.

Adds tests for `connection.WebSocket`.

Creates `tests/connection` and moved `tests/request` to that location.

* Support for SwaggerUI (#302) (#303)

* Support for SwaggerUI (#302)

* Support for SwaggerUI

As per #300

* Use built-in copy method

* Add basic sanity check tests for ReDoc and Swagger UI routes (#304)

Tests for #303 / #302

These tests check whether the UI handlers:
- don't throw an Exception
- return 200 OK
- return HTML of some form

* updated urls, add docs

* fix memoization issue

Co-authored-by: Tim Wedde <timwedde@icloud.com>

* 1.7.1

* Allow Partial to annotate fields of nested classes (#288)

* Allow Partial to annotate fields for superclasses

* added test to ensure __annotations__ are resolved from parent classes

* added test for runtime behaviour of Partial on classes that don't inherit from pydantic.BaseModel

* use typing.get_type_hints() instead of __annotations__ for getting class type annotations

* raise ImproperlyConfiguredException if class passed to Partial doesn't inherit from BaseModel

* added test to ensure Partial raises ImproperlyConfiguredException if an invalid class is given

* added Partial section to DTO docs

* docs: add Harry-Lees as a contributor for code, doc (#305)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* update docs

* Tidy grammar in comment.

* `OpenAPIConfig.use_handler_docstrings`

Adds ability to configure openapi schema generation to use the route handler docstring for operation description.

If `False` docstrings are ignored, this is default behavior for backward compatibility.

If `True`, `HTTPRouteHandler.description` takes precedence if set, otherwise the docstring is used.

* Adds detail to exception raised during signature model creation.

* 1.7.2

* add route map extension

* Build rust project with poetry

* Move cargo stuff entirely within the extensions/rust dir

* Correct import

* Ignore build directory

* fix .gitignore order

* rust ext: refactor and rename route map module; added resolve_asgi_app()

* reinstall lock file

* fix some issues caused when rebasing

Co-authored-by: Zachary Dremann <dremann@gmail.com>
Co-authored-by: Cody Fincher <204685+cofin@users.noreply.github.com>
Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>
Co-authored-by: Dane Solberg <danesolberg@gmail.com>
Co-authored-by: Peter Schutt <peter@topsport.com.au>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: josepdaniel <36941460+josepdaniel@users.noreply.github.com>
Co-authored-by: Joseph Daniel <jdn@logpoint.com>
Co-authored-by: cătălin <catalin@roboces.dev>
Co-authored-by: Peter Schutt <peter.github@proton.me>
Co-authored-by: Tim Wedde <timwedde@icloud.com>
Co-authored-by: Harry <harry.lees@gmail.com>

Fix issues with Rust route map bindings (#310)

* fix poetry.lock error

* put auto-initialize behind a feature flag

* update poetry.lock

* add back missing plain_routes attribute (will be removed)

cleanup

Misc rust fixes/changes (#312)

* Expose RouteMap as a python stub

* Remove unused duplicate of rust extension inside starlite dir

* Rename module to just `route_map`

It's not clear that we need the module to include `_rs`

* Remove need for macro for get_attr_and_downcast

* Replace macro with a lambda

* Use entry.or_insert_with for getting/inserting nodes

Should be slightly more efficent: We only have to look up once, rather
than twice

* Remove unneeded `.into()`/`to_object()` calls

* Add back a comment to the top of the route_map type stubs

Explain what the file is, and where the implementation is located

Update rust setup (#314)

* updated folder structure and add pre commit hooks

* replace pyi file with py file

* update codespell hook

* turn off TC006

* update ci

Rust Bindings: CI (#317)

* updated ci to handle rust testing

* update python path

* fix coverage

* addressed review comments

* remove flag preventing install when deps are cached

Rust bindings - Some unit tests (#319)

* update poetry.lock

* add some init tests

* add doc comment for gett_attr_and_downcast

* derive Default for Node

* reformat python scripts for rust tests
  • Loading branch information
nramos0 authored and Goldziher committed Aug 5, 2022
1 parent 0be992b commit 7de91d1
Show file tree
Hide file tree
Showing 21 changed files with 1,197 additions and 324 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions-rs/toolchain@v1
name: Install Rust toolchain
with:
toolchain: stable
profile: minimal
components: rustfmt, clippy
- uses: pre-commit/action@v3.0.0
test:
needs: validate
Expand All @@ -31,23 +37,36 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --extras="brotli"
run: poetry install --no-interaction --extras="brotli"
- name: Set pythonpath
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
run: echo "PYTHONPATH=$PWD:$PWD/.venv/lib/python${{ matrix.python-version }}/site-packages/" >> $GITHUB_ENV
- name: Test
run: poetry run pytest
if: matrix.python-version != '3.10'
- name: Test with Coverage
run: poetry run pytest --cov=. --cov-report=xml
if: matrix.python-version == '3.10'
- uses: actions-rs/toolchain@v1
name: Install Rust toolchain
with:
toolchain: stable
profile: minimal
- uses: actions-rs/cargo@v1
name: Run cargo test
with:
command: test
args: --no-default-features --features auto-initialize
- uses: actions/upload-artifact@v3
with:
name: coverage-xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install dependencies
run: poetry install --no-interaction --no-root --no-dev
run: poetry install --no-interaction
- name: publish
shell: bash
run: |
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repos:
rev: v2.1.0
hooks:
- id: codespell
args: [-L, crate]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
Expand All @@ -51,6 +52,12 @@ repos:
hooks:
- id: pycln
args: [--config=pyproject.toml]
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: cargo-check
- id: clippy
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
Expand Down Expand Up @@ -89,6 +96,7 @@ repos:
sqlalchemy,
starlette,
]
args: [--no-strict-imports]
- repo: https://github.com/pycqa/pylint
rev: "v2.14.5"
hooks:
Expand All @@ -97,6 +105,7 @@ repos:
args: ["--unsafe-load-any-extension=y"]
additional_dependencies:
[
setuptools_rust,
orjson,
piccolo,
pydantic,
Expand Down
249 changes: 249 additions & 0 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "rust_bindings"
version = "0.1.0"
edition = "2021"

[lib]
name = "route_map"
crate-type = ["cdylib"]
path = "extensions/route_map/lib.rs"

[dependencies]
pyo3 = { version = "0.16.5" }

[features]
extension-module = ["pyo3/extension-module"]
auto-initialize = ["pyo3/auto-initialize"]
default = ["extension-module"]
16 changes: 16 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Any, Dict

from setuptools_rust import RustExtension


def build(setup_kwargs: Dict[str, Any]) -> None:
"""
Add rust_extensions to the setup dict
"""
setup_kwargs.update(
rust_extensions=[RustExtension("starlite.route_map", path="./Cargo.toml", debug=False)], zip_safe=False
)


if __name__ == "__main__":
build({})
Loading

0 comments on commit 7de91d1

Please sign in to comment.