Skip to content

Commit

Permalink
Move to Ruff (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 authored Jan 23, 2023
1 parent bd01dc5 commit 3827350
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 52 deletions.
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 4 additions & 12 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions robyn/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions robyn/dev_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 2 additions & 7 deletions robyn/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
6 changes: 1 addition & 5 deletions robyn/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion robyn/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Optional, Tuple
from typing import Optional


@dataclass
Expand Down
4 changes: 1 addition & 3 deletions robyn/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3827350

Please sign in to comment.