Commit cee72f63 authored by Pierre Dittgen's avatar Pierre Dittgen

Get rid of cachetools dependency

parent 128689fe
Pipeline #1018 failed with stage
in 21 seconds
...@@ -54,7 +54,6 @@ setup( ...@@ -54,7 +54,6 @@ setup(
'backports-datetime-fromisoformat', 'backports-datetime-fromisoformat',
'cachecontrol', 'cachecontrol',
'cachetools',
'commonmark', 'commonmark',
'ezodf', 'ezodf',
'flask', 'flask',
......
...@@ -9,7 +9,6 @@ import flask ...@@ -9,7 +9,6 @@ import flask
import jinja2 import jinja2
import requests import requests
import tableschema import tableschema
from cachetools.func import ttl_cache
import opendataschema import opendataschema
...@@ -18,9 +17,16 @@ from . import config ...@@ -18,9 +17,16 @@ from . import config
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ttl_cache(maxsize=24, ttl=5*60) def generate_schema_from_url_func(session):
def schema_from_url(url): """Generates a function that encloses session"""
return tableschema.Schema(url)
def schema_from_url(url):
req = session.get(url)
req.raise_for_status()
schema_dict = req.json()
return tableschema.Schema(schema_dict)
return schema_from_url
# And load schema catalogs which urls are found in config.json # And load schema catalogs which urls are found in config.json
...@@ -28,6 +34,7 @@ schema_catalog_map = {} ...@@ -28,6 +34,7 @@ schema_catalog_map = {}
if config.HOMEPAGE_CONFIG: if config.HOMEPAGE_CONFIG:
log.info("Initializing homepage sections...") log.info("Initializing homepage sections...")
caching_session = cachecontrol.CacheControl(requests.Session()) caching_session = cachecontrol.CacheControl(requests.Session())
schema_from_url = generate_schema_from_url_func(caching_session)
for section in config.HOMEPAGE_CONFIG['sections']: for section in config.HOMEPAGE_CONFIG['sections']:
if isinstance(section['catalog'], str) and section['catalog'].startswith('http'): if isinstance(section['catalog'], str) and section['catalog'].startswith('http'):
code = section['code'] code = section['code']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment