diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index a3bc99f..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Documentation - -on: - push: - branches: - - main - -jobs: - build-docs: - runs-on: ubuntu-18.04 - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.9" - - uses: actions/cache@v2 - id: cache - with: - path: ${{ env.pythonLocation }} - key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-docs - - name: Install Flit - if: steps.cache.outputs.cache-hit != 'true' - run: python3.9 -m pip install flit - - name: Install docs extras - if: steps.cache.outputs.cache-hit != 'true' - run: python3.9 -m flit install --deps production --extras docs - - name: Build docs - run: mkdocs build -d build - - - name: Deploy docs - uses: jsmrcaga/action-netlify-deploy@v1.1.0 - with: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - NETLIFY_DEPLOY_TO_PROD: true - NETLIFY_DEPLOY_MESSAGE: "Prod deploy v${{ github.ref }}" \ No newline at end of file diff --git a/Makefile b/Makefile index 5146ae3..7d1b223 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,7 @@ help: @echo "Targets:" - @echo " make setuptools" - @echo " make install" @echo " make test" - @echo " make build" @echo " make lint" - @echo " make publish" - @echo " make bumpversion-major" - @echo " make bumpversion-minor" - @echo " make bumpversion-patch" @echo " make clean" @echo " make clean-test" @@ -18,15 +11,6 @@ lint: test: pytest -bumpversion-major: - bumpversion major --allow-dirty - -bumpversion-minor: - bumpversion minor - -bumpversion-patch: - bumpversion patch - clean: find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyo' -exec rm -f {} + diff --git a/docs/code_of_conduct.md b/docs/code_of_conduct.md deleted file mode 100644 index 6de9ea2..0000000 --- a/docs/code_of_conduct.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at yasserth19@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/docs/contributing.md b/docs/contributing.md deleted file mode 100644 index ef6e91b..0000000 --- a/docs/contributing.md +++ /dev/null @@ -1,33 +0,0 @@ -## Development π§ - -You should create a virtual environment and activate it: - -```bash -python -m venv venv/ -``` - -```bash -source venv/bin/activate -``` - -And then install the development dependencies: - -```bash -pip install -r requirements.dev.txt -``` - -### Testing π¬ - -We Provide `pytest` for testing the Code, just run: - -```shell -pytest --cov=fastapi_class/ -``` - -### Format the code π - -Execute the following command to apply `pre-commit` formatting: - -```bash -make lint -``` \ No newline at end of file diff --git a/docs/favicon.png b/docs/favicon.png deleted file mode 100644 index 187bcf4..0000000 Binary files a/docs/favicon.png and /dev/null differ diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index ddd3e8a..0000000 --- a/docs/index.md +++ /dev/null @@ -1,79 +0,0 @@ -# Fastapi-Class π¦ - - - -
- Classes and Decorators to use FastAPI with Class based routing -
- -[](https://codecov.io/gh/yezz123/fastapi-class) -[](https://github.com/yezz123/fastapi-class/actions/workflows/test.yml) -[](https://badge.fury.io/py/fastapi-class) -[](https://pepy.tech/project/fastapi-class) -[](https://pepy.tech/project/fastapi-class) -[](https://github.com/yezz123) -[](https://fastapi.tiangolo.com/) -[](https://github.com/yezz123/fastapi-class) -[](https://pypi.org/project/fastapi-class) - ---- - -**Source Code**:
-
-The class is licensed under the [MIT License](https://opensource.org/licenses/mit)
-
-Copyright © 2021 [Yasser Tahiri](https://yezz.me)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the βSoftwareβ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED βAS ISβ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-* * *
diff --git a/docs/overview.md b/docs/overview.md
deleted file mode 100644
index 358a16c..0000000
--- a/docs/overview.md
+++ /dev/null
@@ -1,50 +0,0 @@
-# Deep Dive into Async Python
-
-## What Do "Sync" and "Async" Mean?
-
-Web applications often have to deal with many requests, all arriving from different clients and within a short period of time. To avoid processing delays it is considered a must that they should be able to handle several requests at the same time, something commonly known as concurrency. I will continue to use web applications as an example throughout this article, but keep in mind that there are other types of applications that also benefit from having multiple tasks done concurrently, so this discussion isn't specific to the web.
-
-The terms "sync" and "async" refer to two ways in which to write applications that use concurrency. The so called "sync" servers use the underlying operating system support of threads and processes to implement this concurrency. Here is a diagram of how a sync deployment might look:
-
-
-
-## Partial Object
-
-The "partial object" is a way to send a subset of an object to the client, the full concept is to provide a way to send a subset of an object to the client, and the client can then request the rest of the object. This is useful for sending a subset of an object to the client, and the client can then request the rest of the object.
-
-That why FastAPI Class allows you to construct an **instance** of a class and have methods of that instance be route handlers for FastAPI & Python 3.8.
-
-- Older Versions of Python:
- - Unfortunately this does not work with `async` routes with Python versions less than 3.8 [due to bugs in `inspect.iscoroutinefunction`](https://stackoverflow.com/a/52422903/1431244). Specifically with older versions of Python `iscoroutinefunction` incorrectly returns false so `async` routes aren't `await`'d. We therefore only support Python versions >= 3.8.
-
-## Why This?
-
-FastAPI generally has one define routes like:
-
-```py
-app = FastAPI()
-
-@app.get('/echo/{x}')
-def echo(x: int) -> int:
- return x
-```
-
-__Note:__ that `app` is a global. Furthermore, [FastAPI's suggested way of doing dependency injection](https://fastapi.tiangolo.com/tutorial/dependencies/classes-as-dependencies/) is handy for things like pulling values out of header in the HTTP request. However, they don't work well for more standard dependency injection scenarios where we'd like to do something like inject a Data Access Object or database connection. For that, FastAPI suggests [their parameterized dependencies](https://fastapi.tiangolo.com/advanced/advanced-dependencies/) which might look something like:
-
-```py
-app = FastAPI()
-
-class ValueToInject:
- # Value to inject into the function.
- def __init__(self, y: int) -> None:
- self.y = y
-
- def __call__(self) -> int:
- return self.y
-
-to_add = ValueToInject(2)
-
-@app.get('/add/{x}')
-def add(x: int, y: Depends(to_add)) -> int:
- return x + y
-```
diff --git a/fastapi_class/decorators.py b/fastapi_class/decorators.py
index 7fc9fde..837585e 100644
--- a/fastapi_class/decorators.py
+++ b/fastapi_class/decorators.py
@@ -1,3 +1,4 @@
+import inspect
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Sequence, Type, TypeVar, Union
@@ -24,13 +25,13 @@ def route(
"""
def marker(method: AnyCallable) -> AnyCallable:
- setattr(
- method,
- "_endpoint",
- EndpointDefinition(
- endpoint=method, args=RouteArgs(path=path, methods=methods, **kwargs)
- ),
- )
+ args = RouteArgs(path=path, methods=methods, **kwargs)
+ if args.name is None:
+ args.name = method.__name__
+ if not args.description:
+ description = inspect.cleandoc(method.__doc__ or "")
+ args.description = description or " "
+ setattr(method, "_endpoint", EndpointDefinition(endpoint=method, args=args))
return method
return marker
@@ -144,7 +145,7 @@ def post(
)
-def put(
+def patch(
path: str,
*,
response_model: Optional[Type[Any]] = None,
@@ -172,7 +173,7 @@ def put(
) -> Callable[[AnyCallable], AnyCallable]:
return route(
path,
- methods=["PUT"],
+ methods=["PATCH"],
response_model=response_model,
status_code=status_code,
tags=tags,
@@ -198,7 +199,7 @@ def put(
)
-def delete(
+def put(
path: str,
*,
response_model: Optional[Type[Any]] = None,
@@ -226,7 +227,7 @@ def delete(
) -> Callable[[AnyCallable], AnyCallable]:
return route(
path,
- methods=["DELETE"],
+ methods=["PUT"],
response_model=response_model,
status_code=status_code,
tags=tags,
@@ -252,7 +253,7 @@ def delete(
)
-def patch(
+def delete(
path: str,
*,
response_model: Optional[Type[Any]] = None,
@@ -280,7 +281,7 @@ def patch(
) -> Callable[[AnyCallable], AnyCallable]:
return route(
path,
- methods=["PATCH"],
+ methods=["DELETE"],
response_model=response_model,
status_code=status_code,
tags=tags,
diff --git a/fastapi_class/routable.py b/fastapi_class/routable.py
index 199dd82..252abcd 100644
--- a/fastapi_class/routable.py
+++ b/fastapi_class/routable.py
@@ -9,14 +9,6 @@
AnyCallable = TypeVar("AnyCallable", bound=Callable[..., Any])
-"""
- This module contains the `Routable` class, which is used to define a class
-
- Returns:
- [Routable]: A class that can be used to define a routable class
-
-"""
-
class RoutableMeta(type):
"""This is a meta-class that converts all the methods that were marked by a route/path decorator into values on a
@@ -32,29 +24,23 @@ def __new__(
]
attrs["_endpoints"] = endpoints
- # Remove the _endpoint attribute from the class
return cast(RoutableMeta, type.__new__(cls, name, bases, attrs))
class Routable(metaclass=RoutableMeta):
- """
- - The Routable class is a base class for all the classes that are to be used as the base for the API.
- - The Routable class is a metaclass that converts all the methods that were marked by a route/path decorator into
- values on a class member called _endpoints that the Routable constructor then uses to add the endpoints to its
- router.
+ """Base class for all classes the want class-based routing.
+
+ This Uses RoutableMeta as a metaclass and various decorators like @get or @post from the decorators module. The
+ decorators just mark a method as an endpoint. The RoutableMeta then converts those to a list of desired endpoints in
+ the _endpoints class method during class creation. The constructor constructs an APIRouter and adds all the routes
+ in the _endpoints to it so they can be added to an app via FastAPI.include_router or similar.
"""
- _endpoints: List[EndpointDefinition] = [
- # This is a list of all the endpoints that the class has defined
- # TODO: This should be a list of EndpointDefinition objects
- ]
+ _endpoints: List[EndpointDefinition] = []
- def __init__(self) -> None:
- # Create a router for the class
- self.router = APIRouter()
- # Loop through all the endpoints in the class
+ def __init__(self, *args, **kwargs) -> None:
+ self.router = APIRouter(*args, **kwargs)
for endpoint in self._endpoints:
- # The endpoint is a tuple of the endpoint name and the endpoint function
self.router.add_api_route(
endpoint=partial(endpoint.endpoint, self),
**dataclasses.asdict(endpoint.args),
diff --git a/mkdocs.yml b/mkdocs.yml
deleted file mode 100644
index 3a4a2d8..0000000
--- a/mkdocs.yml
+++ /dev/null
@@ -1,72 +0,0 @@
-site_name: FastAPI Class
-site_description: Generate Class & Decorators for your FastAPI project β‘
-site_url: https://yezz123.github.io/fastapi-class/
-
-theme:
- name: 'material'
- palette:
- - scheme: default
- primary: teal
- accent: amber
- toggle:
- icon: material/lightbulb
- name: Switch to dark mode
- - scheme: slate
- primary: teal
- accent: amber
- toggle:
- icon: material/lightbulb-outline
- name: Switch to light mode
- icon:
- logo: material/bird
- favicon: favicon.png
-
-repo_name: yezz123/fastapi-class
-repo_url: https://github.com/yezz123/fastapi-class
-edit_uri: ""
-
-
-markdown_extensions:
- - markdown_include.include:
- base_path: docs
- - toc:
- permalink: true
- - admonition
- - codehilite
- - pymdownx.superfences:
- custom_fences:
- - name: mermaid
- class: mermaid
- format: !!python/name:mermaid2.fence_mermaid
- - pymdownx.tasklist
- - pymdownx.tabbed
-
-plugins:
- - search
- - mermaid2:
- arguments:
- theme: |
- ^(JSON.parse(window.localStorage.getItem('/.__palette')).index == 1) ? 'dark' : 'light'
-extra_javascript:
- - https://unpkg.com/mermaid/dist/mermaid.min.js
-
-nav:
- - About: index.md
- - installation.md
- - Overview: overview.md
- - Development - Contributing: contributing.md
- - Code of Conduct: code_of_conduct.md
- - License: license.md
-
-extra:
- social:
- - icon: fontawesome/brands/github-alt
- link: https://github.com/yezz123
- - icon: fontawesome/brands/discord
- link: https://discord.gg/2hdSWVgNPH
- - icon: fontawesome/brands/twitter
- link: https://twitter.com/THyasser1
- - icon: fontawesome/brands/linkedin
- link: https://www.linkedin.com/in/yezz123
- - icon: fontawesome/solid/globe
- link: https://yezz.me
diff --git a/pyproject.toml b/pyproject.toml
index 2aa5fb9..261717b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -39,16 +39,6 @@ test = [
"codecov",
"pytest-cov"
]
-docs = [
- "mkdocs == 1.2.3",
- "mkdocs-material==8.1.4",
- "mkdocs-markdownextradata-plugin==0.2.5",
- "mkdocs-mermaid2-plugin==0.5.2",
- "markdown-include==0.6.0",
- "pymdown-extensions==9.1",
- "mdx-include==1.4.1",
- "jinja2==3.0.3"
-]
[tool.flit.metadata.urls]
-Documentation = "https://yezz123.github.io/fastapi-class/"
\ No newline at end of file
+Documentation = "https://github.com/yezz123/fastapi-class/blob/main/README.md"
\ No newline at end of file