Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jan 27, 2025
1 parent 22e3145 commit f49a8ea
Show file tree
Hide file tree
Showing 22 changed files with 1,245 additions and 524 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
lint:
runs-on: ubuntu-latest

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
enable-cache: false
- name: Install
run: |
python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin develop --extras=lint
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv sync --group lint
- name: Lint
run: |
source .venv/bin/activate
Expand Down
58 changes: 30 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
enable-cache: false
- name: Install
run: |
python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin develop --extras=test
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv sync --group all
uv run --no-sync maturin develop --uv
- name: Test
run: |
source .venv/bin/activate
py.test -v tests
make test
macos:
runs-on: macos-latest
Expand All @@ -51,24 +52,25 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
enable-cache: false
- name: Install
run: |
python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin develop --extras=test
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv sync --group all
uv run --no-sync maturin develop --uv
- name: Test
run: |
source .venv/bin/activate
py.test -v tests
make test
windows:
runs-on: windows-latest
Expand All @@ -81,21 +83,21 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
enable-cache: false
- name: Install
run: |
python -m venv venv
venv/Scripts/Activate.ps1
pip install maturin
maturin develop --extras=test
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv sync --group all
uv run --no-sync maturin develop --uv
- name: Test
run: |
venv/Scripts/Activate.ps1
py.test -v tests
uv run --no-sync pytest -v tests
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pysources = granian tests
.PHONY: build-dev
build-dev:
@rm -f granian/*.so
maturin develop --extras lint,test
uv sync --group all
maturin develop

.PHONY: format
format:
Expand Down
2 changes: 1 addition & 1 deletion granian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from ._granian import __version__ # noqa: F401
from .server import Granian as Granian
from .server import Server as Granian # noqa: F401
5 changes: 5 additions & 0 deletions granian/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys


_PYV = int(sys.version_info.major * 100 + sys.version_info.minor)
_PY_39 = 309
1 change: 1 addition & 0 deletions granian/_granian.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from ._types import WebsocketMessage
from .http import HTTP1Settings, HTTP2Settings

__version__: str
BUILD_GIL: bool

class RSGIHeaders:
def __contains__(self, key: str) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion granian/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def load_module(module_name: str, raise_on_failure: bool = True) -> Optional[Mod
except ImportError:
if sys.exc_info()[-1].tb_next:
raise RuntimeError(
f"While importing '{module_name}', an ImportError was raised:" f'\n\n{traceback.format_exc()}'
f"While importing '{module_name}', an ImportError was raised:\n\n{traceback.format_exc()}"
)
elif raise_on_failure:
raise RuntimeError(f"Could not import '{module_name}'.")
Expand Down
17 changes: 10 additions & 7 deletions granian/_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple

from ._compat import _PY_39, _PYV


WrappableT = Callable[..., Any]
LoopBuilderT = Callable[..., asyncio.AbstractEventLoop]
Expand Down Expand Up @@ -71,23 +73,24 @@ def get(self, key: str) -> asyncio.AbstractEventLoop:
@loops.register('asyncio')
def build_asyncio_loop():
loop = asyncio.new_event_loop() if os.name != 'nt' else asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
if _PYV == _PY_39:
asyncio.set_event_loop(loop)
return loop


@loops.register('uvloop', packages=['uvloop'])
def build_uv_loop(uvloop):
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop = uvloop.new_event_loop()
if _PYV == _PY_39:
asyncio.set_event_loop(loop)
return loop


@loops.register('rloop', packages=['rloop'])
def build_rloop(rloop):
asyncio.set_event_loop_policy(rloop.EventLoopPolicy())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop = rloop.new_event_loop()
if _PYV == _PY_39:
asyncio.set_event_loop(loop)
return loop


Expand Down
4 changes: 2 additions & 2 deletions granian/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .errors import FatalError
from .http import HTTP1Settings, HTTP2Settings
from .log import LogLevels
from .server import Granian
from .server import Server


_AnyCallable = Callable[..., Any]
Expand Down Expand Up @@ -313,7 +313,7 @@ def cli(
print('Unable to parse provided logging config.')
raise click.exceptions.Exit(1)

server = Granian(
server = Server(
app,
address=host,
port=port,
Expand Down
7 changes: 7 additions & 0 deletions granian/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .._granian import BUILD_GIL


if BUILD_GIL:
from .mp import MPServer as Server
else:
from .mt import MTServer as Server # noqa: F401
Loading

0 comments on commit f49a8ea

Please sign in to comment.