-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add support for Esmerald #907
Add support for Esmerald #907
Conversation
tarsil
commented
Dec 1, 2023
- Adding support for Esmerald with Piccolo.
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 #907 +/- ##
=======================================
Coverage 92.03% 92.03%
=======================================
Files 107 107
Lines 8145 8145
=======================================
Hits 7496 7496
Misses 649 649 ☔ View full report in Codecov by Sentry. |
@tarsil Thanks for this. If you add piccolo/piccolo/apps/asgi/commands/new.py Line 13 in b8026da
Then when someone uses If you need to lock piccolo/piccolo/apps/asgi/commands/new.py Lines 14 to 16 in b8026da
We run integration tests against all of the ASGI frameworks that Piccolo supports: https://github.com/piccolo-orm/piccolo/blob/master/tests/apps/asgi/commands/test_new.py We basically test that the generated Python code is valid, and we run a really simplistic ASGI server to make sure the app runs. |
Hi @dantownsend thank you for your message. I will have a look at all of this in the next days (not in my machine at the moment) but I was also wondering where I could do that test you mentioned. Great to know. Great ORM btw 🙂 EDIT: I was able to add the missing one. Is this ok now? |
@tarsil Yep, that's it. The test will run in our CI now. If you ever need to run it locally you can use |
@dantownsend not sure what happened with that flow. Can we re-run it? Because the rest is passing |
@tarsil It looks like there's a dependency issue. Piccolo Admin has FastAPI as a dependency, which itself depends on Starlette. FastAPI has very narrowly defined dependency versions which means it sometimes doesn't play well with other libraries which depend on Starlette etc. Which version of Starlette does |
@dantownsend I see. I know that limitation from Fast. Esmerald uses the version 0.32.0.post1. Besides the lastest released today basically |
@dantownsend let me know your thoughts how to go from here then if you don't mind |
@tarsil I think the problem is that But the latest FastAPI only supports So when trying to I think the only solutions are:
It's a shame that FastAPI is like this, because it makes it makes it harder for libraries based on |
@dantownsend thank you for this detailed explanation. I will be releasing a version soon and I can lose some tight versions and put it in a range. This way it will allow the same version of Starlette to be installed 🙂. I will let you know once it's released and maybe we can rerun the CI? It's great piccolo admin to use FastAPI actually. While I do this change for a release, if you want to have a look at Esmerald just for the knowledge, feel free and I would appreciate any constructive feedback anyway 🙂 |
@tarsil ok, cool - let me know when the new version is out, and I'll rerun the CI. I'll have a look at the docs 👍 |
@dantownsend I did a new release today and made the requirements more broad, from >=0.28.0,<=0.32.0.post1. I think this should now do the trick? |
@tarsil Thanks, I'll re-run the CI now. |
@dantownsend is still the same issue happening? |
@tarsil Yeah, it's another dependency clash. If you make a virtualenv, and make this
|
piccolo/apps/asgi/commands/templates/app/_esmerald_app.py.jinja
Outdated
Show resolved
Hide resolved
piccolo/apps/asgi/commands/templates/app/home/_esmerald_endpoints.py.jinja
Outdated
Show resolved
Hide resolved
@dantownsend Sorry to interfere into the conversation, but I think you're right that we'll have to wait for FastAPI to upgrade the Starlette version (and there's nothing we can do about that). I had no problems with Pydantic and the only thing I had to do was remove the Piccolo admin from the Esmerald template which removes FastAPI as a dependency (and some other small changes I wrote suggestions for) and then the integration tests passed locally for me. @tarsil I left some suggestions for PR. You should also add Esmerald to endpoints.py.jinja like this. {% if router in ['fastapi', 'starlette'] %}
{% include '_starlette_endpoints.py.jinja' %}
{% elif router == 'blacksheep' %}
{% include '_blacksheep_endpoints.py.jinja' %}
{% elif router == 'litestar' %}
{% include '_litestar_endpoints.py.jinja' %}
{% elif router == 'esmerald' %}
{% include '_esmerald_endpoints.py.jinja' %}
{% endif %} After these suggested changes (you should also remove the Piccolo Admin import and |
@sinisaos thank you very much for the suggestions above. Odd as my local version has something like you suggested. Maybe I actually didn't push what I needed before but either way, this is great. Thank you so much. I will do the changes in the next few days |
…nts.py.jinja Co-authored-by: sinisaos <sinisaos@gmail.com>
Co-authored-by: sinisaos <sinisaos@gmail.com>
@sinisaos i applied your suggestions. I confirm that in my local I actually had similar but not pushed since the MediaType is actually inside the enums but we actually don't use it here. The last suggestion, if I'm not mistaken it was already in the PR but I appreciate that. @dantownsend i think with these changes suggested by @sinisaos , we can try again after I ran these locally, if you don't mind? I will come back you soon and maybe we could try again. Although it won't hurt trying again here anyway in the meantime. |
@tarsil No problem. I'm always glad if I can help somehow. As for Piccolo Admin, unfortunately, I think we have to wait for the FastAPI upgrade, which is not always very fast.
You're right. I wrote it wrong (but I thought), you have to add Esmerald here as well Also remove the Piccolo Admin import and |
Will definitely do @sinisaos thank you once again |
@sinisaos I'm actually still having some issues locally. How it does look like in your final In theory I did remove the |
@tarsil You also need to add Emserald here like this {% if router == 'fastapi' %}
{% include '_fastapi_app.py.jinja' %}
{% elif router == 'starlette' %}
{% include '_starlette_app.py.jinja' %}
{% elif router == 'blacksheep' %}
{% include '_blacksheep_app.py.jinja' %}
{% elif router == 'litestar' %}
{% include '_litestar_app.py.jinja' %}
{% elif router == 'esmerald' %}
{% include '_esmerald_app.py.jinja' %}
{% endif %} to add |
Ahhhh, yes, totally missed that one and yet you mentioned but I was mistaken with another file. Done! If we could run the CI here to see, that would be great @sinisaos @dantownsend . Hopefully now we can merge this and once FastAPI moves some of the versions up, we can add the admin as well. Thank you very much for your help @sinisaos , you are a ⭐ . I used Piccolo with Esmerald a few versions ago (of Esmerald) and I simply loved it. The tests passed now locally. |
@tarsil I'm glad you made it 😃 . For re-run in CI you must wait for @dantownsend. Just two more small thing. static_files_config=StaticFilesConfig(path="/", directory=Path("static")), to static_files_config=StaticFilesConfig(path="/static", directory=Path("static")), in Esmerald application class, to make static files work. |
Oh, true, I was doing an experiment in the static files config and forgot to add back the /static, nice catch (been doing so many things that I miss a lot sometimes). The tasks path should now be correct. Nice suggestions @sinisaos . I'm actually happily impressed how clear you are with Esmerald 😃 |
@tarsil Great. Thanks for the kind words. |
I'm the one who needs to thank you. Without your help I would take longer to get this done 🙂. I hope you like Esmerald to be honest 🙂 |
It looks like the tests are passing. @sinisaos thanks for your help with this. So it looks like Piccolo Admin was omitted to get around the dependency issues, which I think makes sense. But as Piccolo Admin is in It still gets installed. I checked the logs for the integration tests, and it installed a really old version of Piccolo Admin. As We could do something simple like: {% if 'esmerald' not in router_dependencies %}
piccolo_admin
{% endif } There might be a cleaner way of doing this. In here instead: It could be: ROUTERS = ["starlette", "fastapi", "blacksheep", "litestar"]
ROUTER_DEPENDENCIES = {
"starlette": ["starlette", "piccolo_admin"],
"fastapi": ["fastapi>=0.100.0", "piccolo_admin"],
"blacksheep": ["blacksheep", "piccolo_admin"],
"litestar": ["litestar", "piccolo_admin"],
"esmerald": ["esmerald"],
} I noticed that We might be able to remove both of these. |
@dantownsend based what you have said, which makes sense, what do you say you create a code change suggestion and we can simply merge it? I'm sure you are more familiar with this procedure than I am and this way we can move forward? Or we simply merge this and open another PR to simply do those changes since it might imply some other aspects that we might have not caught up so far |
piccolo/apps/asgi/commands/templates/app/_esmerald_app.py.jinja
Outdated
Show resolved
Hide resolved
Co-authored-by: sinisaos <sinisaos@gmail.com>
@dantownsend Unfortunately this does not run the tests for
I think this is much better:
so {%- for router_dependency in router_dependencies -%}
{{ router_dependency }}
{% endfor -%}
{{ server }}
piccolo[postgres]
{% if not 'esmerald' in router_dependencies %}
piccolo_admin
{% endif %} This runs the tests but does not install Piccolo Admin for Esmerald. |
If @dantownsend is happy with that, @sinisaos you can add as suggestion for change as well |
@tarsil You'll have to wait for @dantownsend . If that's good enough, you or @dantownsend need to add it because |
@sinisaos of course! Thank you, if @dantownsend agrees, I can add it to the PR. |