Skip to content

Commit 9996f26

Browse files
committed
Add project wide flake8 settings
1 parent 8e1e64f commit 9996f26

11 files changed

+42
-28
lines changed

.flake8

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
3+
max-line-length = 160
4+
exclude = src/* , .git , docs
5+
max-complexity = 10
6+
ignore =
7+
# empty file at eof
8+
W391

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
[![Gitter](https://badges.gitter.im/robyn_/community.svg)](https://gitter.im/robyn_/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
77
[![Downloads](https://static.pepy.tech/personalized-badge/robyn?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/robyn)
8+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
89

910

10-
[Docs](https://sansyrox.github.io/robyn/#/)
11+
API Docs: [Docs](https://sansyrox.github.io/robyn/#/)
1112

1213
Robyn is an async Python backend server with a runtime written in Rust, btw.
1314

dev-requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flake8==4.0.1
2+
black==21.12b0

robyn/__init__.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
from inspect import signature
55
import multiprocessing as mp
6-
mp.allow_connection_pickling()
76

87
# custom imports and exports
98
from .robyn import Server, SocketHeld
@@ -14,11 +13,11 @@
1413
from .log_colors import Colors
1514
from .ws import WS
1615

17-
1816
# 3rd party imports and exports
1917
from multiprocess import Process
2018
from watchdog.observers import Observer
2119

20+
mp.allow_connection_pickling()
2221

2322

2423
class Robyn:
@@ -31,15 +30,14 @@ def __init__(self, file_object):
3130
self.server = Server(directory_path)
3231
self.parser = ArgumentParser()
3332
self.dev = self.parser.is_dev()
34-
self.processes = self.parser.num_processes()
33+
self.processes = self.parser.num_processes()
3534
self.workers = self.parser.workers()
3635
self.routes = []
3736
self.headers = []
3837
self.routes = []
3938
self.directories = []
4039
self.web_sockets = {}
4140

42-
4341
def add_route(self, route_type, endpoint, handler):
4442
"""
4543
[This is base handler for all the decorators]
@@ -53,22 +51,24 @@ def add_route(self, route_type, endpoint, handler):
5351
"""
5452
number_of_params = len(signature(handler).parameters)
5553
self.routes.append(
56-
( route_type, endpoint, handler, asyncio.iscoroutinefunction(handler), number_of_params)
54+
(route_type,
55+
endpoint,
56+
handler,
57+
asyncio.iscoroutinefunction(handler), number_of_params)
5758
)
5859

5960
def add_directory(self, route, directory_path, index_file=None, show_files_listing=False):
60-
self.directories.append(( route, directory_path, index_file, show_files_listing ))
61+
self.directories.append((route, directory_path, index_file, show_files_listing))
6162

6263
def add_header(self, key, value):
63-
self.headers.append(( key, value ))
64+
self.headers.append((key, value))
6465

6566
def remove_header(self, key):
6667
self.server.remove_header(key)
6768

6869
def add_web_socket(self, endpoint, ws):
6970
self.web_sockets[endpoint] = ws
70-
71-
71+
7272
def start(self, url="127.0.0.1", port=5000):
7373
"""
7474
[Starts the server]
@@ -82,7 +82,9 @@ def start(self, url="127.0.0.1", port=5000):
8282
copied = socket.try_clone()
8383
p = Process(
8484
target=spawn_process,
85-
args=(url, port, self.directories, self.headers, self.routes, self.web_sockets, copied, f"Process {process_number}", workers),
85+
args=(url, port, self.directories, self.headers,
86+
self.routes, self.web_sockets, copied,
87+
f"Process {process_number}", workers),
8688
)
8789
p.start()
8890

@@ -92,7 +94,9 @@ def start(self, url="127.0.0.1", port=5000):
9294
event_handler.start_server_first_time()
9395
print(f"{Colors.OKBLUE}Dev server initialised with the directory_path : {self.directory_path}{Colors.ENDC}")
9496
observer = Observer()
95-
observer.schedule(event_handler, path=self.directory_path, recursive=True)
97+
observer.schedule(event_handler,
98+
path=self.directory_path,
99+
recursive=True)
96100
observer.start()
97101
try:
98102
while True:
@@ -101,7 +105,6 @@ def start(self, url="127.0.0.1", port=5000):
101105
observer.stop()
102106
observer.join()
103107

104-
105108
def get(self, endpoint):
106109
"""
107110
[The @app.get decorator to add a get route]
@@ -154,7 +157,7 @@ def patch(self, endpoint):
154157
"""
155158
def inner(handler):
156159
self.add_route("PATCH", endpoint, handler)
157-
160+
158161
return inner
159162

160163
def head(self, endpoint):
@@ -179,7 +182,6 @@ def inner(handler):
179182

180183
return inner
181184

182-
183185
def connect(self, endpoint):
184186
"""
185187
[The @app.connect decorator to add a get route]
@@ -202,4 +204,3 @@ def inner(handler):
202204

203205
return inner
204206

205-

robyn/dev_event_handler.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from watchdog.events import FileSystemEventHandler
99

1010

11-
1211
class EventHandler(FileSystemEventHandler):
1312
def __init__(self, file_name):
1413
self.file_name = file_name
@@ -27,7 +26,7 @@ def on_any_event(self, event):
2726
2827
:param event [FSEvent]: [a data structure with info about the events]
2928
"""
30-
if len(self.processes)>0:
29+
if len(self.processes) > 0:
3130
for process in self.processes:
3231
process.terminate()
3332
print(f"{Colors.OKGREEN}Starting the server in dev mode{Colors.ENDC}")

robyn/processpool.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def spawn_process(url, port, directories, headers, routes, web_sockets, socket,
2323
:param process_name string: This is the name given to the process to identify the process
2424
:param workers number: This is the name given to the process to identify the process
2525
"""
26-
# platform_name = platform.machine()
26+
# platform_name = platform.machine()
2727
if sys.platform.startswith("win32") or sys.platform.startswith("linux-cross"):
2828
loop = asyncio.new_event_loop()
2929
asyncio.set_event_loop(loop)
@@ -46,7 +46,6 @@ def spawn_process(url, port, directories, headers, routes, web_sockets, socket,
4646
for key, val in headers:
4747
server.add_header(key, val)
4848

49-
5049
for route in routes:
5150
route_type, endpoint, handler, is_async, number_of_params = route
5251
server.add_route(route_type, endpoint, handler, is_async, number_of_params)
@@ -56,6 +55,5 @@ def spawn_process(url, port, directories, headers, routes, web_sockets, socket,
5655
print(web_socket.methods)
5756
server.add_web_socket_route(endpoint, web_socket.methods["connect"], web_socket.methods["close"], web_socket.methods["message"])
5857

59-
6058
server.start(url, port, socket, process_name, workers)
6159
asyncio.get_event_loop().run_forever()

robyn/responses.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22

3+
34
def static_file(file_path):
45
"""
56
[This function will help in serving a static_file]
@@ -12,11 +13,12 @@ def static_file(file_path):
1213
"file_path": file_path
1314
}
1415

16+
1517
def jsonify(input_dict):
1618
"""
1719
[This function serializes input dict to a json string]
1820
1921
:param input_dict [dict]: [response of the function]
2022
"""
2123
return json.dumps(input_dict)
22-
24+

robyn/test_robyn.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
app = Robyn(__file__)
55

6+
67
def test_directory_path():
78
assert app.directory_path == os.path.dirname(os.path.abspath(__file__))
89

10+
911
def test_file_path():
1012
assert app.file_path == __file__
1113

robyn/ws.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from inspect import signature
33

4+
45
class WS:
56
"""This is the python wrapper for the web socket that will be used here.
67
"""
@@ -14,8 +15,8 @@ def inner(handler):
1415
if type not in ["connect", "close", "message"]:
1516
raise Exception(f"Socket method {type} does not exist")
1617
else:
17-
self.methods[type] = ( handler, self._is_async(handler), self._num_params(handler) )
18-
self.robyn_object.add_web_socket(self.endpoint, self)
18+
self.methods[type] = (handler, self._is_async(handler), self._num_params(handler))
19+
self.robyn_object.add_web_socket(self.endpoint, self)
1920

2021
return inner
2122

src/server.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ impl Server {
4949
pub fn start(
5050
&mut self,
5151
py: Python,
52-
url: String,
53-
port: u16,
52+
_url: String,
53+
_port: u16,
5454
socket: &PyCell<SocketHeld>,
55-
name: String,
55+
_name: String,
5656
workers: usize,
5757
) -> PyResult<()> {
5858
if STARTED

src/web_socket_connection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
9595
ctx.pong(&msg)
9696
}
9797

98-
Ok(ws::Message::Text(text)) => {
98+
Ok(ws::Message::Text(_text)) => {
9999
// need to also passs this text as a param
100100
let handler_function = &self.router.get("message").unwrap().0;
101101
let _number_of_params = &self.router.get("message").unwrap().1;

0 commit comments

Comments
 (0)