Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #177: Add a baseline for Rust path resolution bindings #270

Merged
merged 79 commits into from
Jul 26, 2022
Merged

Conversation

nramos0
Copy link

@nramos0 nramos0 commented Jul 9, 2022

Addresses #177.

Baseline implementation very closely mimics the original Python trie implementation for path resolution, but uses Rust types for native performance.

A native extension wheel can be built using maturin build in a Poetry shell, which will output to ./target/wheels, but the packaging of the wheels into the Starlite package has not been done. I think this should be doable by calling a build script from Poetry and including the wheels somehow, if it is not otherwise possible to directly include the wheel directory's wheels.

The native extension has to be built with maturin develop before running pytest in order to run tests locally.

Copy link
Contributor

@Goldziher Goldziher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, very nice stuff and thank you. It's a great first step. I left some comments -

  1. Implementation is not identical I think, and I did not see a 405 being raised anywhere. I would double check and compare the python code to the rest code.

  2. I'm missing unit tests on the rest code. How involved is adding this and updating CI?

  3. Whats needed for a setup script that builds the rust component correctly before publishing?

  4. How can we run integration tests locally?

  5. What can of tooling should he added to pre-commit?

I'm tagging @peterschutt here so he gives input

build.py Outdated Show resolved Hide resolved
starlite/extensions/rust/route_map.rs Outdated Show resolved Hide resolved
starlite/extensions/rust/route_map.rs Outdated Show resolved Hide resolved
starlite/extensions/rust/route_map.rs Outdated Show resolved Hide resolved
starlite/extensions/rust/route_map.rs Outdated Show resolved Hide resolved
starlite/route_map.py Outdated Show resolved Hide resolved
@Dr-Emann
Copy link
Contributor

I also have been working on an implementation as well, currently out-of-tree, I think we should work together to try to take the best of both worlds.

My implementation deviates from the original python one a fair bit in order to be more type-safe, and less stringly-typed. This looks more integrated with the existing repository though.

@nramos0
Copy link
Author

nramos0 commented Jul 11, 2022

First off, very nice stuff and thank you. It's a great first step. I left some comments -

1. Implementation is not identical I think, and I did not see a 405 being raised anywhere. I would double check and compare the python code to the rest code.

2. I'm missing unit tests on the rest code. How involved is adding this and updating CI?

3. Whats needed for a setup script that builds the rust component correctly before publishing?

4. How can we run integration tests locally?

5. What can of tooling should he added to `pre-commit`?

I'm tagging @peterschutt here so he gives input

Thank you for the comments, I will take a look at these later in the day and get back to you with some changes.

@nramos0
Copy link
Author

nramos0 commented Jul 11, 2022

I also have been working on an implementation as well, currently out-of-tree, I think we should work together to try to take the best of both worlds.

My implementation deviates from the original python one a fair bit in order to be more type-safe, and less stringly-typed. This looks more integrated with the existing repository though.

Absolutely. I was also wondering if there was a way to do this in a more type-safe way, and I'd be happy to collaborate on the implementation. I'll take a look at your code later today as well and see if we can talk about next steps.

@peterschutt
Copy link
Contributor

I'm tagging @peterschutt here so he gives input

Really keen to follow along as the work unfolds and happy to contribute where I can. Aside from actual implementations I think it makes sense to sink some time into:

  • settling on an interface and making the pure python implementation conform to that so that it's easy to plug in the different implementations
  • setting up benchmarks and bench-marking the pure python version so we have a base line
  • ensuring we have extensive behavioral tests

I'd be happy to contribute to any of those areas and if I can find the time I'd like to have a crack at cython and mypyc implementations to see how they compete on the benchmarks.

Also, I think this has the makings of a good blog:)

pyproject.toml Outdated Show resolved Hide resolved
starlite/app.py Outdated Show resolved Hide resolved
@nramos0
Copy link
Author

nramos0 commented Jul 12, 2022

First off, very nice stuff and thank you. It's a great first step. I left some comments -

1. Implementation is not identical I think, and I did not see a 405 being raised anywhere. I would double check and compare the python code to the rest code.

2. I'm missing unit tests on the rest code. How involved is adding this and updating CI?

3. Whats needed for a setup script that builds the rust component correctly before publishing?

4. How can we run integration tests locally?

5. What can of tooling should he added to `pre-commit`?

I'm tagging @peterschutt here so he gives input

