Commit 9fc18022 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Use black

parent a6e7f236
{
"baseUrl": "http://127.0.0.1:5601"
}
{"baseUrl": "http://127.0.0.1:5601"}
{
"sections": [
{
"name": "schema-catalog",
"title": "A catalog of schemas",
"description": "This is a catalog of schemas that is published somewhere. (Note: the catalog must be conform to this schema: https://opendataschema.frama.io/catalog/schema-catalog.json",
"catalog": "https://git.opendatafrance.net/scdl/catalog/raw/master/catalog.json"
},
{
"name": "schema-list",
"title": "A list of schemas",
"description": "This is a list of other schemas.",
"catalog": {
"version": 1,
"schemas": [
{
"repo_url": "https://github.com/CharlesNepote/liste-prenoms-nouveaux-nes/",
"schema_filename": "prenom-schema.json",
"doc_url_by_ref": {
"~latest_tag": "https://scdl.opendatafrance.net/docs/schemas/prenoms.html",
"next": "https://scdl.opendatafrance.net/docs-next/schemas/prenoms.html"
}
},
{
"name": "irve",
"repo_url": "https://github.com/etalab/schema-irve/",
"doc_url_by_ref": {
"~latest_tag": "https://scdl.opendatafrance.net/docs/schemas/irve.html",
"next": "https://scdl.opendatafrance.net/docs-next/schemas/irve.html"
}
}
]
}
},
{
"name": "external",
"title": "A list of links to external validators",
"description": "This is a selection of validation tools that complement Validata.",
"links": [
"sections": [
{
"name": "inspire",
"type": "external",
"title": "INSPIRE",
"description": "proposé par la Commission Européenne pour tester des ressources géographiques (données, services ou métadonnées)",
"website": "http://inspire-sandbox.jrc.ec.europa.eu/validator/"
"name": "schema-catalog",
"title": "A catalog of schemas",
"description": "This is a catalog of schemas that is published somewhere. (Note: the catalog must be conform to this schema: https://opendataschema.frama.io/catalog/schema-catalog.json",
"catalog": "https://git.opendatafrance.net/scdl/catalog/raw/master/catalog.json",
},
{
"name": "bal",
"type": "external",
"title": "BAL",
"description": "proposé par la mission Etalab pour tester des données Adresse produites localement (format BAL 1.1)",
"website": "https://adresse.data.gouv.fr/bases-locales/validateur"
}
]
}
]
"name": "schema-list",
"title": "A list of schemas",
"description": "This is a list of other schemas.",
"catalog": {
"version": 1,
"schemas": [
{
"repo_url": "https://github.com/CharlesNepote/liste-prenoms-nouveaux-nes/",
"schema_filename": "prenom-schema.json",
"doc_url_by_ref": {
"~latest_tag": "https://scdl.opendatafrance.net/docs/schemas/prenoms.html",
"next": "https://scdl.opendatafrance.net/docs-next/schemas/prenoms.html",
},
},
{
"name": "irve",
"repo_url": "https://github.com/etalab/schema-irve/",
"doc_url_by_ref": {
"~latest_tag": "https://scdl.opendatafrance.net/docs/schemas/irve.html",
"next": "https://scdl.opendatafrance.net/docs-next/schemas/irve.html",
},
},
],
},
},
{
"name": "external",
"title": "A list of links to external validators",
"description": "This is a selection of validation tools that complement Validata.",
"links": [
{
"name": "inspire",
"type": "external",
"title": "INSPIRE",
"description": "proposé par la Commission Européenne pour tester des ressources géographiques (données, services ou métadonnées)",
"website": "http://inspire-sandbox.jrc.ec.europa.eu/validator/",
},
{
"name": "bal",
"type": "external",
"title": "BAL",
"description": "proposé par la mission Etalab pour tester des données Adresse produites localement (format BAL 1.1)",
"website": "https://adresse.data.gouv.fr/bases-locales/validateur",
},
],
},
]
}
[isort]
line_length = 120
[pycodestyle]
max_line_length = 120
[pylint]
max_line_length = 120
[aliases]
test=pytest
[flake8]
# Recommend matching the black line length (default 88),
# rather than using the flake8 default of 79:
max-line-length = 88
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,
enable-extensions=G # for flake8-logging-format
[tool:pytest]
addopts = --doctest-modules
\ No newline at end of file
......@@ -7,68 +7,52 @@ from setuptools import setup
script_dir = Path(__file__).parent
# Gets the long description from the README.md file
readme_filepath = script_dir / 'README.md'
with readme_filepath.open('rt', encoding='utf-8') as fd:
readme_filepath = script_dir / "README.md"
with readme_filepath.open("rt", encoding="utf-8") as fd:
LONG_DESCRIPTION = fd.read()
setup(
name='validata_ui',
version='0.3.10',
description='Validata Web UI',
name="validata_ui",
version="0.3.10",
description="Validata Web UI",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
url='https://git.opendatafrance.net/validata/validata-ui',
author='Validata team',
author_email='admin-validata@jailbreak.paris',
license='AGPLv3',
url="https://git.opendatafrance.net/validata/validata-ui",
author="Validata team",
author_email="admin-validata@jailbreak.paris",
license="AGPLv3",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 5 - Production/Stable',
"Development Status :: 5 - Production/Stable",
# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Operating System :: OS Independent',
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: GNU Affero General Public License v3',
"License :: OSI Approved :: GNU Affero General Public License v3",
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3',
"Programming Language :: Python :: 3",
],
packages=['validata_ui'],
packages=["validata_ui"],
include_package_data=True,
package_data={
'validata_ui': ['templates/*', 'static/**/*'],
},
package_data={"validata_ui": ["templates/*", "static/**/*"],},
zip_safe=True,
install_requires=[
'backports-datetime-fromisoformat',
'cachecontrol',
'commonmark',
'ezodf',
'flask',
'lxml',
'python-dotenv',
'requests',
'sentry-sdk[flask]==0.14.3',
'toml',
'opendataschema >= 0.5.5, < 0.6',
"backports-datetime-fromisoformat",
"cachecontrol",
"commonmark",
"ezodf",
"flask",
"lxml",
"python-dotenv",
"requests",
"sentry-sdk[flask]==0.14.3",
"toml",
"opendataschema >= 0.5.5, < 0.6",
],
)
......@@ -55,14 +55,15 @@ fetch_schema = generate_schema_from_url_func(caching_session)
schema_catalog_registry = SchemaCatalogRegistry(caching_session)
if config.HOMEPAGE_CONFIG:
log.info("Initializing homepage sections...")
for section in config.HOMEPAGE_CONFIG['sections']:
name = section['name']
for section in config.HOMEPAGE_CONFIG["sections"]:
name = section["name"]
log.info('Initializing homepage section "{}"...'.format(name))
catalog_ref = section.get('catalog')
catalog_ref = section.get("catalog")
if catalog_ref:
schema_catalog_registry.add_ref(name, catalog_ref)
log.info("...done")
def configure_sentry(app):
"""Configure sentry.io service for application error monitoring."""
......@@ -73,6 +74,7 @@ def configure_sentry(app):
sentry_sdk.init(dsn=sentry_dsn, integrations=[FlaskIntegration()])
# Flask things
app = flask.Flask(__name__)
app.secret_key = config.SECRET_KEY
......@@ -81,7 +83,7 @@ configure_sentry(app)
# Jinja2 url_quote_plus custom filter
# https://stackoverflow.com/questions/12288454/how-to-import-custom-jinja2-filters-from-another-file-and-using-flask
blueprint = flask.Blueprint('filters', __name__)
blueprint = flask.Blueprint("filters", __name__)
@jinja2.contextfilter
......@@ -101,7 +103,9 @@ app.register_blueprint(blueprint)
@app.context_processor
def inject_version():
return {"validata_ui_version": pkg_resources.get_distribution("validata-ui").version}
return {
"validata_ui_version": pkg_resources.get_distribution("validata-ui").version
}
@app.context_processor
......
......@@ -14,13 +14,13 @@ load_dotenv()
def without_trailing_slash(url):
return url[:-1] if url.endswith('/') else url
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: {}".format(LOG_LEVEL))
logging.basicConfig(
format="%(levelname)s:%(name)s:%(message)s",
level=numeric_log_level,
......
......@@ -6,19 +6,19 @@ from flask import flash
def flash_error(msg):
""" Flash bootstrap error message """
flash(msg, 'danger')
flash(msg, "danger")
def flash_warning(msg):
""" Flash bootstrap warning message """
flash(msg, 'warning')
flash(msg, "warning")
def flash_success(msg):
""" Flash bootstrap success message """
flash(msg, 'success')
flash(msg, "success")
def flash_info(msg):
""" Flash bootstrap info message """
flash(msg, 'info')
flash(msg, "info")
......@@ -27,7 +27,7 @@ class URLValidataResource(ValidataResource):
def __init__(self, url):
"""Built from URL"""
super().__init__('url')
super().__init__("url")
self.url = url
self.filename = Path(urlparse(url).path).name
......@@ -41,7 +41,7 @@ class UploadedFileValidataResource(ValidataResource):
def __init__(self, filename, bytes_content):
"""Built from file name and content"""
super().__init__('file')
super().__init__("file")
self.filename = filename
self.content = bytes_content
......@@ -50,20 +50,21 @@ class UploadedFileValidataResource(ValidataResource):
def __detect_format_from_file_extension(self):
ext = Path(self.filename).suffix
if ext in ('.csv', '.tsv', '.ods', '.xls', '.xlsx'):
if ext in (".csv", ".tsv", ".ods", ".xls", ".xlsx"):
return ext[1:]
return None
def build_stream_args(self):
"""Uploaded file implementation"""
options = {
'scheme': 'stream',
'format': self.__detect_format_from_file_extension()
"scheme": "stream",
"format": self.__detect_format_from_file_extension(),
}
return (self.build_reader(), options)
def strip_accents(s):
"""Remove accents from string, used to sort normalized strings"""
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
return "".join(
c for c in unicodedata.normalize("NFD", s) if unicodedata.category(c) != "Mn"
)
This diff is collapsed.
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