From d97f4749ccc745a7a2df12a608eac3aa71078b29 Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Mon, 2 May 2022 17:18:47 +0100 Subject: [PATCH 1/5] Add type stubs --- robyn/__init__.py | 2 +- robyn/__init__.pyi | 149 ++++++++++++++++++++++++++++++ robyn/argument_parser.pyi | 16 ++++ robyn/dev_event_handler.pyi | 18 ++++ robyn/events.pyi | 3 + robyn/log_colors.pyi | 10 ++ robyn/processpool.py | 2 +- robyn/processpool.pyi | 30 ++++++ robyn/py.typed | 0 robyn/responses.pyi | 21 +++++ robyn/robyn.cpython-38-darwin.pyi | 126 +++++++++++++++++++++++++ robyn/robyn.pyi | 65 +++++++++++++ robyn/router.pyi | 48 ++++++++++ robyn/test_robyn.py | 14 --- robyn/ws.pyi | 11 +++ 15 files changed, 499 insertions(+), 16 deletions(-) create mode 100644 robyn/__init__.pyi create mode 100644 robyn/argument_parser.pyi create mode 100644 robyn/dev_event_handler.pyi create mode 100644 robyn/events.pyi create mode 100644 robyn/log_colors.pyi create mode 100644 robyn/processpool.pyi create mode 100644 robyn/py.typed create mode 100644 robyn/responses.pyi create mode 100644 robyn/robyn.cpython-38-darwin.pyi create mode 100644 robyn/robyn.pyi create mode 100644 robyn/router.pyi delete mode 100644 robyn/test_robyn.py create mode 100644 robyn/ws.pyi diff --git a/robyn/__init__.py b/robyn/__init__.py index bec6cfb52..f642e9b01 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -6,7 +6,7 @@ from robyn.events import Events # custom imports and exports -from .robyn import Server, SocketHeld +from .robyn import SocketHeld from .argument_parser import ArgumentParser from .responses import static_file, jsonify from .dev_event_handler import EventHandler diff --git a/robyn/__init__.pyi b/robyn/__init__.pyi new file mode 100644 index 000000000..35bd728c9 --- /dev/null +++ b/robyn/__init__.pyi @@ -0,0 +1,149 @@ +import os +import asyncio +import multiprocessing as mp +from inspect import signature +from robyn.events import Events +from .robyn import Server, SocketHeld +from .argument_parser import ArgumentParser +from .responses import jsonify, static_file +from .dev_event_handler import EventHandler +from .processpool import spawn_process +from .log_colors import Colors +from .ws import WS +from .router import MiddlewareRouter, Router, WebSocketRouter +from multiprocess import Process +from watchdog.observers import Observer + +from typing import Callable + +class Robyn: + """This is the python wrapper for the Robyn binaries.""" + + def __init__(self, file_object: str) -> None: + pass + + def before_request(self, endpoint: str): # -> (handler: Unknown) -> None: + """ + [The @app.before_request decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def after_request(self, endpoint: str): # -> (handler: Unknown) -> None: + """ + [The @app.after_request decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def add_directory( + self, + route: str, + directory_path: str, + index_file: str = ..., + show_files_listing: str = ..., + ): + pass + + def add_header(self, key: str, value: str) -> None: + pass + + def add_web_socket(self, endpoint: str, ws: WS) -> None: + pass + + def startup_handler(self, handler: Callable) -> None: + pass + + def shutdown_handler(self, handler: Callable) -> None: + pass + + def start(self, url: str = ..., port: int = ...) -> None: + """ + [Starts the server] + + :param port [int]: [reperesents the port number at which the server is listening] + """ + + pass + + def get(self, endpoint: str): # -> (handler: Unknown) -> None: + """ + [The @app.get decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + pass + + def post(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.post decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + pass + + def put(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.put decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def delete(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.delete decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def patch(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.patch decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def head(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.head decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def options(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.options decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass + + def connect(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.connect decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + pass + + def trace(self, endpoint: str) -> Callable[..., None]: + """ + [The @app.trace decorator to add a get route] + + :param endpoint [str]: [endpoint to server the route] + """ + + pass diff --git a/robyn/argument_parser.pyi b/robyn/argument_parser.pyi new file mode 100644 index 000000000..204f02424 --- /dev/null +++ b/robyn/argument_parser.pyi @@ -0,0 +1,16 @@ +import argparse + + +class ArgumentParser(argparse.ArgumentParser): + + def __init__(self) -> None: + pass + + def num_processes(self): + pass + + def workers(self): + pass + + def is_dev(self): + pass diff --git a/robyn/dev_event_handler.pyi b/robyn/dev_event_handler.pyi new file mode 100644 index 000000000..f3f23d0ec --- /dev/null +++ b/robyn/dev_event_handler.pyi @@ -0,0 +1,18 @@ +from watchdog.events import FileSystemEventHandler, FileSystemEvent + + +class EventHandler(FileSystemEventHandler): + def __init__(self, file_name: str) -> None: + pass + + def start_server_first_time(self): # -> None: + pass + + def on_any_event(self, event: FileSystemEvent): # -> None: + """ + [This function is a callback that will start a new server on every even change] + + :param event [FSEvent]: [a data structure with info about the events] + """ + + pass diff --git a/robyn/events.pyi b/robyn/events.pyi new file mode 100644 index 000000000..4a2a04291 --- /dev/null +++ b/robyn/events.pyi @@ -0,0 +1,3 @@ +class Events: + STARTUP = ... + SHUTDOWN = ... diff --git a/robyn/log_colors.pyi b/robyn/log_colors.pyi new file mode 100644 index 000000000..1ed12ab9c --- /dev/null +++ b/robyn/log_colors.pyi @@ -0,0 +1,10 @@ +class Colors: + HEADER = ... + OKBLUE = ... + OKCYAN = ... + OKGREEN = ... + WARNING = ... + FAIL = ... + ENDC = ... + BOLD = ... + UNDERLINE = ... diff --git a/robyn/processpool.py b/robyn/processpool.py index 88f96c469..4534eb80a 100644 --- a/robyn/processpool.py +++ b/robyn/processpool.py @@ -24,7 +24,7 @@ def spawn_process( :param middlewares tuple: The middleware router touple, containing the description about every route. :param web_sockets list: This is a list of all the web socket routes :param event_handlers Dict: This is an event dict that contains the event handlers - :param socket Socket: This is the main tcp socket, which is being shared across multiple processes. + :param socket SocketHeld: This is the main tcp socket, which is being shared across multiple processes. :param process_name string: This is the name given to the process to identify the process :param workers number: This is the name given to the process to identify the process """ diff --git a/robyn/processpool.pyi b/robyn/processpool.pyi new file mode 100644 index 000000000..f431787b4 --- /dev/null +++ b/robyn/processpool.pyi @@ -0,0 +1,30 @@ +from numbers import Number +from robyn.robyn import SocketHeld + + +def spawn_process( + directories: tuple, + headers: tuple, + routes: tuple, + middlewares: tuple, + web_sockets: list, + event_handlers: dict, + socket: SocketHeld, + workers: Number, +) -> None: + """ + This function is called by the main process handler to create a server runtime. + This functions allows one runtime per process. + + :param directories tuple: the list of all the directories and related data in a tuple + :param headers tuple: All the global headers in a tuple + :param routes tuple: The routes touple, containing the description about every route. + :param middlewares tuple: The middleware router touple, containing the description about every route. + :param web_sockets list: This is a list of all the web socket routes + :param event_handlers Dict: This is an event dict that contains the event handlers + :param socket SocketHeld: This is the main tcp socket, which is being shared across multiple processes. + :param process_name string: This is the name given to the process to identify the process + :param workers number: This is the name given to the process to identify the process + """ + + pass diff --git a/robyn/py.typed b/robyn/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/robyn/responses.pyi b/robyn/responses.pyi new file mode 100644 index 000000000..6e24ac2bf --- /dev/null +++ b/robyn/responses.pyi @@ -0,0 +1,21 @@ +from typing import Any + + +def static_file(file_path: str) -> dict[str, Any]: + """ + [This function will help in serving a static_file] + + :param file_path [str]: [file path to serve as a response] + """ + + pass + + +def jsonify(input_dict: dict) -> str: + """ + [This function serializes input dict to a json string] + + :param input_dict [dict]: [response of the function] + """ + + pass diff --git a/robyn/robyn.cpython-38-darwin.pyi b/robyn/robyn.cpython-38-darwin.pyi new file mode 100644 index 000000000..21d487d73 --- /dev/null +++ b/robyn/robyn.cpython-38-darwin.pyi @@ -0,0 +1,126 @@ +""" +This type stub file was generated by pyright. +""" + +L = ... +@ +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +D = ... +@z +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +w: y +R: y +c: _ +@4 +class : + ... + + +@uh +class : + ... + + +@Vh +class : + ... + + +Z = ... +@C +class : + ... + + +@H +class : + ... + + +pn: +af: +@ +@ +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +wK = ... +X = ... +@ +class : + ... + + +I = ... +@ +class : + ... + + +@ +class : + ... + + +@ +class : + ... + + +@E +class : + ... + + diff --git a/robyn/robyn.pyi b/robyn/robyn.pyi new file mode 100644 index 000000000..245c38603 --- /dev/null +++ b/robyn/robyn.pyi @@ -0,0 +1,65 @@ +from __future__ import annotations +from typing import Callable, Optional, Tuple + + +class SocketHeld: + def __init__(self, url: str, port: int): + pass + + def try_clone(self) -> SocketHeld: + pass + + +class Server: + def __init__(self): + pass + + def add_directory( + self, + route: str, + directory_path: str, + index_file: Optional[str], + show_files_listing: bool, + ): + pass + + def add_header(self, key: str, value: str): + pass + + def add_route( + self, + route_type: str, + route: str, + handler: Callable, + is_async: bool, + number_of_params: int, + ): + pass + + def add_middleware_route( + self, + route_type: str, + route: str, + handler: Callable, + is_async: bool, + number_of_params: int, + ): + pass + + def add_startup_handler(self, handler: Callable, is_async: bool): + pass + + def add_shutdown_handler(self, handler: Callable, is_async: bool): + pass + + def add_web_socket_route( + self, + route: str, + connect_route: Tuple[Callable, bool, int], + close_route: Tuple[Callable, bool, int], + message_route: Tuple[Callable, bool, int], + ): + pass + + def start(self, socket: SocketHeld, workers: int): + pass diff --git a/robyn/router.pyi b/robyn/router.pyi new file mode 100644 index 000000000..6ed4679fd --- /dev/null +++ b/robyn/router.pyi @@ -0,0 +1,48 @@ +from abc import ABC, abstractmethod +from robyn.ws import WS +from typing import Callable + + +class BaseRouter(ABC): + @abstractmethod + def add_route(*args) -> None: + pass + + +class Router(BaseRouter): + def __init__(self) -> None: + pass + + def add_route(self, route_type: str, endpoint: str, handler: Callable) -> None: + pass + + def get_routes(self) -> list: + pass + + +class MiddlewareRouter(BaseRouter): + def __init__(self) -> None: + pass + + def add_route(self, route_type: str, endpoint: str, handler: Callable) -> None: + pass + + def add_after_request(self, endpoint: str) -> Callable[..., None]: + pass + + def add_before_request(self, endpoint: str) -> Callable[..., None]: + pass + + def get_routes(self) -> list: + pass + + +class WebSocketRouter(BaseRouter): + def __init__(self) -> None: + pass + + def add_route(self, endpoint: str, web_socket: WS) -> None: + pass + + def get_routes(self) -> dict[str, WS]: + pass diff --git a/robyn/test_robyn.py b/robyn/test_robyn.py deleted file mode 100644 index 1f28f17e9..000000000 --- a/robyn/test_robyn.py +++ /dev/null @@ -1,14 +0,0 @@ -from robyn import Robyn -import os - -app = Robyn(__file__) - - -def test_directory_path(): - assert app.directory_path == os.path.dirname(os.path.abspath(__file__)) - - -def test_file_path(): - assert app.file_path == __file__ - - diff --git a/robyn/ws.pyi b/robyn/ws.pyi new file mode 100644 index 000000000..7bf90db2d --- /dev/null +++ b/robyn/ws.pyi @@ -0,0 +1,11 @@ +from robyn import Robyn + + +class WS: + """This is the python wrapper for the web socket that will be used here. + """ + def __init__(self, robyn_object: Robyn, endpoint: str) -> None: + pass + + def on(self, type: str): + pass From 04aa1e317d86ee298a9351182a6628725eedd978 Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sat, 7 May 2022 01:05:18 +0100 Subject: [PATCH 2/5] Fix type stubs --- robyn/__init__.pyi | 85 ++++++++++---------- robyn/argument_parser.pyi | 8 +- robyn/dev_event_handler.pyi | 10 +-- robyn/processpool.pyi | 22 ++++-- robyn/robyn.cpython-38-darwin.pyi | 126 ------------------------------ robyn/router.pyi | 4 +- 6 files changed, 68 insertions(+), 187 deletions(-) delete mode 100644 robyn/robyn.cpython-38-darwin.pyi diff --git a/robyn/__init__.pyi b/robyn/__init__.pyi index 35bd728c9..9a7684617 100644 --- a/robyn/__init__.pyi +++ b/robyn/__init__.pyi @@ -16,20 +16,21 @@ from watchdog.observers import Observer from typing import Callable + class Robyn: """This is the python wrapper for the Robyn binaries.""" def __init__(self, file_object: str) -> None: - pass + ... - def before_request(self, endpoint: str): # -> (handler: Unknown) -> None: + def before_request(self, endpoint: str) -> Callable[..., None]: """ - [The @app.before_request decorator to add a get route] + The @app.before_request decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def after_request(self, endpoint: str): # -> (handler: Unknown) -> None: """ @@ -38,7 +39,7 @@ class Robyn: :param endpoint [str]: [endpoint to server the route] """ - pass + ... def add_directory( self, @@ -47,103 +48,103 @@ class Robyn: index_file: str = ..., show_files_listing: str = ..., ): - pass + ... def add_header(self, key: str, value: str) -> None: - pass + ... def add_web_socket(self, endpoint: str, ws: WS) -> None: - pass + ... def startup_handler(self, handler: Callable) -> None: - pass + ... def shutdown_handler(self, handler: Callable) -> None: - pass + ... def start(self, url: str = ..., port: int = ...) -> None: """ - [Starts the server] + Starts the server - :param port [int]: [reperesents the port number at which the server is listening] + :param port int: reperesents the port number at which the server is listening """ - pass + ... - def get(self, endpoint: str): # -> (handler: Unknown) -> None: + def get(self, endpoint: str) -> Callable[..., None]: """ - [The @app.get decorator to add a get route] + The @app.get decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def post(self, endpoint: str) -> Callable[..., None]: """ - [The @app.post decorator to add a get route] + The @app.post decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def put(self, endpoint: str) -> Callable[..., None]: """ - [The @app.put decorator to add a get route] + The @app.put decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def delete(self, endpoint: str) -> Callable[..., None]: """ - [The @app.delete decorator to add a get route] + The @app.delete decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def patch(self, endpoint: str) -> Callable[..., None]: """ - [The @app.patch decorator to add a get route] + The @app.patch decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def head(self, endpoint: str) -> Callable[..., None]: """ - [The @app.head decorator to add a get route] + The @app.head decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def options(self, endpoint: str) -> Callable[..., None]: """ - [The @app.options decorator to add a get route] + The @app.options decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def connect(self, endpoint: str) -> Callable[..., None]: """ - [The @app.connect decorator to add a get route] + The @app.connect decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... def trace(self, endpoint: str) -> Callable[..., None]: """ - [The @app.trace decorator to add a get route] + The @app.trace decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - pass + ... diff --git a/robyn/argument_parser.pyi b/robyn/argument_parser.pyi index 204f02424..1e58fc857 100644 --- a/robyn/argument_parser.pyi +++ b/robyn/argument_parser.pyi @@ -4,13 +4,13 @@ import argparse class ArgumentParser(argparse.ArgumentParser): def __init__(self) -> None: - pass + ... def num_processes(self): - pass + ... def workers(self): - pass + ... def is_dev(self): - pass + ... diff --git a/robyn/dev_event_handler.pyi b/robyn/dev_event_handler.pyi index f3f23d0ec..59371fce4 100644 --- a/robyn/dev_event_handler.pyi +++ b/robyn/dev_event_handler.pyi @@ -3,16 +3,14 @@ from watchdog.events import FileSystemEventHandler, FileSystemEvent class EventHandler(FileSystemEventHandler): def __init__(self, file_name: str) -> None: - pass + ... - def start_server_first_time(self): # -> None: - pass + def start_server_first_time(self) -> None: + ... - def on_any_event(self, event: FileSystemEvent): # -> None: + def on_any_event(self, event: FileSystemEvent) -> None: """ [This function is a callback that will start a new server on every even change] :param event [FSEvent]: [a data structure with info about the events] """ - - pass diff --git a/robyn/processpool.pyi b/robyn/processpool.pyi index f431787b4..8d6fe3f68 100644 --- a/robyn/processpool.pyi +++ b/robyn/processpool.pyi @@ -1,14 +1,20 @@ from numbers import Number +from robyn.ws import WS +from robyn.events import Events from robyn.robyn import SocketHeld +from typing import Dict, Tuple, Callable + +Route = Tuple[str, str, Callable, bool, int] + def spawn_process( - directories: tuple, - headers: tuple, - routes: tuple, - middlewares: tuple, - web_sockets: list, - event_handlers: dict, + directories: Tuple[str, str, str, str], + headers: Tuple[str, str], + routes: Tuple[Route], + middlewares: Tuple[Route], + web_sockets: Dict[str, WS], + event_handlers: Dict[Events, list], socket: SocketHeld, workers: Number, ) -> None: @@ -18,8 +24,8 @@ def spawn_process( :param directories tuple: the list of all the directories and related data in a tuple :param headers tuple: All the global headers in a tuple - :param routes tuple: The routes touple, containing the description about every route. - :param middlewares tuple: The middleware router touple, containing the description about every route. + :param routes Tuple[Route]: The routes touple, containing the description about every route. + :param middlewares Tuple[Route]: The middleware router touple, containing the description about every route. :param web_sockets list: This is a list of all the web socket routes :param event_handlers Dict: This is an event dict that contains the event handlers :param socket SocketHeld: This is the main tcp socket, which is being shared across multiple processes. diff --git a/robyn/robyn.cpython-38-darwin.pyi b/robyn/robyn.cpython-38-darwin.pyi deleted file mode 100644 index 21d487d73..000000000 --- a/robyn/robyn.cpython-38-darwin.pyi +++ /dev/null @@ -1,126 +0,0 @@ -""" -This type stub file was generated by pyright. -""" - -L = ... -@ -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -D = ... -@z -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -w: y -R: y -c: _ -@4 -class : - ... - - -@uh -class : - ... - - -@Vh -class : - ... - - -Z = ... -@C -class : - ... - - -@H -class : - ... - - -pn: -af: -@ -@ -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -wK = ... -X = ... -@ -class : - ... - - -I = ... -@ -class : - ... - - -@ -class : - ... - - -@ -class : - ... - - -@E -class : - ... - - diff --git a/robyn/router.pyi b/robyn/router.pyi index 6ed4679fd..c157d2b30 100644 --- a/robyn/router.pyi +++ b/robyn/router.pyi @@ -1,6 +1,8 @@ from abc import ABC, abstractmethod from robyn.ws import WS -from typing import Callable +from typing import Callable, List, Tuple + +Routes = List[Tuple[str, str, Callable, bool, int]] class BaseRouter(ABC): From 010f35412f358ab4fbd9331e2337059d5e54244a Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sat, 7 May 2022 03:50:11 +0100 Subject: [PATCH 3/5] Fix type stubs final --- robyn/processpool.pyi | 10 ++++++---- robyn/router.pyi | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/robyn/processpool.pyi b/robyn/processpool.pyi index 8d6fe3f68..39584eca6 100644 --- a/robyn/processpool.pyi +++ b/robyn/processpool.pyi @@ -6,13 +6,15 @@ from robyn.robyn import SocketHeld from typing import Dict, Tuple, Callable Route = Tuple[str, str, Callable, bool, int] +Directory = Tuple[str, str, str, str] +Header = Tuple[str, str] def spawn_process( - directories: Tuple[str, str, str, str], - headers: Tuple[str, str], - routes: Tuple[Route], - middlewares: Tuple[Route], + directories: Tuple[Directory, ...], + headers: Tuple[Header, ...], + routes: Tuple[Route, ...], + middlewares: Tuple[Route, ...], web_sockets: Dict[str, WS], event_handlers: Dict[Events, list], socket: SocketHeld, diff --git a/robyn/router.pyi b/robyn/router.pyi index c157d2b30..6ed4679fd 100644 --- a/robyn/router.pyi +++ b/robyn/router.pyi @@ -1,8 +1,6 @@ from abc import ABC, abstractmethod from robyn.ws import WS -from typing import Callable, List, Tuple - -Routes = List[Tuple[str, str, Callable, bool, int]] +from typing import Callable class BaseRouter(ABC): From 386ebe86a829e4ba3bf7650042c9d6d7f2e7351d Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sun, 8 May 2022 14:10:01 +0100 Subject: [PATCH 4/5] Remove generic type stubs --- robyn/__init__.pyi | 56 +++++++++++-------------------------- robyn/argument_parser.pyi | 17 +++-------- robyn/dev_event_handler.pyi | 11 ++------ robyn/processpool.pyi | 11 +++----- robyn/responses.pyi | 2 -- robyn/robyn.pyi | 12 +------- robyn/router.pyi | 19 ++++--------- robyn/ws.pyi | 6 ++-- 8 files changed, 36 insertions(+), 98 deletions(-) diff --git a/robyn/__init__.pyi b/robyn/__init__.pyi index 9a7684617..7522fd34b 100644 --- a/robyn/__init__.pyi +++ b/robyn/__init__.pyi @@ -1,28 +1,27 @@ -import os import asyncio import multiprocessing as mp +import os from inspect import signature +from typing import Callable + +from multiprocess import Process +from watchdog.observers import Observer + from robyn.events import Events -from .robyn import Server, SocketHeld + from .argument_parser import ArgumentParser -from .responses import jsonify, static_file from .dev_event_handler import EventHandler -from .processpool import spawn_process from .log_colors import Colors -from .ws import WS +from .processpool import spawn_process +from .responses import jsonify, static_file +from .robyn import Server, SocketHeld from .router import MiddlewareRouter, Router, WebSocketRouter -from multiprocess import Process -from watchdog.observers import Observer - -from typing import Callable - +from .ws import WS class Robyn: """This is the python wrapper for the Robyn binaries.""" - def __init__(self, file_object: str) -> None: - ... - + def __init__(self, file_object: str) -> None: ... def before_request(self, endpoint: str) -> Callable[..., None]: """ The @app.before_request decorator to add a get route @@ -31,7 +30,6 @@ class Robyn: """ ... - def after_request(self, endpoint: str): # -> (handler: Unknown) -> None: """ [The @app.after_request decorator to add a get route] @@ -40,28 +38,17 @@ class Robyn: """ ... - def add_directory( self, route: str, directory_path: str, index_file: str = ..., show_files_listing: str = ..., - ): - ... - - def add_header(self, key: str, value: str) -> None: - ... - - def add_web_socket(self, endpoint: str, ws: WS) -> None: - ... - - def startup_handler(self, handler: Callable) -> None: - ... - - def shutdown_handler(self, handler: Callable) -> None: - ... - + ): ... + def add_header(self, key: str, value: str) -> None: ... + def add_web_socket(self, endpoint: str, ws: WS) -> None: ... + def startup_handler(self, handler: Callable) -> None: ... + def shutdown_handler(self, handler: Callable) -> None: ... def start(self, url: str = ..., port: int = ...) -> None: """ Starts the server @@ -70,7 +57,6 @@ class Robyn: """ ... - def get(self, endpoint: str) -> Callable[..., None]: """ The @app.get decorator to add a get route @@ -78,7 +64,6 @@ class Robyn: :param endpoint str: endpoint to server the route """ ... - def post(self, endpoint: str) -> Callable[..., None]: """ The @app.post decorator to add a get route @@ -86,7 +71,6 @@ class Robyn: :param endpoint str: endpoint to server the route """ ... - def put(self, endpoint: str) -> Callable[..., None]: """ The @app.put decorator to add a get route @@ -95,7 +79,6 @@ class Robyn: """ ... - def delete(self, endpoint: str) -> Callable[..., None]: """ The @app.delete decorator to add a get route @@ -104,7 +87,6 @@ class Robyn: """ ... - def patch(self, endpoint: str) -> Callable[..., None]: """ The @app.patch decorator to add a get route @@ -113,7 +95,6 @@ class Robyn: """ ... - def head(self, endpoint: str) -> Callable[..., None]: """ The @app.head decorator to add a get route @@ -122,7 +103,6 @@ class Robyn: """ ... - def options(self, endpoint: str) -> Callable[..., None]: """ The @app.options decorator to add a get route @@ -131,7 +111,6 @@ class Robyn: """ ... - def connect(self, endpoint: str) -> Callable[..., None]: """ The @app.connect decorator to add a get route @@ -139,7 +118,6 @@ class Robyn: :param endpoint str: endpoint to server the route """ ... - def trace(self, endpoint: str) -> Callable[..., None]: """ The @app.trace decorator to add a get route diff --git a/robyn/argument_parser.pyi b/robyn/argument_parser.pyi index 1e58fc857..2125f1979 100644 --- a/robyn/argument_parser.pyi +++ b/robyn/argument_parser.pyi @@ -1,16 +1,7 @@ import argparse - class ArgumentParser(argparse.ArgumentParser): - - def __init__(self) -> None: - ... - - def num_processes(self): - ... - - def workers(self): - ... - - def is_dev(self): - ... + def __init__(self) -> None: ... + def num_processes(self): ... + def workers(self): ... + def is_dev(self): ... diff --git a/robyn/dev_event_handler.pyi b/robyn/dev_event_handler.pyi index 59371fce4..88bcb567a 100644 --- a/robyn/dev_event_handler.pyi +++ b/robyn/dev_event_handler.pyi @@ -1,13 +1,8 @@ -from watchdog.events import FileSystemEventHandler, FileSystemEvent - +from watchdog.events import FileSystemEvent, FileSystemEventHandler class EventHandler(FileSystemEventHandler): - def __init__(self, file_name: str) -> None: - ... - - def start_server_first_time(self) -> None: - ... - + def __init__(self, file_name: str) -> None: ... + def start_server_first_time(self) -> None: ... def on_any_event(self, event: FileSystemEvent) -> None: """ [This function is a callback that will start a new server on every even change] diff --git a/robyn/processpool.pyi b/robyn/processpool.pyi index 39584eca6..04764dc8d 100644 --- a/robyn/processpool.pyi +++ b/robyn/processpool.pyi @@ -1,15 +1,14 @@ from numbers import Number -from robyn.ws import WS +from typing import Dict, Tuple + from robyn.events import Events from robyn.robyn import SocketHeld +from robyn.router import Route +from robyn.ws import WS -from typing import Dict, Tuple, Callable - -Route = Tuple[str, str, Callable, bool, int] Directory = Tuple[str, str, str, str] Header = Tuple[str, str] - def spawn_process( directories: Tuple[Directory, ...], headers: Tuple[Header, ...], @@ -34,5 +33,3 @@ def spawn_process( :param process_name string: This is the name given to the process to identify the process :param workers number: This is the name given to the process to identify the process """ - - pass diff --git a/robyn/responses.pyi b/robyn/responses.pyi index 6e24ac2bf..098a7f57f 100644 --- a/robyn/responses.pyi +++ b/robyn/responses.pyi @@ -1,6 +1,5 @@ from typing import Any - def static_file(file_path: str) -> dict[str, Any]: """ [This function will help in serving a static_file] @@ -10,7 +9,6 @@ def static_file(file_path: str) -> dict[str, Any]: pass - def jsonify(input_dict: dict) -> str: """ [This function serializes input dict to a json string] diff --git a/robyn/robyn.pyi b/robyn/robyn.pyi index 245c38603..295e63f06 100644 --- a/robyn/robyn.pyi +++ b/robyn/robyn.pyi @@ -1,19 +1,16 @@ from __future__ import annotations -from typing import Callable, Optional, Tuple +from typing import Callable, Optional, Tuple class SocketHeld: def __init__(self, url: str, port: int): pass - def try_clone(self) -> SocketHeld: pass - class Server: def __init__(self): pass - def add_directory( self, route: str, @@ -22,10 +19,8 @@ class Server: show_files_listing: bool, ): pass - def add_header(self, key: str, value: str): pass - def add_route( self, route_type: str, @@ -35,7 +30,6 @@ class Server: number_of_params: int, ): pass - def add_middleware_route( self, route_type: str, @@ -45,13 +39,10 @@ class Server: number_of_params: int, ): pass - def add_startup_handler(self, handler: Callable, is_async: bool): pass - def add_shutdown_handler(self, handler: Callable, is_async: bool): pass - def add_web_socket_route( self, route: str, @@ -60,6 +51,5 @@ class Server: message_route: Tuple[Callable, bool, int], ): pass - def start(self, socket: SocketHeld, workers: int): pass diff --git a/robyn/router.pyi b/robyn/router.pyi index 6ed4679fd..54a7795b4 100644 --- a/robyn/router.pyi +++ b/robyn/router.pyi @@ -1,48 +1,39 @@ from abc import ABC, abstractmethod +from typing import Callable, Tuple + from robyn.ws import WS -from typing import Callable +Route = Tuple[str, str, Callable, bool, int] class BaseRouter(ABC): @abstractmethod def add_route(*args) -> None: pass - class Router(BaseRouter): def __init__(self) -> None: pass - def add_route(self, route_type: str, endpoint: str, handler: Callable) -> None: pass - - def get_routes(self) -> list: + def get_routes(self) -> list[Route]: pass - class MiddlewareRouter(BaseRouter): def __init__(self) -> None: pass - def add_route(self, route_type: str, endpoint: str, handler: Callable) -> None: pass - def add_after_request(self, endpoint: str) -> Callable[..., None]: pass - def add_before_request(self, endpoint: str) -> Callable[..., None]: pass - - def get_routes(self) -> list: + def get_routes(self) -> list[Route]: pass - class WebSocketRouter(BaseRouter): def __init__(self) -> None: pass - def add_route(self, endpoint: str, web_socket: WS) -> None: pass - def get_routes(self) -> dict[str, WS]: pass diff --git a/robyn/ws.pyi b/robyn/ws.pyi index 7bf90db2d..4d5452a9f 100644 --- a/robyn/ws.pyi +++ b/robyn/ws.pyi @@ -1,11 +1,9 @@ from robyn import Robyn - class WS: - """This is the python wrapper for the web socket that will be used here. - """ + """This is the python wrapper for the web socket that will be used here.""" + def __init__(self, robyn_object: Robyn, endpoint: str) -> None: pass - def on(self, type: str): pass From be532f6da12698387147a8e325f40e4f3ba859cc Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sun, 8 May 2022 14:22:15 +0100 Subject: [PATCH 5/5] Remove inconsistent docstrings --- robyn/__init__.py | 48 +++++++++++++++++++------------------ robyn/__init__.pyi | 12 ++++++---- robyn/dev_event_handler.py | 5 ++-- robyn/dev_event_handler.pyi | 4 ++-- robyn/processpool.py | 5 ++-- robyn/responses.py | 9 +++---- robyn/responses.pyi | 8 +++---- 7 files changed, 49 insertions(+), 42 deletions(-) diff --git a/robyn/__init__.py b/robyn/__init__.py index f642e9b01..ff760a150 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -55,18 +55,20 @@ def _add_route(self, route_type, endpoint, handler): def before_request(self, endpoint): """ - [The @app.before_request decorator to add a get route] + The @app.before_request decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ + return self.middleware_router.add_before_request(endpoint) def after_request(self, endpoint): """ - [The @app.after_request decorator to add a get route] + The @app.after_request decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ + return self.middleware_router.add_after_request(endpoint) def add_directory( @@ -96,10 +98,11 @@ def shutdown_handler(self, handler): def start(self, url="127.0.0.1", port=5000): """ - [Starts the server] + Starts the server - :param port [int]: [reperesents the port number at which the server is listening] + :param port int: reperesents the port number at which the server is listening """ + if not self.dev: workers = self.workers socket = SocketHeld(url, port) @@ -139,9 +142,9 @@ def start(self, url="127.0.0.1", port=5000): def get(self, endpoint): """ - [The @app.get decorator to add a get route] + The @app.get decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -151,9 +154,9 @@ def inner(handler): def post(self, endpoint): """ - [The @app.post decorator to add a get route] + The @app.post decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -163,11 +166,10 @@ def inner(handler): def put(self, endpoint): """ - [The @app.put decorator to add a get route] + The @app.put decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - def inner(handler): self._add_route("PUT", endpoint, handler) @@ -175,9 +177,9 @@ def inner(handler): def delete(self, endpoint): """ - [The @app.delete decorator to add a get route] + The @app.delete decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -199,9 +201,9 @@ def inner(handler): def head(self, endpoint): """ - [The @app.head decorator to add a get route] + The @app.head decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -211,9 +213,9 @@ def inner(handler): def options(self, endpoint): """ - [The @app.options decorator to add a get route] + The @app.options decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -223,9 +225,9 @@ def inner(handler): def connect(self, endpoint): """ - [The @app.connect decorator to add a get route] + The @app.connect decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -235,9 +237,9 @@ def inner(handler): def trace(self, endpoint): """ - [The @app.trace decorator to add a get route] + The @app.trace decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): diff --git a/robyn/__init__.pyi b/robyn/__init__.pyi index 7522fd34b..73c140126 100644 --- a/robyn/__init__.pyi +++ b/robyn/__init__.pyi @@ -18,6 +18,7 @@ from .robyn import Server, SocketHeld from .router import MiddlewareRouter, Router, WebSocketRouter from .ws import WS + class Robyn: """This is the python wrapper for the Robyn binaries.""" @@ -28,16 +29,16 @@ class Robyn: :param endpoint str: endpoint to server the route """ - ... - def after_request(self, endpoint: str): # -> (handler: Unknown) -> None: - """ - [The @app.after_request decorator to add a get route] - :param endpoint [str]: [endpoint to server the route] + def after_request(self, endpoint: str) -> Callable[..., None]: """ + The @app.after_request decorator to add a get route + :param endpoint str: endpoint to server the route + """ ... + def add_directory( self, route: str, @@ -95,6 +96,7 @@ class Robyn: """ ... + def head(self, endpoint: str) -> Callable[..., None]: """ The @app.head decorator to add a get route diff --git a/robyn/dev_event_handler.py b/robyn/dev_event_handler.py index eadca5280..9524517f3 100644 --- a/robyn/dev_event_handler.py +++ b/robyn/dev_event_handler.py @@ -22,10 +22,11 @@ def start_server_first_time(self): def on_any_event(self, event): """ - [This function is a callback that will start a new server on every even change] + This function is a callback that will start a new server on every even change - :param event [FSEvent]: [a data structure with info about the events] + :param event FSEvent: a data structure with info about the events """ + if len(self.processes) > 0: for process in self.processes: process.terminate() diff --git a/robyn/dev_event_handler.pyi b/robyn/dev_event_handler.pyi index 88bcb567a..6414e801f 100644 --- a/robyn/dev_event_handler.pyi +++ b/robyn/dev_event_handler.pyi @@ -5,7 +5,7 @@ class EventHandler(FileSystemEventHandler): def start_server_first_time(self) -> None: ... def on_any_event(self, event: FileSystemEvent) -> None: """ - [This function is a callback that will start a new server on every even change] + This function is a callback that will start a new server on every even change - :param event [FSEvent]: [a data structure with info about the events] + :param event FSEvent: a data structure with info about the events """ diff --git a/robyn/processpool.py b/robyn/processpool.py index 4534eb80a..cd457226c 100644 --- a/robyn/processpool.py +++ b/robyn/processpool.py @@ -20,14 +20,15 @@ def spawn_process( :param directories tuple: the list of all the directories and related data in a tuple :param headers tuple: All the global headers in a tuple - :param routes tuple: The routes touple, containing the description about every route. - :param middlewares tuple: The middleware router touple, containing the description about every route. + :param routes Tuple[Route]: The routes touple, containing the description about every route. + :param middlewares Tuple[Route]: The middleware router touple, containing the description about every route. :param web_sockets list: This is a list of all the web socket routes :param event_handlers Dict: This is an event dict that contains the event handlers :param socket SocketHeld: This is the main tcp socket, which is being shared across multiple processes. :param process_name string: This is the name given to the process to identify the process :param workers number: This is the name given to the process to identify the process """ + # platform_name = platform.machine() if sys.platform.startswith("win32") or sys.platform.startswith("linux-cross"): loop = asyncio.new_event_loop() diff --git a/robyn/responses.py b/robyn/responses.py index 2202a76fa..0b3cbe58e 100644 --- a/robyn/responses.py +++ b/robyn/responses.py @@ -3,9 +3,9 @@ def static_file(file_path): """ - [This function will help in serving a static_file] + This function will help in serving a static_file - :param file_path [str]: [file path to serve as a response] + :param file_path str: file path to serve as a response """ return { @@ -19,9 +19,10 @@ def static_file(file_path): def jsonify(input_dict): """ - [This function serializes input dict to a json string] + This function serializes input dict to a json string - :param input_dict [dict]: [response of the function] + :param input_dict dict: response of the function """ + return json.dumps(input_dict) diff --git a/robyn/responses.pyi b/robyn/responses.pyi index 098a7f57f..fc7da4a99 100644 --- a/robyn/responses.pyi +++ b/robyn/responses.pyi @@ -2,18 +2,18 @@ from typing import Any def static_file(file_path: str) -> dict[str, Any]: """ - [This function will help in serving a static_file] + This function will help in serving a static_file - :param file_path [str]: [file path to serve as a response] + :param file_path str: file path to serve as a response """ pass def jsonify(input_dict: dict) -> str: """ - [This function serializes input dict to a json string] + This function serializes input dict to a json string - :param input_dict [dict]: [response of the function] + :param input_dict dict: response of the function """ pass