-
Notifications
You must be signed in to change notification settings - Fork 91
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 ASGI requirements #911
Conversation
Piccolo has `jinja2` as a direct dependency, so this shouldn't be needed.
I think this was needed for Starlette at some point, but it has since transitioned to `httpx`, so I don't think it's needed any more.
We don't use it for `esmerald` so don't include it by default for all routers.
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #911 +/- ##
==========================================
- Coverage 87.91% 78.71% -9.21%
==========================================
Files 107 108 +1
Lines 8145 8199 +54
==========================================
- Hits 7161 6454 -707
- Misses 984 1745 +761 ☔ View full report in Codecov by Sentry. |
piccolo/apps/asgi/commands/new.py
Outdated
ADMIN_DEPENDENCIES = ["piccolo_admin>=1.0.0"] | ||
ROUTER_DEPENDENCIES = { | ||
"fastapi": ["fastapi>=0.100.0"], | ||
"starlette": ["starlette", *ADMIN_DEPENDENCIES], | ||
"fastapi": ["fastapi>=0.100.0", *ADMIN_DEPENDENCIES], | ||
"blacksheep": ["blacksheep", *ADMIN_DEPENDENCIES], | ||
"litestar": ["litestar", *ADMIN_DEPENDENCIES], | ||
# We don't currently use Piccolo Admin with esmerald, due to dependency | ||
# conflicts with FastAPI. We'll revisit this at some point in the future | ||
# when newer versions of FastAPI are released (DT - 12th December 2023). | ||
"esmerald": ["esmerald"], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to omit piccolo_admin
from esmerald
this way instead of having this in requirements.txt.jinja
:
{% if "esmerald" not in router_dependencies %}
piccolo_admin
{% endif %}
Because at some point I'd like to version pin the routers a bit more. So it might be that we have esmerald>X.X.X
in which case the if
statement would fail.
piccolo[postgres] | ||
piccolo_admin | ||
requests | ||
piccolo[postgres]>=1.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this will cause any problems ... i.e. it means that all of routers must support Pydantic v2. Will see when the CI runs.
@dantownsend This should work because all router frameworks, used by Piccolo, support Pydantic v2, but I want to try each router template to be sure. I'll do it tonight because I can't right now, if you're okay with that? |
@sinisaos No worries - thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes from this PR are good and don't affect how the Piccolo asgi template works, but I found two things that don't work. First is that Litestar Swagger docs don't work, but that's not on our side. Fix for that is made in Litestar main branch but not released yet (when they release new version everything will be fine - see issue). Second thing is for Esmerald. We have to remove "piccolo_admin.piccolo_app"
only for Esmerald template from here
apps=["home.piccolo_app", "piccolo_admin.piccolo_app"] |
APP_REGISTRY
Unable to connect to database
exception is raised and we can't run migrations for home
app. We can use something like this.
{% if router == 'esmerald' %}
APP_REGISTRY = AppRegistry(
apps=["home.piccolo_app"]
)
{% else %}
APP_REGISTRY = AppRegistry(
apps=["home.piccolo_app", "piccolo_admin.piccolo_app"]
)
{% endif %}
It is also necessary to somehow notify the user that they cannot currently run session_auth
and user
migrations for Esmerald (dependency conflicts with FastAPI)
@sinisaos Good points. Let's not worry about With |
That would be great. I found another small issue with Blacksheep and Pydantic v2. If we create a Pydantic model with I think it's not a Piccolo problem, but a problem with the old version of SwaggerUI in BlackSheep. If I change I know you have been in contact with the author of BlackSheep for mounting the ASGI apps to BlackSheep (for Piccolo Admin). If you could raise issue in their repo, referring to this issue, that would be great. |
Litestar problem is solved with newest version (v2.4.4) |
BlackSheep issue will also be resolved with the next BlackSheep release (SwaggerUI has been upgraded in the BlackSheep |
@sinisaos Great, thanks a lot for checking that 👍 |
@dantownsend FastAPI has been upgraded (Starlette >=0.29.0,<0.33.0) and we can now add Piccolo Admin to the Esmerald template. The integration test passed, but when I try to make a new Esmerald project in a fresh virtualenv, I had problems pip installing awesome-slugify (an Esmerald dependency) @tarsil, can you check it? |
Thank you @sinisaos I created actually some venvs in the past with all python versions and no issues were found. What error are you receiving? |
@tarsil I'm not at my machine right now, but when I can, I'll post the error log here. I tried Py3.9, Py3.10, Py3.11 and always got the same error (can't install |
Also away for a couple of days and then I will be back at my machine but it is a first like this |
@tarsil I'm very sorry, but the problem was my machine (very strange, but somehow setuptools was not installed when I created a new virtualenv and that caused problems with installing Esmerald). After restarting the laptop, everything is fine. |
Thank you @sinisaos for confirming. This was indeed odd but it could have happened |
@sinisaos Cool, thanks for checking. It'll be much easier to not exclude Piccolo Admin. |
@dantownsend Now that FastAPI is upgraded there is no need to exclude Piccolo Admin. Just need to add ADMIN_DEPENDENCIES to # in _esmerald_app.py.jinja
from piccolo_admin.endpoints import create_admin
...
app = Esmerald(
routes=[
Gateway("/", handler=home),
Gateway("/tasks", handler=TaskAPIView),
Include(
"/admin/",
create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
),
),
],
static_files_config=StaticFilesConfig(path="/static", directory=Path("static")),
on_startup=[open_database_connection_pool],
on_shutdown=[close_database_connection_pool],
) and we can use Piccolo Admin in Esmerald template. |
Related to #907
jinja2
as it's already a direct dependency of Piccolorequests
as I don't think it's needed any more (I think this was for Starlette at some point)piccolo_admin
foresmerald