Skip to content

Commit

Permalink
🚀 Prepare release 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Nov 5, 2022
1 parent c707b06 commit 27ff626
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 60 deletions.
8 changes: 8 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes

## 0.2.3

November 5, 2022

### Fixed

- OpenAPI documenation rendering for the same path with differnt http methods.

## 0.2.2

November 2, 2022.
Expand Down
2 changes: 1 addition & 1 deletion esmerald/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Esmerald: Highly scalable, performant, easy to learn and for every application.
"""
__version__ = "0.2.2"
__version__ = "0.2.3"

from esmerald.conf import settings
from esmerald.conf.global_settings import EsmeraldAPISettings
Expand Down
8 changes: 2 additions & 6 deletions esmerald/core/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ def get_actions(parser):
# Any required arguments which are passed in via **options must be passed
# to parse_args().
for opt in parser_actions:
if opt.dest in options and (
opt.required or opt in mutually_exclusive_required_options
):
if opt.dest in options and (opt.required or opt in mutually_exclusive_required_options):
parse_args.append(min(opt.option_strings))
if isinstance(opt, (_AppendConstAction, _CountAction, _StoreConstAction)):
continue
Expand Down Expand Up @@ -350,9 +348,7 @@ def execute(self):
elif not options.args:
sys.stdout.write(self.main_help_text() + "\n")
else:
self.fetch_command(options.args[0]).print_help(
self.prog_name, options.args[0]
)
self.fetch_command(options.args[0]).print_help(self.prog_name, options.args[0])
elif subdirective == "version" or self.argv[1:] == ["--version"]:
sys.stdout.write(esmerald.__version__ + "\n")
elif self.argv[1:] in (["--help"], ["-h"]):
Expand Down
12 changes: 3 additions & 9 deletions esmerald/core/management/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def handle(
continue

old_path = os.path.join(root, filename)
new_path = os.path.join(
top_dir, relative_dir, filename.replace(base_name, name)
)
new_path = os.path.join(top_dir, relative_dir, filename.replace(base_name, name))
project_dir = os.path.join(top_dir, relative_dir)
template_name = filename
for old_suffix, new_suffix in self.rewrite_template_suffixes:
Expand All @@ -104,9 +102,7 @@ def handle(
if self.verbosity >= 2:
self.stdout.write("Creating %s" % new_path)
try:
self.manage_template_variables(
template_name, new_path, project_dir, context
)
self.manage_template_variables(template_name, new_path, project_dir, context)
self.apply_umask(old_path, new_path)
self.make_file_writable(new_path)
except OSError:
Expand Down Expand Up @@ -171,9 +167,7 @@ def validate_name(self, name, name_or_dir="name"):
)
)

def apply_umask(
self, old_path: Union[str, FilePath], new_path: Union[str, FilePath]
):
def apply_umask(self, old_path: Union[str, FilePath], new_path: Union[str, FilePath]):
current_umask = os.umask(0)
os.umask(current_umask)
current_mode = stat.S_IMODE(os.stat(old_path).st_mode)
Expand Down
59 changes: 15 additions & 44 deletions esmerald/routing/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def __init__(
Router,
),
):
raise ImproperlyConfigured(
f"The route {route} must be of type Gateway or Include"
)
raise ImproperlyConfigured(f"The route {route} must be of type Gateway or Include")
routes = routes or []
super().__init__(
on_startup=on_startup,
Expand Down Expand Up @@ -265,9 +263,7 @@ def add_apiview(self, value: "APIView"):
route_handlers = value.handler.get_route_handlers()
for route_handler in route_handlers:
gateway = (
Gateway
if not isinstance(route_handler, WebSocketHandler)
else WebSocketGateway
Gateway if not isinstance(route_handler, WebSocketHandler) else WebSocketGateway
)
gate = gateway(
path=value.path,
Expand Down Expand Up @@ -365,9 +361,7 @@ async def not_found(self, scope: "Scope", receive: "Receive", send: "Send") -> N
if "app" in scope:
raise NotFound(status_code=status.HTTP_404_NOT_FOUND)
else:
response = JSONResponse(
{"detail": "Not Found"}, status_code=status.HTTP_404_NOT_FOUND
)
response = JSONResponse({"detail": "Not Found"}, status_code=status.HTTP_404_NOT_FOUND)
await response(scope, receive, send)

def url_path_for(self, name: str, **path_params: Any) -> URLPath:
Expand Down Expand Up @@ -446,9 +440,7 @@ def __init__(
) -> None:
if not path:
path = "/"
super().__init__(
path=path, endpoint=endpoint, include_in_schema=include_in_schema
)
super().__init__(path=path, endpoint=endpoint, include_in_schema=include_in_schema)
"""
Handles the "handler" or "apiview" of the platform. A handler can be any get, put, patch, post, delete or route.
"""
Expand Down Expand Up @@ -672,8 +664,7 @@ def validate_handler(self):
)
if (
self.status_code < status.HTTP_200_OK
or self.status_code
in {status.HTTP_204_NO_CONTENT, status.HTTP_304_NOT_MODIFIED}
or self.status_code in {status.HTTP_204_NO_CONTENT, status.HTTP_304_NOT_MODIFIED}
) and return_annotation not in [NoReturn, None]:
raise ImproperlyConfigured(
"A status code 204, 304 or in the range below 200 does not support a response body."
Expand All @@ -693,13 +684,9 @@ def validate_handler(self):
]:
self.media_type = MediaType.TEXT
if SOCKET in self.signature.parameters:
raise ImproperlyConfigured(
"The 'socket' argument is not supported with http handlers"
)
raise ImproperlyConfigured("The 'socket' argument is not supported with http handlers")
if DATA in self.signature.parameters and "GET" in self.methods:
raise ImproperlyConfigured(
"'data' argument is unsupported for 'GET' request handlers"
)
raise ImproperlyConfigured("'data' argument is unsupported for 'GET' request handlers")

async def to_response(self, app: "Esmerald", data: Any) -> StarletteResponse:
response_handler = self.get_response_handler()
Expand All @@ -726,9 +713,7 @@ def __init__(
*,
endpoint: Callable[..., "CoroutineHandler"] = None,
dependencies: Optional["Dependencies"] = None,
exception_handlers: Optional[
Dict[Union[int, Type[Exception]], "ExceptionHandler"]
] = None,
exception_handlers: Optional[Dict[Union[int, Type[Exception]], "ExceptionHandler"]] = None,
permissions: Optional[List["Permission"]] = None,
middleware: Optional[List["Middleware"]] = None,
):
Expand Down Expand Up @@ -779,9 +764,7 @@ def validate_websocket_handler_function(self) -> None:
)

if SOCKET not in signature.parameters:
raise ImproperlyConfigured(
"Websocket handlers must set a 'socket' argument."
)
raise ImproperlyConfigured("Websocket handlers must set a 'socket' argument.")
if not is_async_callable(fn):
raise ImproperlyConfigured(
"Functions decorated with 'asgi, get, patch, put, post and delete' must be async functions."
Expand Down Expand Up @@ -815,14 +798,10 @@ async def get_kwargs(self, websocket: WebSocket[Any, Any]) -> Dict[str, Any]:
signature_model = get_signature_model(self)
kwargs = self.websocket_parameter_model.to_kwargs(connection=websocket)
for dependency in self.websocket_parameter_model.expected_dependencies:
kwargs[
dependency.key
] = await self.websocket_parameter_model.resolve_dependency(
kwargs[dependency.key] = await self.websocket_parameter_model.resolve_dependency(
dependency=dependency, connection=websocket, **kwargs
)
return signature_model.parse_values_from_connection_kwargs(
connection=websocket, **kwargs
)
return signature_model.parse_values_from_connection_kwargs(connection=websocket, **kwargs)


class Include(Mount):
Expand Down Expand Up @@ -863,9 +842,7 @@ def __init__(
pattern: Optional[str] = None,
parent: Optional["Router"] = None,
dependencies: Optional["Dependencies"] = None,
exception_handlers: Optional[
Dict[Union[int, Type[Exception]], "ExceptionHandler"]
] = None,
exception_handlers: Optional[Dict[Union[int, Type[Exception]], "ExceptionHandler"]] = None,
permissions: Optional[List["Permission"]] = None,
middleware: Optional[List["Middleware"]] = None,
include_in_schema: Optional[bool] = True,
Expand All @@ -880,14 +857,10 @@ def __init__(
raise ImproperlyConfigured("It can only be namespace or routes, not both.")

if namespace and not isinstance(namespace, str):
raise ImproperlyConfigured(
"Namespace must be a string. Example: 'myapp.routes'."
)
raise ImproperlyConfigured("Namespace must be a string. Example: 'myapp.routes'.")

if pattern and not isinstance(pattern, str):
raise ImproperlyConfigured(
"Pattern must be a string. Example: 'route_patterns'."
)
raise ImproperlyConfigured("Pattern must be a string. Example: 'route_patterns'.")

if pattern and routes:
raise ImproperlyConfigured("Pattern must be used only with namespace.")
Expand Down Expand Up @@ -972,9 +945,7 @@ def resolve_route_path_handler(self, routes: List[StarletteBaseRoute]):

for route in routes:
if not isinstance(route, (Include, Gateway, WebSocketGateway, Mount)):
raise ImproperlyConfigured(
"The route must be of type Gateway or Include"
)
raise ImproperlyConfigured("The route must be of type Gateway or Include")
route.parent = self
if isinstance(route, Include):
routing.append(route)
Expand Down

0 comments on commit 27ff626

Please sign in to comment.