Skip to content

Commit

Permalink
Prep for release 2.0a0 (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Jan 8, 2023
1 parent 65778d5 commit 5913265
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 134 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,25 @@ jobs:
with:
name: dist
path: dist
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master

- name: Use Python 3.11
uses: actions/setup-python@v1
with:
skip_existing: true
user: __token__
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
python-version: '3.11'

- name: Install dependencies
run: |
pip install twine
- name: Publish distribution 📦 to Test PyPI
run: |
twine upload -r testpypi dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.test_pypi_password }}

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
run: |
twine upload -r pypi dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi_password }}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - ???
## [2.0a0] - 2023-01-08 :hourglass_flowing_sand:

- Renames the `plugins` namespace to `settings`
- Upgrades `rodi` to v2, which includes improvements.
Expand All @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
ways to achieve Server Side Rendering (SSR) of HTML; however, `Jinja2` is still
the default library if the user doesn´t specify how HTML should be rendered.
- Adds options to control `Jinja2` settings through environment variables.
- Removes the deprecated `ServeFilesOptions` class.

## [1.2.8] - 2022-10-27 :snake:
- Upgrades pinned dependencies to support Python 3.11
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Since version `1.2.1`, BlackSheep implements:
* [Built-in support for OpenID Connect authentication](https://www.neoteroi.dev/blacksheep/authentication/#oidc)
* [Built-in support for JWT Bearer authentication](https://www.neoteroi.dev/blacksheep/authentication/#jwt-bearer)

Meaning that it is extremely easy to integrate with services such as:
Meaning that it is easy to integrate with services such as:
* [Auth0](https://auth0.com)
* [Azure Active Directory](https://azure.microsoft.com/en-us/services/active-directory/)
* [Azure Active Directory B2C](https://docs.microsoft.com/en-us/azure/active-directory-b2c/overview)
Expand All @@ -189,6 +189,7 @@ Meaning that it is extremely easy to integrate with services such as:
Refer to the documentation for more details and examples.

## Web framework features

* [ASGI compatibility](https://www.neoteroi.dev/blacksheep/asgi/)
* [Routing](https://www.neoteroi.dev/blacksheep/routing/)
* Request handlers can be [defined as
Expand Down Expand Up @@ -264,3 +265,8 @@ Please refer to the [documentation website](https://www.neoteroi.dev/blacksheep/

## Communication
[BlackSheep community in Gitter](https://gitter.im/Neoteroi/BlackSheep).

## Branches
The _main_ branch contains the currently developed version, which is version 2
alpha. The _v1_ branch contains version 1 of the web framework, for bugs fixes
and maintenance.
5 changes: 0 additions & 5 deletions blacksheep/includes/consts.pxi
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
DEF MAX_RESPONSE_CHUNK_SIZE = 61440 # 64kb
DEF MAX_REQUEST_HEADERS_COUNT = 80
DEF MAX_REQUEST_HEADER_SIZE = 8192 # 8kb

# 61440 # 64kb
# 16384
20 changes: 0 additions & 20 deletions blacksheep/server/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from blacksheep.server.cors import CORSPolicy, CORSStrategy, get_cors_middleware
from blacksheep.server.env import EnvironmentSettings
from blacksheep.server.errors import ServerErrorDetailsHandler
from blacksheep.server.files import ServeFilesOptions
from blacksheep.server.files.dynamic import serve_files_dynamic
from blacksheep.server.normalization import normalize_handler, normalize_middleware
from blacksheep.server.responses import _ensure_bytes
Expand Down Expand Up @@ -475,25 +474,6 @@ def serve_files(
response would be otherwise 404 Not Found; e.g. use this to serve SPA that
use HTML5 History API for client side routing.
"""
if isinstance(source_folder, ServeFilesOptions):
# deprecated class, will be removed in the next version
from typing import cast

deprecated_arg = cast(ServeFilesOptions, source_folder)
deprecated_arg.validate()
serve_files_dynamic(
self.router,
self.files_handler,
str(deprecated_arg.source_folder),
discovery=deprecated_arg.discovery,
cache_time=deprecated_arg.cache_time,
extensions=deprecated_arg.extensions,
root_path=deprecated_arg.root_path,
index_document=deprecated_arg.index_document,
fallback_document=deprecated_arg.fallback_document,
anonymous_access=deprecated_arg.allow_anonymous,
)
return
serve_files_dynamic(
self.router,
self.files_handler,
Expand Down
4 changes: 4 additions & 0 deletions blacksheep/server/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from blacksheep.baseapp import BaseApplication
from blacksheep.messages import Request, Response
from blacksheep.server.routing import Route, Router
from blacksheep.server.websocket import WebSocket

from .responses import not_found, ok, status_code

Expand Down Expand Up @@ -243,6 +244,9 @@ def get_cors_middleware(
strategy: CORSStrategy,
) -> Callable[[Request, Callable[..., Any]], Awaitable[Response]]:
async def cors_middleware(request: Request, handler):
if isinstance(request, WebSocket):
return await handler(request)

origin = request.get_first_header(b"Origin")

if not origin:
Expand Down
76 changes: 1 addition & 75 deletions blacksheep/server/files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from pathlib import Path
from typing import AsyncIterable, Callable, Optional, Set, Union
from typing import AsyncIterable, Callable, Optional, Set

from blacksheep import Request, Response, StreamedContent
from blacksheep.common.files.asyncfs import FilesHandler
Expand Down Expand Up @@ -184,80 +184,6 @@ def validate_source_path(source_folder: str) -> None:
raise InvalidArgument("The given root path is not a directory.")


class ServeFilesOptions:

__slots__ = (
"source_folder",
"extensions",
"discovery",
"cache_time",
"root_path",
"allow_anonymous",
"index_document",
"fallback_document",
)

def __init__(
self,
source_folder: Union[str, Path],
*,
extensions: Optional[Set[str]] = None,
discovery: bool = False,
cache_time: int = 10800,
root_path: str = "",
allow_anonymous: bool = True,
index_document: Optional[str] = "index.html",
fallback_document: Optional[str] = None,
):
"""
Options for static files serving.
Args:
source_folder (str): Path to the source folder containing static files.
extensions: The set of files extensions to serve.
discovery: Whether to enable file discovery, serving HTML pages for folders.
cache_time: Controls the Cache-Control Max-Age in seconds for static files.
root_path: Path prefix used for routing requests.
For example, if set to "public", files are served at "/public/*".
allow_anonymous: Whether to enable anonymous access to static files, true by
default.
index_document: The name of the index document to display, if present,
in folders. Requests for folders that contain a file with matching produce
a response with this document.
fallback_document: Optional file name, for a document to serve when a
response would be otherwise 404 Not Found; e.g. use this to serve SPA that
use HTML5 History API for client side routing.
"""
import warnings

warnings.warn(
"The ServeFilesOptions is deprecated and will "
"be removed in the version 1.0.0. Update your code to not use this class "
"and pass the same arguments to the application.serve_files method. "
"For more information see "
"https://www.neoteroi.dev/blacksheep/static-files/",
DeprecationWarning,
)

if extensions is None:
extensions = self.get_default_extensions()
self.source_folder = source_folder
self.extensions = set(extensions)
self.discovery = bool(discovery)
self.cache_time = int(cache_time)
self.root_path = root_path
self.allow_anonymous = allow_anonymous
self.index_document = index_document
self.fallback_document = fallback_document

def get_default_extensions(self) -> Set[str]:
"""Returns a set of extensions that are served by default."""
return get_default_extensions()

def validate(self) -> None:
validate_source_path(str(self.source_folder))


def get_response_for_file(
files_handler: FilesHandler,
request: Request,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def readme():

setup(
name="blacksheep",
version="2.0.0",
version="2.0a0",
description="Fast web framework for Python asyncio",
long_description=readme(),
long_description_content_type="text/markdown",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand Down
20 changes: 0 additions & 20 deletions tests/test_files_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from blacksheep.server.files import (
FileInfo,
RangeNotSatisfiable,
ServeFilesOptions,
_get_requested_range,
get_default_extensions,
get_range_file_getter,
Expand Down Expand Up @@ -338,25 +337,6 @@ async def test_serve_files_no_discovery(app):
assert response.status == 404


@pytest.mark.asyncio
async def test_serve_files_deprecated_serve_files_options(files2_index_contents, app):
with pytest.deprecated_call():
app.serve_files(ServeFilesOptions(get_folder_path("files2"))) # type: ignore

await app.start()

scope = get_example_scope("GET", "/", [])
await app(
scope,
MockReceive(),
MockSend(),
)

response = app.response
assert response.status == 200
assert files2_index_contents == await response.read()


@pytest.mark.asyncio
async def test_serve_files_fallback_document(files2_index_contents: bytes, app):
"""Feature used to serve SPAs that use HTML5 History API"""
Expand Down

0 comments on commit 5913265

Please sign in to comment.