Commit f5d6dab3 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Use black

parent 484a9b1e
......@@ -56,7 +56,11 @@ if config.CONFIG:
name = section.name
log.info('Initializing homepage section "{}"...'.format(name))
if section.catalog:
catalog_ref = str(section.catalog) if isinstance(section.catalog, HttpUrl) else section.catalog.dict()
catalog_ref = (
str(section.catalog)
if isinstance(section.catalog, HttpUrl)
else section.catalog.dict()
)
schema_catalog_registry.add_ref(name, catalog_ref)
log.info("...done")
......
"""Configuration stuff."""
import yaml
import logging
import os
......@@ -9,7 +11,7 @@ import toml
from dotenv import load_dotenv
from pydantic.error_wrappers import ValidationError
from . model import Config
from .model import Config
log = logging.getLogger(__name__)
......@@ -17,13 +19,14 @@ load_dotenv()
def without_trailing_slash(url):
"""Strip trailing slash if exists."""
return url[:-1] if url.endswith("/") else url
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
numeric_log_level = getattr(logging, LOG_LEVEL.upper(), None)
if not isinstance(numeric_log_level, int):
log.error("Invalid log level: {}".format(LOG_LEVEL))
log.error("Invalid log level: %s", LOG_LEVEL)
logging.basicConfig(
format="%(levelname)s:%(name)s:%(message)s",
level=numeric_log_level,
......@@ -35,11 +38,16 @@ SECRET_KEY = os.environ.get("SECRET_KEY") or None
BADGE_CONFIG_URL = os.environ.get("BADGE_CONFIG_URL") or None
BADGE_CONFIG = None
if BADGE_CONFIG_URL is None:
log.warning("BADGE_CONFIG_URL environment variable is not set, disable badge feature")
log.warning(
"BADGE_CONFIG_URL environment variable is not set, disable badge feature"
)
else:
response = requests.get(BADGE_CONFIG_URL)
if not response.ok:
log.warning("Can't retrieve badge config from [%s], disable badge feature", BADGE_CONFIG_URL)
log.warning(
"Can't retrieve badge config from [%s], disable badge feature",
BADGE_CONFIG_URL,
)
else:
BADGE_CONFIG = toml.loads(response.text)
......
......@@ -7,6 +7,7 @@ class Link(BaseModel):
title: str
url: HttpUrl
class ExternalLink(BaseModel):
name: str
type: str
......@@ -14,14 +15,17 @@ class ExternalLink(BaseModel):
description: str
website: HttpUrl
class Schema(BaseModel):
name: str
repo_url: HttpUrl
class Catalog(BaseModel):
version: int
schemas: List[Schema]
class Section(BaseModel):
name: str
title: str
......@@ -37,16 +41,21 @@ class Section(BaseModel):
if catalog is not None and links is not None:
raise ValueError("only one of catalog and links must be defined")
return values
class Footer(BaseModel):
links: List[Link]
class Header(BaseModel):
links: List[Link]
class Homepage(BaseModel):
sections: List[Section]
class Config(BaseModel):
footer: Footer
header: Header
homepage: Homepage
\ No newline at end of file
homepage: Homepage
......@@ -2,6 +2,7 @@
import unicodedata
def strip_accents(s):
"""Remove accents from string, used to sort normalized strings"""
return "".join(
......
......@@ -20,7 +20,11 @@ from flask import abort, make_response, redirect, render_template, request, url_
from opendataschema import GitSchemaReference, by_commit_date
import validata_core
from validata_core.helpers import ValidataResource, URLValidataResource, FileContentValidataResource
from validata_core.helpers import (
ValidataResource,
URLValidataResource,
FileContentValidataResource,
)
from . import app, config, schema_catalog_registry, fetch_schema
from .model import Section
......@@ -491,9 +495,7 @@ def create_validata_ui_report(validata_core_report, schema_dict):
error_stats = {
"count": key_errors_count,
"count-by-code": sorted(
(k, v) for k, v in ct.items()
),
"count-by-code": sorted((k, v) for k, v in ct.items()),
}
total_errors_count += key_errors_count
......@@ -564,7 +566,9 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc
badge_url, badge_msg = None, None
display_badge = badge_config and config.SHIELDS_IO_BASE_URL
if display_badge:
badge_stats = validata_core.compute_badge_metrics(validata_core_report, badge_config)
badge_stats = validata_core.compute_badge_metrics(
validata_core_report, badge_config
)
badge_url, badge_msg = get_badge_url_and_message(badge_stats)
# Source error
......@@ -596,7 +600,7 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc
schema_info = compute_schema_info(schema_instance.schema, schema_instance.url)
# Build PDF report URL
# PDF report is available only when resource are URL as it require to download them again
# PDF report is available only when resource are URL as it require to download them again
pdf_report_url = None
if isinstance(validata_resource, URLValidataResource):
base_url = url_for("pdf_report")
......@@ -742,7 +746,9 @@ def home():
"catalog": schema_info_list,
}
return render_template("home.html", config=config.CONFIG, sections=list(iter_sections()))
return render_template(
"home.html", config=config.CONFIG, sections=list(iter_sections())
)
@app.route("/pdf")
......@@ -796,7 +802,9 @@ def pdf_report():
datetime.now().strftime("%d-%m-%Y %Hh%M")
)
response = make_response(tmp_pdf_report.read_bytes())
response.headers.set("Content-disposition", "attachment", filename=pdf_filename)
response.headers.set(
"Content-disposition", "attachment", filename=pdf_filename
)
response.headers.set("Content-type", "application/pdf")
response.headers.set("Content-length", tmp_pdf_report.stat().st_size)
......
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