Skip to content

Commit

Permalink
Introduce ruff execution on the examples and scripts folder #2867 (#2869
Browse files Browse the repository at this point in the history
)
  • Loading branch information
iAndriy authored Dec 6, 2023
1 parent ef8584e commit 00f2af2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ docker-test: clean

.PHONY: fix
fix:
ruff check sanic --fix
ruff check sanic examples scripts --fix

.PHONY: format
format:
ruff format sanic
ruff format sanic examples scripts

.PHONY: pretty
pretty: fix format
Expand Down
1 change: 1 addition & 0 deletions examples/amending_request_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ def key_exist_handler(request):

return text("num does not exist in request")


if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
3 changes: 1 addition & 2 deletions examples/exception_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class' default handler, we can do anything including sending exceptions to
an external service.
"""
from sanic import Sanic
from sanic.exceptions import SanicException
from sanic.handlers import ErrorHandler

Expand Down Expand Up @@ -37,8 +38,6 @@ def default(self, request, exception):
server's error_handler to an instance of our CustomHandler
"""

from sanic import Sanic


handler = CustomHandler()
app = Sanic("Example", error_handler=handler)
Expand Down
1 change: 1 addition & 0 deletions examples/http_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ async def runner(app: Sanic, app_server: AsyncioServer):
app.is_running = False
app.is_stopping = True


if __name__ == "__main__":
https.run(port=HTTPS_PORT, debug=True)
5 changes: 4 additions & 1 deletion examples/log_request_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def filter(self, record):
},
"formatters": {
"default": {
"format": "%(asctime)s %(levelname)s %(name)s:%(lineno)d %(request_id)s | %(message)s",
"format": (
"%(asctime)s %(levelname)s %(name)s:%(lineno)d"
" %(request_id)s | %(message)s"
),
},
},
"loggers": {
Expand Down
2 changes: 1 addition & 1 deletion examples/modify_header_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def handle_request(request):


@app.route("/unauthorized")
def handle_request(request):
def handle_unauthorized_request(request):
return response.json(
{"message": "You are not authorized"},
headers={"X-Served-By": "sanic"},
Expand Down
1 change: 1 addition & 0 deletions examples/request_stream/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests


# Warning: This is a heavy process.

data = ""
Expand Down
1 change: 1 addition & 0 deletions examples/run_async_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async def after_server_stop(app, loop):
async def test(request):
return response.json({"answer": "42"})


if __name__ == "__main__":
asyncio.set_event_loop(uvloop.new_event_loop())
serv_coro = app.create_server(
Expand Down
9 changes: 6 additions & 3 deletions scripts/changelog.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/env python

from os import path
import sys

from os import path


if __name__ == "__main__":
try:
import towncrier
import click
import towncrier
except ImportError:
print(
"Please make sure you have a installed towncrier and click before using this tool"
"Please make sure you have installed towncrier and "
"click before using this tool"
)
sys.exit(1)

Expand Down
15 changes: 9 additions & 6 deletions scripts/release.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#!/usr/bin/env python

import sys

from argparse import ArgumentParser, Namespace
from collections import OrderedDict
from configparser import RawConfigParser
from datetime import datetime
from json import dumps
from os import path, chdir
from subprocess import Popen, PIPE
from os import chdir, path
from subprocess import PIPE, Popen

from jinja2 import Environment, BaseLoader
from requests import patch
import sys
import towncrier

from jinja2 import BaseLoader, Environment
from requests import patch


GIT_COMMANDS = {
"get_tag": ["git describe --tags --abbrev=0"],
"commit_version_change": [
Expand Down Expand Up @@ -78,7 +81,7 @@ def _run_shell_command(command: list):
output, error = process.communicate()
return_code = process.returncode
return output.decode("utf-8"), error, return_code
except:
except Exception:
return None, None, -1


Expand Down

0 comments on commit 00f2af2

Please sign in to comment.