Skip to content

Commit

Permalink
Merge pull request #18944 from mvdbeek/no_async_if_async_no_good
Browse files Browse the repository at this point in the history
[24.1] Don't use ``async def`` where not appropriate
  • Loading branch information
mvdbeek authored Oct 7, 2024
2 parents f670f0f + 7b54d64 commit 05a3aa8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
12 changes: 6 additions & 6 deletions lib/galaxy/webapps/galaxy/api/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class FastAPIPages:
summary="Lists all Pages viewable by the user.",
response_description="A list with summary page information.",
)
async def index(
def index(
self,
response: Response,
trans: ProvidesUserContext = DependsOnTrans,
Expand Down Expand Up @@ -153,7 +153,7 @@ def create(
summary="Marks the specific Page as deleted.",
status_code=status.HTTP_204_NO_CONTENT,
)
async def delete(
def delete(
self,
id: PageIdPathParam,
trans: ProvidesUserContext = DependsOnTrans,
Expand All @@ -167,7 +167,7 @@ async def delete(
summary="Undelete the specific Page.",
status_code=status.HTTP_204_NO_CONTENT,
)
async def undelete(
def undelete(
self,
id: PageIdPathParam,
trans: ProvidesUserContext = DependsOnTrans,
Expand All @@ -188,7 +188,7 @@ async def undelete(
501: {"description": "PDF conversion service not available."},
},
)
async def show_pdf(
def show_pdf(
self,
id: PageIdPathParam,
trans: ProvidesUserContext = DependsOnTrans,
Expand All @@ -210,7 +210,7 @@ async def show_pdf(
501: {"description": "PDF conversion service not available."},
},
)
async def prepare_pdf(
def prepare_pdf(
self,
id: PageIdPathParam,
trans: ProvidesUserContext = DependsOnTrans,
Expand All @@ -226,7 +226,7 @@ async def prepare_pdf(
summary="Return a page summary and the content of the last revision.",
response_description="The page summary information.",
)
async def show(
def show(
self,
id: PageIdPathParam,
trans: ProvidesUserContext = DependsOnTrans,
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/webapps/galaxy/api/remote_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FastAPIRemoteFiles:
deprecated=True,
summary="Displays remote files available to the user. Please use /api/remote_files instead.",
)
async def index(
def index(
self,
response: Response,
user_ctx: ProvidesUserContext = DependsOnTrans,
Expand Down Expand Up @@ -157,7 +157,7 @@ async def index(
summary="Display plugin information for each of the gxfiles:// URI targets available.",
response_description="A list with details about each plugin.",
)
async def plugins(
def plugins(
self,
user_ctx: ProvidesUserContext = DependsOnTrans,
browsable_only: Annotated[Optional[bool], BrowsableQueryParam] = True,
Expand All @@ -176,7 +176,7 @@ async def plugins(
"/api/remote_files",
summary="Creates a new entry (directory/record) on the remote files source.",
)
async def create_entry(
def create_entry(
self,
user_ctx: ProvidesUserContext = DependsOnTrans,
payload: CreateEntryPayload = Body(
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/webapps/galaxy/api/tool_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def index(self) -> ToolDataEntryList:
summary="Import a data manager bundle",
require_admin=True,
)
async def create(
def create(
self, tool_data_file_path: Optional[str] = None, import_bundle_model: ImportToolDataBundle = Body(...)
) -> AsyncTaskResultSummary:
source = import_bundle_model.source
Expand All @@ -91,7 +91,7 @@ async def show(self, table_name: str = ToolDataTableName) -> ToolDataDetails:
response_description="A description of the reloaded data table and its content",
require_admin=True,
)
async def reload(self, table_name: str = ToolDataTableName) -> ToolDataDetails:
def reload(self, table_name: str = ToolDataTableName) -> ToolDataDetails:
"""Reloads a data table and return its details."""
return self.tool_data_manager.reload(table_name)

Expand All @@ -116,7 +116,7 @@ async def show_field(
response_class=GalaxyFileResponse,
require_admin=True,
)
async def download_field_file(
def download_field_file(
self,
table_name: str = ToolDataTableName,
field_name: str = ToolDataTableFieldName,
Expand All @@ -136,7 +136,7 @@ async def download_field_file(
response_description="A description of the affected data table and its content",
require_admin=True,
)
async def delete(
def delete(
self,
payload: ToolDataItem,
table_name: str = ToolDataTableName,
Expand Down
28 changes: 15 additions & 13 deletions lib/galaxy/webapps/galaxy/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,37 @@ class JsonApiRoute(APIContentTypeRoute):
FetchDataForm = as_form(FetchDataFormPayload)


async def get_files(request: Request, files: Optional[List[UploadFile]] = None):
# FastAPI's UploadFile is a very light wrapper around starlette's UploadFile
files2: List[StarletteUploadFile] = cast(List[StarletteUploadFile], files or [])
if not files2:
data = await request.form()
for value in data.values():
if isinstance(value, StarletteUploadFile):
files2.append(value)
return files2


@router.cbv
class FetchTools:
service: ToolsService = depends(ToolsService)

@router.post("/api/tools/fetch", summary="Upload files to Galaxy", route_class_override=JsonApiRoute)
async def fetch_json(self, payload: FetchDataPayload = Body(...), trans: ProvidesHistoryContext = DependsOnTrans):
def fetch_json(self, payload: FetchDataPayload = Body(...), trans: ProvidesHistoryContext = DependsOnTrans):
return self.service.create_fetch(trans, payload)

@router.post(
"/api/tools/fetch",
summary="Upload files to Galaxy",
route_class_override=FormDataApiRoute,
)
async def fetch_form(
def fetch_form(
self,
request: Request,
payload: FetchDataFormPayload = Depends(FetchDataForm.as_form),
files: Optional[List[UploadFile]] = None,
trans: ProvidesHistoryContext = DependsOnTrans,
files: List[StarletteUploadFile] = Depends(get_files),
):
files2: List[StarletteUploadFile] = cast(List[StarletteUploadFile], files or [])

# FastAPI's UploadFile is a very light wrapper around starlette's UploadFile
if not files2:
data = await request.form()
for value in data.values():
if isinstance(value, StarletteUploadFile):
files2.append(value)
return self.service.create_fetch(trans, payload, files2)
return self.service.create_fetch(trans, payload, files)


class ToolsController(BaseGalaxyAPIController, UsesVisualizationMixin):
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FastAPIVisualizations:
"/api/visualizations",
summary="Returns visualizations for the current user.",
)
async def index(
def index(
self,
response: Response,
trans: ProvidesUserContext = DependsOnTrans,
Expand Down

0 comments on commit 05a3aa8

Please sign in to comment.