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

FastAPI port of API/Studio, second time around #360

Merged
merged 18 commits into from
Apr 17, 2024
Merged

FastAPI port of API/Studio, second time around #360

merged 18 commits into from
Apr 17, 2024

Conversation

dhdaines
Copy link
Collaborator

@dhdaines dhdaines commented Apr 4, 2024

This time with backwards compatibility and testing! Wow!

Copy link

codecov bot commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 98.63014% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.84%. Comparing base (7ec44b3) to head (9bc3855).

❗ Current head 9bc3855 differs from pull request most recent head 2d68577. Consider uploading reports for the commit 2d68577 to get more accurate results

Files Patch % Lines
g2p/app.py 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
+ Coverage   93.77%   93.84%   +0.07%     
==========================================
  Files          16       16              
  Lines        2328     2291      -37     
  Branches      517      516       -1     
==========================================
- Hits         2183     2150      -33     
+ Misses         82       79       -3     
+ Partials       63       62       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Apr 4, 2024

CLI load time: 0:00.05
PR head 2d6857776b0dd4bd0d2d8dd995c780ab60ea34fb
Imports that take more than 0.1 s:
import time: self [us] | cumulative | imported package

@dhdaines
Copy link
Collaborator Author

dhdaines commented Apr 4, 2024

Note that fastapi-socketio is really broken, so it would probably be better to not use it: pyropy/fastapi-socketio#52

In the end there's very little actual code in it so we can just use socketio directly.

@dhdaines
Copy link
Collaborator Author

dhdaines commented Apr 4, 2024

Also note that this would mean that the API and Studio require Python 3.8, so not sure if we want to go there...

@joanise
Copy link
Collaborator

joanise commented Apr 5, 2024

Also note that this would mean that the API and Studio require Python 3.8, so not sure if we want to go there...

The Web API already requires Python 3.8, we only continue to support 3.7 for the programmatic Python API, i.e., g2p as a Python module.

@dhdaines
Copy link
Collaborator Author

dhdaines commented Apr 5, 2024

Also note that this would mean that the API and Studio require Python 3.8, so not sure if we want to go there...

The Web API already requires Python 3.8, we only continue to support 3.7 for the programmatic Python API, i.e., g2p as a Python module.

Ah, of course - then there's no problem since the API is a separate, optional dependency here. But we need to separate the test suites so that we can test the non-API parts with 3.7.

@dhdaines
Copy link
Collaborator Author

dhdaines commented Apr 5, 2024

Also, not quite sure what's going wrong with coverage in CI here, it gives the correct results when I run it locally.

Copy link
Collaborator

@joanise joanise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like these changes, although on my end g2p-studio is broken on this branch, I don't know if I'm doing something wrong or if it's a bug.
I better get my act together and review your hatch PR, but having installed using hatch for this branch I'm already pretty much on-board now.

CI coverage: I don't know what's going on.

