Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tutorial to use latest #98

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cannula/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"render_file",
]

__VERSION__ = "0.17.0"
__VERSION__ = "0.18.0"
4 changes: 2 additions & 2 deletions examples/tutorial/dashboard/core/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pathlib
import functools

from cannula.contrib.config import BaseConfig
from fastapi.templating import Jinja2Templates
from pydantic_settings import BaseSettings
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine, async_sessionmaker

DASHBOARD_ROOT = pathlib.Path(__file__).parent.parent


class Config(BaseSettings):
class Config(BaseConfig):
database_uri: str = "sqlite+aiosqlite:///db.sqlite"
debug: bool = True
template_dir: str = "templates"
Expand Down
1 change: 1 addition & 0 deletions examples/tutorial/dashboard/static/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Make this directory exist
24 changes: 0 additions & 24 deletions examples/tutorial/dashboard/static/main.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/tutorial/dashboard/static/pyscript.toml

This file was deleted.

41 changes: 1 addition & 40 deletions examples/tutorial/dashboard/templates/part5/index.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
{% extends 'base.html' %}
{% block head %}
<script type="module" src="https://pyscript.net/releases/2024.10.1/core.js"></script>
<style>
.py-error {
z-index: 1000;
position: relative;
}
</style>
{% endblock %}

{% block content %}
<h1 class="text-3xl md:text-5xl mb-4 font-extrabold">Part Five: Datasources</h1>

<div class="flex flex-row h-[50rem] flex-nowrap justify-between m-4 overflow-hidden">
<textarea id="input" class="w-1/3 h-2/3 float p-2">
# Example Schema
scalar Datetime
scalar UUID

interface Persona {
id: UUID!
}

type User implements Persona {
id: UUID!
created: Datetime
}

type Query {
user(id: UUID!): User
users(limit: Int! = 100, offset: Int! = 0): [Users]
}
</textarea>
<button py-click="run_codegen" enabled="false" id="generate-btn" class="py-button top-0">
Generate
</button>

<pre id="output" class="w-[50rem] h-2/3 bg-white border-gray-600 overflow-auto p-2 text-sm"></pre>
</div>
<script type="py" src="/static/main.py" config="/static/pyscript.toml"></script>
<h2>Part 5</h2>
{% endblock %}
5 changes: 2 additions & 3 deletions examples/tutorial/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
aiosqlite==0.19.0 # Async version of sqlite
cannula==0.15.0 # The reason you are reading this
cannula[codegen]==0.17.0 # The reason you are reading this
click==8.1.7 # Command line tool helper
fastapi[all]==0.108.0 # The main asgi application logic
fastapi[all]==0.115.0 # The main asgi application logic
greenlet==3.0.3 # For sqlalchemy async support
pydantic_settings==2.1.0 # Configurations via ENV variables
ruff==0.1.4 # For formatting the code
sqlalchemy==2.0.25 # For database table access
uvicorn==0.25.0 # Web server for asgi applications
Expand Down
3 changes: 2 additions & 1 deletion examples/tutorial/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async def session():

@pytest.fixture
def client() -> httpx.AsyncClient:
return httpx.AsyncClient(app=app, base_url="http://localhost")
transport = httpx.ASGITransport(app=app)
return httpx.AsyncClient(base_url="http://localhost", transport=transport)


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion performance/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ async def get_cannula_app(


async def test_performance():
client = httpx.AsyncClient(app=api, base_url="http://localhost")
transport = httpx.ASGITransport(app=api)
client = httpx.AsyncClient(transport=transport, base_url="http://localhost")

start = time.perf_counter()
for x in range(NUM_RUNS):
Expand Down