To reply to some of your points the best I can here:

  1. I noticed that in the original code, MethodNotAllowedException is raised by StarliteASGIRouter.resolve_asgi_app, which I did not port to Rust and is still being called by StarliteASGIRouter.__call__. Should the resolution of the actual handler as done in resolve_asgi_app also be handled by the Rust code? When writing the extension, I wasn't sure to what extent I should move tasks out of the Python code and into the Rust code, so I only replaced up to StarliteASGIRouter.parse_scope_to_route.

  2. As the code stands, I'm not so certain about how we might go about writing pure Rust unit tests for the Rust component, since we would need to somehow mock the Starlite instance and others using PyO3. That is, the Rust code needs pieces from the Python environment that normal Rust unit tests wouldn't have access to. But we could probably do it either with maybe a Python wrapper (it seems possible that this could just be more tests in the ./tests/ directory that are directed at the Rust code?), or I think perhaps this might be possible with directly evaluating Python code (which PyO3 supports I believe, see here) to import and instantiate Starlite in Rust native tests before making calls to the instance.

  3. As far as I'm aware, a script running in the project's Poetry-instantiated virtual environment with all pyproject.toml dependencies installed should be able to run maturin build to generate native extension wheels. Then perhaps in the tool.poetry section of pyproject.toml there could be something like

include = [
    {path = "target/wheels/*.whl", format = "wheel"}
]