I've left notes about the clunky way I've been making sure we're still exercising Python 3.7 in CI. I'm open to better suggestions: the actual goal is that some part of CI should exercise g2p as a Python module and CLI command (i.e., all the tests that don't involve g2p-studio or the REST API) with Python 3.7. I'm not attached to how we get there, just that we do it. And that's a hint that my documentation was sorely inadequate, nothing in there pointed out that goal.

.github/workflows/tests.yml Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved

python run_studio.py

It does not seem that any equivalents of `routes` or `shell` exist.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here this is conflating the migration from 1.x to 2.0 and from 2.0 to what will probably have to be 2.1 or possibly even 3.0 if this is not backwards compatible. While I don't think we need a separate migrating to 2.1 file, I think this section should distinguish between migrating to 2.0 (previous text) and to 2.1 new text like you're writing here.
Side note: losing routes is unfortunate. But I assume there's some other form of auto-generated API documentation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, there's the auto-generated online API documentation, which is arguably more useful anyway...

g2p/app.py Show resolved Hide resolved
g2p/app.py Show resolved Hide resolved
g2p/app.py Show resolved Hide resolved
@joanise
Copy link
Collaborator

joanise commented Apr 15, 2024

I believe this will be ready to merge, with #363 and a redirect link from /docs to /api/v1/docs, although when we also merge the v2, we might want a page listing both instead of an actual redirect...

g2p/app.py Show resolved Hide resolved
run_studio.py Show resolved Hide resolved
g2p/app.py Show resolved Hide resolved
joanise and others added 2 commits April 17, 2024 14:28
All production API code, and API testing code, requires Python 3.7, but
the base g2p CLI and library module still support Python 3.7 and need to
be testing in CI.
@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

Meh, I'm being bitten by a stale environment again. I'll create something fresh to test.

@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

I hate dependency hell!

@dhdaines
Copy link
Collaborator Author

I hate dependency hell!

Hm, I'm really surprised this is happening ... I didn't have to change anything in my environment, the packages are the same as before the last updates except that we aren't using some of the ones we were previously...

@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

Found it:

     "starlette>=0.35.1",
-    "python-socketio>=5",
+    "python-socketio>=5.9.0",
     "uvicorn",

@dhdaines
Copy link
Collaborator Author

Found it:

     "starlette>=0.35.1",
-    "python-socketio>=5",
+    "python-socketio>=5.9.0",
     "uvicorn",

aaah ... okay, I put python-socketio>=5 because that's what supports the same protocol as the JavaScript side, but I'll apply this fix (presuming there is no problem with Python 3.8)

@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

That's the minimum required patch. On a stale environment with python-socketio==5.8.0 I got exceptions like this from ./run_studio.py:

WARNING:  No supported WebSocket library detected. Please use 'pip install uvicorn[standard]', or install 'websockets' or 'wsproto' manually.
INFO:     127.0.0.1:62614 - "GET /ws/socket.io/?EIO=4&transport=websocket HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):

A simpler fix was to install uvicorn[standard], but that installed quite a few more things. Just python-socketio==5.9.0 gave me simple-websocket==1.0.0 as a side effect and that was enough.

I suppose we could also declare simple-websocket ourselves in the api dependency block.

@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

Warning: you accidentally undid #365. Maybe we need to make the change in pyproject.toml too. That fixes a prod CVE, so we really want to apply it.

@dhdaines
Copy link
Collaborator Author

Warning: you accidentally undid #365. Maybe we need to make the change in pyproject.toml too. That fixes a prod CVE, so we really want to apply it.

Oh, oops. This may be due to "git rebase"'s merge conflicts being backwards and hard to understand.

@dhdaines
Copy link
Collaborator Author

Warning: you accidentally undid #365. Maybe we need to make the change in pyproject.toml too. That fixes a prod CVE, so we really want to apply it.

Oh, oops. This may be due to "git rebase"'s merge conflicts being backwards and hard to understand.

I don't understand, though ... how did the updated gunicorn dependency disappear from the main branch?

@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

Alright, finally I can say I agree: we're there! We can merge this.

Thank you for your patience working through all the details, and putting up with my stale environments which, while annoying, bring us to express our actual dependencies more accurately, so I don't actually feel bad about it. 😉

Copy link
Collaborator

@joanise joanise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@dhdaines dhdaines merged commit 75b7420 into main Apr 17, 2024
4 checks passed
@dhdaines dhdaines deleted the dev.fastapi branch April 17, 2024 21:12
@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

Oh, oops. This may be due to "git rebase"'s merge conflicts being backwards and hard to understand.

I don't understand, though ... how did the updated gunicorn dependency disappear from the main branch?

You almost certainly made a mistake in handling a merge conflict.

This is the commit that undoes it:

commit cfc50c6ef1
Author: David Huggins-Daines <dhd@ecolingui.ca>
Date:   Thu Apr 4 10:09:02 2024 -0400

    fix: update prod environment and workflow

@joanise
Copy link
Collaborator

joanise commented Apr 17, 2024

In your defense, merge conflict resolution is indeed quite confusing. I'm quite paranoid about them, often doing extensive reviewing of the commit I'm trying to rebase and the changes that were there before, and not just relying on the conflict resolution tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants