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 190484c
Show file tree
Hide file tree
Showing 19 changed files with 1,206 additions and 509 deletions.
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 pip install maturin
uv run --no-sync maturin develop --uv --extras=test
- 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 pip install maturin
uv run --no-sync maturin develop --uv --extras=test
- 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 pip install maturin
uv run --no-sync maturin develop --uv --extras=test
- name: Test
run: |
venv/Scripts/Activate.ps1
py.test -v tests
uv run --no-sync py.test -v tests
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
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
9 changes: 2 additions & 7 deletions granian/_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,18 @@ 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)
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()
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()
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 190484c

Please sign in to comment.