But when trying this and building the Starlite wheel with poetry build, and then installing the wheel in a new virtual environment, I get that the rust_backend module (the native extension's module name) cannot be found. Does anyone know what the problem might be here? Poetry doesn't seem to include the native extension wheel in the end Starlite wheel. The same happens trying to install the .tar.gz package. Will do more research on what is wrong with this.

  1. Are the integration tests the ones that run with pytest? If so, in a fresh install of my forked branch, the following works:
  • poetry shell
  • poetry install
  • maturin develop (assuming Rust is installed)
  • pytest
  1. Perhaps we can look at adding something that uses cargo fmt or cargo clippy, which are a Rust formatter and linter respectively. I'm not familiar with pre-commit and its config file

@Goldziher
Copy link
Contributor

First off, very nice stuff and thank you. It's a great first step. I left some comments -

1. Implementation is not identical I think, and I did not see a 405 being raised anywhere. I would double check and compare the python code to the rest code.

2. I'm missing unit tests on the rest code. How involved is adding this and updating CI?

3. Whats needed for a setup script that builds the rust component correctly before publishing?

4. How can we run integration tests locally?

5. What can of tooling should he added to `pre-commit`?

I'm tagging @peterschutt here so he gives input

To reply to some of your points the best I can here:

  1. I noticed that in the original code, MethodNotAllowedException is raised by StarliteASGIRouter.resolve_asgi_app, which I did not port to Rust and is still being called by StarliteASGIRouter.__call__. Should the resolution of the actual handler as done in resolve_asgi_app also be handled by the Rust code? When writing the extension, I wasn't sure to what extent I should move tasks out of the Python code and into the Rust code, so I only replaced up to StarliteASGIRouter.parse_scope_to_route.
  2. As the code stands, I'm not so certain about how we might go about writing pure Rust unit tests for the Rust component, since we would need to somehow mock the Starlite instance and others using PyO3. That is, the Rust code needs pieces from the Python environment that normal Rust unit tests wouldn't have access to. But we could probably do it either with maybe a Python wrapper (it seems possible that this could just be more tests in the ./tests/ directory that are directed at the Rust code?), or I think perhaps this might be possible with directly evaluating Python code (which PyO3 supports I believe, see here) to import and instantiate Starlite in Rust native tests before making calls to the instance.
  3. As far as I'm aware, a script running in the project's Poetry-instantiated virtual environment with all pyproject.toml dependencies installed should be able to run maturin build to generate native extension wheels. Then perhaps in the tool.poetry section of pyproject.toml there could be something like
include = [
    {path = "target/wheels/*.whl", format = "wheel"}
]

But when trying this and building the Starlite wheel with poetry build, and then installing the wheel in a new virtual environment, I get that the rust_backend module (the native extension's module name) cannot be found. Does anyone know what the problem might be here? Poetry doesn't seem to include the native extension wheel in the end Starlite wheel. The same happens trying to install the .tar.gz package. Will do more research on what is wrong with this.

  1. Are the integration tests the ones that run with pytest? If so, in a fresh install of my forked branch, the following works:
  • poetry shell
  • poetry install
  • maturin develop
  • pytest
  1. Perhaps we can look at adding something that uses cargo fmt or cargo clippy, which are a Rust formatter and linter respectively. I'm not familiar with pre-commit and its config file

Hi, so as to 1 - yes, there is little benefit in having the route map logic in rust and then do the parsing of routes in the ASGIRouter in python - this IS the bottleneck.

@nramos0
Copy link
Author

nramos0 commented Jul 12, 2022

First off, very nice stuff and thank you. It's a great first step. I left some comments -

1. Implementation is not identical I think, and I did not see a 405 being raised anywhere. I would double check and compare the python code to the rest code.

2. I'm missing unit tests on the rest code. How involved is adding this and updating CI?

3. Whats needed for a setup script that builds the rust component correctly before publishing?

4. How can we run integration tests locally?

5. What can of tooling should he added to `pre-commit`?

I'm tagging @peterschutt here so he gives input

To reply to some of your points the best I can here:

  1. I noticed that in the original code, MethodNotAllowedException is raised by StarliteASGIRouter.resolve_asgi_app, which I did not port to Rust and is still being called by StarliteASGIRouter.__call__. Should the resolution of the actual handler as done in resolve_asgi_app also be handled by the Rust code? When writing the extension, I wasn't sure to what extent I should move tasks out of the Python code and into the Rust code, so I only replaced up to StarliteASGIRouter.parse_scope_to_route.
  2. As the code stands, I'm not so certain about how we might go about writing pure Rust unit tests for the Rust component, since we would need to somehow mock the Starlite instance and others using PyO3. That is, the Rust code needs pieces from the Python environment that normal Rust unit tests wouldn't have access to. But we could probably do it either with maybe a Python wrapper (it seems possible that this could just be more tests in the ./tests/ directory that are directed at the Rust code?), or I think perhaps this might be possible with directly evaluating Python code (which PyO3 supports I believe, see here) to import and instantiate Starlite in Rust native tests before making calls to the instance.
  3. As far as I'm aware, a script running in the project's Poetry-instantiated virtual environment with all pyproject.toml dependencies installed should be able to run maturin build to generate native extension wheels. Then perhaps in the tool.poetry section of pyproject.toml there could be something like
include = [
    {path = "target/wheels/*.whl", format = "wheel"}
]

But when trying this and building the Starlite wheel with poetry build, and then installing the wheel in a new virtual environment, I get that the rust_backend module (the native extension's module name) cannot be found. Does anyone know what the problem might be here? Poetry doesn't seem to include the native extension wheel in the end Starlite wheel. The same happens trying to install the .tar.gz package. Will do more research on what is wrong with this.

  1. Are the integration tests the ones that run with pytest? If so, in a fresh install of my forked branch, the following works:
  • poetry shell
  • poetry install
  • maturin develop
  • pytest
  1. Perhaps we can look at adding something that uses cargo fmt or cargo clippy, which are a Rust formatter and linter respectively. I'm not familiar with pre-commit and its config file

Hi, so as to 1 - yes, there is little benefit in having the route map logic in rust and then do the parsing of routes in the ASGIRouter in python - this IS the bottleneck.

Alright, I will handle this as well

@Dr-Emann
Copy link
Contributor

I think I figured out building using poetry: https://github.com/nramos0/starlite/pull/1

@nramos0
Copy link
Author

nramos0 commented Jul 14, 2022

I think I figured out building using poetry: nramos0#1

Nice, I will take a look!

@nramos0
Copy link
Author

nramos0 commented Jul 14, 2022

I think I figured out building using poetry: nramos0#1

Seems to work out all fine for me, thanks, will merge now. Though I discovered I had a strange issue where I had to initialize the virtual environment with upgraded dependencies, since the default setuptools version was too old and didn't contain modules required by setuptools_rust, not sure if anyone else will run into this.

@nramos0
Copy link
Author

nramos0 commented Jul 14, 2022

Packaging now works thanks to @Dr-Emann's PR (and I also borrowed some of the external python type/function handle import logic from your implementation). Building is no longer done with maturin, but instead with setuptools_rust. Building the Rust extension for development needs a poetry install to rebuild every time there is a change in the Rust code. For packaging for release, poetry build as normal will do.

Additionally, I've renamed module to route_map_rs, which causes the imports of the proxy type and actual extension respectively to look like this

from starlite.route_map import RouteMap
from starlite.route_map_rs import RouteMap as RouteMapInit

Not sure if this would be a preferred naming convention / if there is a clearer way to add typings to the extension module. @Goldziher @vrslev

@nramos0
Copy link
Author

nramos0 commented Jul 14, 2022

Currently we are still missing Rust unit tests.

As for the running the pytest integration tests, the following now works:

  1. poetry shell
  2. poetry install
  3. pytest

However, if you get the same issue as me where setuptools.command.build is not found due to an old setuptools version installed in new virtual environments by default, running pip install --upgrade setuptools directly before poetry install works.

Harry-Lees and others added 7 commits July 27, 2022 01:06
* 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: update README.md [skip ci]

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

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
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.
@nramos0
Copy link
Author

nramos0 commented Jul 26, 2022

@nramos0 why did you close this issue and the PR? Was this a mistake?

@Goldziher Sorry about that, rebasing right now. I thought I'd move the commits to another branch, sync the fork's main branch and rebase within the fork. I haven't merged the branch back into this main branch yet so it appears github has automatically closed the PR

@nramos0 nramos0 reopened this Jul 26, 2022
@Goldziher Goldziher changed the base branch from main to rust-bindings July 26, 2022 17:48
@Goldziher Goldziher merged commit ab87e9a into litestar-org:rust-bindings Jul 26, 2022
Goldziher added a commit that referenced this pull request Aug 2, 2022
* 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>
Goldziher pushed a commit that referenced this pull request Aug 2, 2022
* 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
Goldziher pushed a commit that referenced this pull request Aug 2, 2022
* 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
Goldziher pushed a commit that referenced this pull request Aug 5, 2022
* 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
Dr-Emann pushed a commit to Dr-Emann/starlite that referenced this pull request Aug 8, 2022
…ngs (litestar-org#270)

* 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 (litestar-org#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 litestar-org#203

* updated dependencies

* Issue 187 layered parameters (litestar-org#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 (litestar-org#275) (litestar-org#277)

* added after_response (litestar-org#279)

* added after_response

* addressed review comments

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

* updated exception init

* add tests

* 1.6.2

* chore: updated maintainer list (litestar-org#285)

* docs: add cofin as a contributor for maintenance (litestar-org#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 litestar-org#255: allow single element query param in sequence types (litestar-org#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 (litestar-org#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 litestar-org#284

* Enhancement: Tortoise-ORM Plugin (litestar-org#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 (litestar-org#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 (litestar-org#302) (litestar-org#303)

* Support for SwaggerUI (litestar-org#302)

* Support for SwaggerUI

As per litestar-org#300

* Use built-in copy method

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

Tests for litestar-org#303 / litestar-org#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 (litestar-org#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 (litestar-org#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 (litestar-org#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 (litestar-org#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 (litestar-org#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 (litestar-org#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 (litestar-org#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
Goldziher pushed a commit that referenced this pull request Aug 8, 2022
* Issue #177: Add a baseline for Rust path resolution bindings (#270)

* 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

* First simple routing unit test

* Import less of starlite

The unit tests for the route_map extension should not need to
(transitively) import starlite.route_map

* Fix unit tests after rebase

* Simplify creation of routes

* Avoid stack overflow on drop

* Heavily refactor rust code

* Convert HandlerGroup to an enum

* Include cargo files in sdist

* Address comments

* Fix pytests added around static handlers

* Comment out slotscheck

Co-authored-by: Nicholas Ramos <35410160+nramos0@users.noreply.github.com>
Goldziher pushed a commit that referenced this pull request Aug 10, 2022
* Issue #177: Add a baseline for Rust path resolution bindings (#270)

* 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

* First simple routing unit test

* Import less of starlite

The unit tests for the route_map extension should not need to
(transitively) import starlite.route_map

* Fix unit tests after rebase

* Simplify creation of routes

* Avoid stack overflow on drop

* Heavily refactor rust code

* Convert HandlerGroup to an enum

* Include cargo files in sdist

* Address comments

* Fix pytests added around static handlers

* Comment out slotscheck

Co-authored-by: Nicholas Ramos <35410160+nramos0@users.noreply.github.com>

Issue #177: Add a baseline for Rust path resolution bindings (#270)

* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants