From 3827350f8edbde29447a871505c8d639847973c0 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 23 Jan 2023 22:31:15 +0000 Subject: [PATCH] Move to Ruff (#364) --- .flake8 | 8 -------- .pre-commit-config.yaml | 10 +++------- integration_tests/conftest.py | 4 +--- pyproject.toml | 9 +++++++++ robyn/__init__.py | 16 ++++------------ robyn/argument_parser.py | 4 +--- robyn/dev_event_handler.py | 4 +--- robyn/router.py | 9 ++------- robyn/templating.py | 6 +----- robyn/types.py | 2 +- robyn/ws.py | 4 +--- 11 files changed, 24 insertions(+), 52 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 77a35f7cd..000000000 --- a/.flake8 +++ /dev/null @@ -1,8 +0,0 @@ -[flake8] - -max-line-length = 160 -exclude = src/* , .git , docs -max-complexity = 10 -ignore = - # empty file at eof - W391 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ab7a922f..1876e51ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,14 +5,10 @@ repos: hooks: - id: black args: [--line-length=160] - - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.224 hooks: - - id: flake8 - - repo: https://github.com/PyCQA/isort - rev: 5.11.4 - hooks: - - id: isort + - id: ruff ci: autoupdate_schedule: weekly diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 134ce095f..f50664add 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -13,9 +13,7 @@ def spawn_process(command: List[str]) -> subprocess.Popen: if sys.platform.startswith("win32"): command[0] = "python" - process = subprocess.Popen( - command, shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP - ) + process = subprocess.Popen(command, shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) return process process = subprocess.Popen(command, preexec_fn=os.setsid) return process diff --git a/pyproject.toml b/pyproject.toml index a38b5cce3..164926fb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,3 +41,12 @@ Changelog = "https://github.com/sansyrox/robyn/blob/main/CHANGELOG.md" [project.optional-dependencies] "templating" = ["jinja2 == 3.0.1"] + + +[tool.ruff] +line-length = 160 +exclude = ["src/*" , ".git" , "docs"] + + +[tool.ruff.mccabe] +max-complexity = 10 diff --git a/robyn/__init__.py b/robyn/__init__.py index 392b1dc3a..351581898 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -83,9 +83,7 @@ def add_directory( index_file: Optional[str] = None, show_files_listing: bool = False, ): - self.directories.append( - Directory(route, directory_path, index_file, show_files_listing) - ) + self.directories.append(Directory(route, directory_path, index_file, show_files_listing)) def add_request_header(self, key: str, value: str) -> None: self.request_headers.append(Header(key, value)) @@ -117,9 +115,7 @@ def start(self, url: str = "127.0.0.1", port: int = 8080): url = os.getenv("ROBYN_URL", url) port = int(os.getenv("ROBYN_PORT", port)) - logger.info( - "%sStarting server at %s:%s %s", Colors.OKGREEN, url, port, Colors.ENDC - ) + logger.info("%sStarting server at %s:%s %s", Colors.OKGREEN, url, port, Colors.ENDC) def init_processpool(socket): @@ -167,9 +163,7 @@ def init_processpool(socket): process_pool = init_processpool(socket) def terminating_signal_handler(_sig, _frame): - logger.info( - f"{Colors.BOLD}{Colors.OKGREEN} Terminating server!! {Colors.ENDC}" - ) + logger.info(f"{Colors.BOLD}{Colors.OKGREEN} Terminating server!! {Colors.ENDC}") for process in process_pool: process.kill() @@ -182,9 +176,7 @@ def terminating_signal_handler(_sig, _frame): else: event_handler = EventHandler(self.file_path) event_handler.start_server_first_time() - logger.info( - f"{Colors.OKBLUE}Dev server initialised with the directory_path : {self.directory_path}{Colors.ENDC}" - ) + logger.info(f"{Colors.OKBLUE}Dev server initialised with the directory_path : {self.directory_path}{Colors.ENDC}") observer = Observer() observer.schedule(event_handler, path=self.directory_path, recursive=True) observer.start() diff --git a/robyn/argument_parser.py b/robyn/argument_parser.py index eea2a112c..ecf30d4c9 100644 --- a/robyn/argument_parser.py +++ b/robyn/argument_parser.py @@ -3,9 +3,7 @@ class ArgumentParser(argparse.ArgumentParser): def __init__(self) -> None: - self.parser = argparse.ArgumentParser( - description="Robyn, a fast async web framework with a rust runtime." - ) + self.parser = argparse.ArgumentParser(description="Robyn, a fast async web framework with a rust runtime.") self.parser.add_argument( "--processes", type=int, diff --git a/robyn/dev_event_handler.py b/robyn/dev_event_handler.py index a7d8729f6..029f2a99c 100644 --- a/robyn/dev_event_handler.py +++ b/robyn/dev_event_handler.py @@ -8,9 +8,7 @@ class EventHandler(FileSystemEventHandler): def __init__(self, file_name) -> None: self.file_name = file_name self.processes = [] - self.python_alias = ( - "python3" if not sys.platform.startswith("win32") else "python" - ) + self.python_alias = "python3" if not sys.platform.startswith("win32") else "python" self.shell = True if sys.platform.startswith("win32") else False def start_server_first_time(self) -> None: diff --git a/robyn/router.py b/robyn/router.py index d59f2ec37..2b9b11df1 100644 --- a/robyn/router.py +++ b/robyn/router.py @@ -5,7 +5,6 @@ from types import CoroutineType from typing import Callable, Dict, List, Tuple, Union -from robyn.responses import jsonify from robyn.robyn import FunctionInfo, Response from robyn.ws import WS @@ -41,15 +40,11 @@ def _format_response(self, res): elif type(res) == Response: response = res else: - response = Response( - status_code=200, headers={"Content-Type": "text/plain"}, body=str(res) - ) + response = Response(status_code=200, headers={"Content-Type": "text/plain"}, body=str(res)) return response - def add_route( - self, route_type: str, endpoint: str, handler: Callable, is_const: bool - ) -> Union[Callable, CoroutineType]: + def add_route(self, route_type: str, endpoint: str, handler: Callable, is_const: bool) -> Union[Callable, CoroutineType]: @wraps(handler) async def async_inner_handler(*args): response = self._format_response(await handler(*args)) diff --git a/robyn/templating.py b/robyn/templating.py index 2799d3cc0..fcaa755ba 100644 --- a/robyn/templating.py +++ b/robyn/templating.py @@ -14,11 +14,7 @@ def render_template(self, *args, **kwargs): class JinjaTemplate(TemplateInterface): def __init__(self, directory, encoding="utf-8", followlinks=False): - self.env = Environment( - loader=FileSystemLoader( - searchpath=directory, encoding=encoding, followlinks=followlinks - ) - ) + self.env = Environment(loader=FileSystemLoader(searchpath=directory, encoding=encoding, followlinks=followlinks)) def render_template(self, template_name, **kwargs): return self.env.get_template(template_name).render(**kwargs) diff --git a/robyn/types.py b/robyn/types.py index ac64b31e0..a93514eda 100644 --- a/robyn/types.py +++ b/robyn/types.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Optional, Tuple +from typing import Optional @dataclass diff --git a/robyn/ws.py b/robyn/ws.py index d4d1148c0..14c89d499 100644 --- a/robyn/ws.py +++ b/robyn/ws.py @@ -23,9 +23,7 @@ def inner(handler): if type not in ["connect", "close", "message"]: raise Exception(f"Socket method {type} does not exist") else: - self.methods[type] = FunctionInfo( - handler, self._is_async(handler), self._num_params(handler) - ) + self.methods[type] = FunctionInfo(handler, self._is_async(handler), self._num_params(handler)) self.robyn_object.add_web_socket(self.endpoint, self) return inner