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

Move pre-commit hooks to use Ruff #364

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is 160 really what we want? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, btw, the default_stages at the top might not be what we'd like, @sansyrox was there a particular reason it is only set to push?

Copy link
Member

Choose a reason for hiding this comment

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

@patrick91

is 160 really what we want? :)

This was just something random. I just feel that 70 characters is a bit too less :p

ah, btw, the default_stages at the top might not be what we'd like, @sansyrox was there a particular reason it is only set to push?

@patrick91 , I am sorry but I don't understand what you mean by this. Can you please explain a bit more? 😅

Copy link
Member

Choose a reason for hiding this comment

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

ah, btw, the default_stages at the top might not be what we'd like, @sansyrox was there a particular reason it is only set to push?

Now, I understand. It was mistake 🤣

- 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 @@ -12,9 +12,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 = 5000):
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
2 changes: 1 addition & 1 deletion robyn/processpool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import sys
from typing import Dict, List, Tuple
from typing import Dict, List

from robyn.events import Events
from robyn.robyn import FunctionInfo, Server, SocketHeld
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