Skip to content

Commit

Permalink
fix: properly monkey-patch Catalog class using MethodType
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioHeredia committed Apr 5, 2024
1 parent 9f7ce1f commit ce8156b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 6 additions & 5 deletions ai4papi/routers/v1/catalog/modules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import configparser
from copy import deepcopy
import re
import types

from cachetools import cached, TTLCache
from fastapi import APIRouter
Expand All @@ -13,8 +14,7 @@


@cached(cache=TTLCache(maxsize=1024, ttl=6*60*60))
def get_list(
):
def get_list(self):
"""
Retrieve a list of *all* modules.
Expand All @@ -37,9 +37,10 @@ def get_list(


def get_config(
self,
item_name: str,
vo: str,
):
):
"""
Returns the default configuration (dict) for creating a deployment
for a specific module. It is prefilled with the appropriate
Expand Down Expand Up @@ -81,8 +82,8 @@ def get_config(


Modules = Catalog()
Modules.get_list = get_list
Modules.get_config = get_config
Modules.get_list = types.MethodType(get_list, Modules)
Modules.get_config = types.MethodType(get_config, Modules)


router = APIRouter(
Expand Down
12 changes: 7 additions & 5 deletions ai4papi/routers/v1/catalog/tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from copy import deepcopy
import json
import types

from cachetools import cached, TTLCache
from fastapi import APIRouter, HTTPException
Expand All @@ -13,8 +14,7 @@


@cached(cache=TTLCache(maxsize=1024, ttl=6*60*60))
def get_list(
):
def get_list(self):
"""
Retrieve a list of *all* modules.
Expand All @@ -27,6 +27,7 @@ def get_list(

@cached(cache=TTLCache(maxsize=1024, ttl=6*60*60))
def get_metadata(
self,
item_name: str,
):
"""
Expand Down Expand Up @@ -72,6 +73,7 @@ def get_metadata(


def get_config(
self,
item_name: str,
vo: str,
):
Expand Down Expand Up @@ -110,9 +112,9 @@ def get_config(


Tools = Catalog()
Tools.get_list = get_list
Tools.get_config = get_config
Tools.get_metadata = get_metadata
Tools.get_list = types.MethodType(get_list, Tools)
Tools.get_config = types.MethodType(get_config, Tools)
Tools.get_metadata = types.MethodType(get_metadata, Tools)


router = APIRouter(
Expand Down

0 comments on commit ce8156b

Please sign in to comment.