Skip to content

Commit

Permalink
use black formatter (apply also for tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisJ committed Oct 2, 2020
1 parent 477a42f commit bb18cfd
Show file tree
Hide file tree
Showing 26 changed files with 2,187 additions and 1,048 deletions.
28 changes: 14 additions & 14 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import os
import sys

sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath("../.."))


import hadar

# -- Project information -----------------------------------------------------
master_doc = 'index'
project = 'hadar-simulator'
copyright = 'Except where otherwise noted, this content is Copyright (c) 2020, RTE (https://www.rte-france.com) and licensed under a CC-BY-4.0 (https://creativecommons.org/licenses/by/4.0/) license.'
author = 'RTE'
master_doc = "index"
project = "hadar-simulator"
copyright = "Except where otherwise noted, this content is Copyright (c) 2020, RTE (https://www.rte-france.com) and licensed under a CC-BY-4.0 (https://creativecommons.org/licenses/by/4.0/) license."
author = "RTE"

# The full version, including alpha/beta/rc tags
release = hadar.__version__
Expand All @@ -34,32 +34,32 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting',
'sphinx.ext.mathjax',
"sphinx.ext.autodoc",
"nbsphinx",
"IPython.sphinxext.ipython_console_highlighting",
"sphinx.ext.mathjax",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', '**.ipynb_checkpoints']
exclude_patterns = ["_build", "**.ipynb_checkpoints"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the reference for
# a list of builtin themes.
#
html_theme = 'pydata_sphinx_theme'
html_theme = "pydata_sphinx_theme"
html_logo = "_static/logo.png"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

nbsphinx_execute = 'never'
nbsphinx_execute = "never"
52 changes: 29 additions & 23 deletions examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from nbconvert.preprocessors import ExecutePreprocessor

exporter = RSTExporter()
ep = ExecutePreprocessor(timeout=600, kernel_name='python3', store_widget_state=True)
ep = ExecutePreprocessor(timeout=600, kernel_name="python3", store_widget_state=True)


def open_nb(name: str, src: str) -> nbformat:
Expand All @@ -26,9 +26,11 @@ def open_nb(name: str, src: str) -> nbformat:
:param src: source directory
:return: notebook object
"""
print('Reading...', end=' ')
nb = nbformat.read('{src}/{name}/{name}.ipynb'.format(name=name, src=src), as_version=4)
print('OK', end=' ')
print("Reading...", end=" ")
nb = nbformat.read(
"{src}/{name}/{name}.ipynb".format(name=name, src=src), as_version=4
)
print("OK", end=" ")
return nb


Expand All @@ -41,9 +43,9 @@ def execute(nb: nbformat, name: str, src: str) -> nbformat:
:param src: notebook source directory (for setup context)
:return: notebook object with computed and stored output widget state
"""
print('Executing...', end=' ')
ep.preprocess(nb, {'metadata': {'path': '%s/%s/' % (src, name)}})
print('OK', end=' ')
print("Executing...", end=" ")
ep.preprocess(nb, {"metadata": {"path": "%s/%s/" % (src, name)}})
print("OK", end=" ")
return nb


Expand All @@ -56,11 +58,11 @@ def copy_image(name: str, export: str, src: str):
:param src: source directory
:return: None
"""
src = '%s/%s' % (src, name)
dest = '%s/%s' % (export, name)
images = [f for f in os.listdir(src) if f.split('.')[-1] in ['png']]
src = "%s/%s" % (src, name)
dest = "%s/%s" % (export, name)
images = [f for f in os.listdir(src) if f.split(".")[-1] in ["png"]]
for img in images:
os.rename('%s/%s' % (src, img), '%s/%s' % (dest, img))
os.rename("%s/%s" % (src, img), "%s/%s" % (dest, img))


def to_export(nb: nbformat, name: str, export: str):
Expand All @@ -72,17 +74,17 @@ def to_export(nb: nbformat, name: str, export: str):
:param export: directory to export
:return: None
"""
print('Exporting...', end=' ')
print("Exporting...", end=" ")
rst, _ = exporter.from_notebook_node(nb)

path = '%s/%s' % (export, name)
path = "%s/%s" % (export, name)
if not os.path.exists(path):
os.makedirs(path)

with open('%s/%s.rst' % (path, name), 'w') as f:
with open("%s/%s.rst" % (path, name), "w") as f:
f.write(rst)

print('OK', end=' ')
print("OK", end=" ")


def list_notebook(src: str) -> List[str]:
Expand All @@ -92,25 +94,29 @@ def list_notebook(src: str) -> List[str]:
:return:
"""
dirs = os.listdir(src)
return [d for d in dirs if os.path.isfile('{src}/{name}/{name}.ipynb'.format(name=d, src=src))]
return [
d
for d in dirs
if os.path.isfile("{src}/{name}/{name}.ipynb".format(name=d, src=src))
]


@click.command('Check and export notebooks')
@click.option('--src', nargs=1, help='Notebook directory')
@click.option('--check', nargs=1, help='check notebook according to result file given')
@click.option('--export', nargs=1, help='export notebooks to directory given')
@click.command("Check and export notebooks")
@click.option("--src", nargs=1, help="Notebook directory")
@click.option("--check", nargs=1, help="check notebook according to result file given")
@click.option("--export", nargs=1, help="export notebooks to directory given")
def main(src: str, check: str, export: str):
for name in list_notebook(src):
print('{:30}'.format(name), ':', end='')
print("{:30}".format(name), ":", end="")
nb = open_nb(name, src)
nb = execute(nb, name, src)
if check:
pass # Implement check
if export:
to_export(nb, name, export)
copy_image(name, export, src)
print('')
print("")


if __name__ == '__main__':
if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
with open("README.md", "r") as fh:
long_description = fh.read()

with open('requirements.txt', 'r') as f:
dependencies = f.read().split('\n')
with open("requirements.txt", "r") as f:
dependencies = f.read().split("\n")

setuptools.setup(
name="hadar",
Expand All @@ -23,5 +23,5 @@
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
python_requires=">=3.6",
)
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
# If a copy of the Apache License, version 2.0 was not distributed with this file, you can obtain one at http://www.apache.org/licenses/LICENSE-2.0.
# SPDX-License-Identifier: Apache-2.0
# This file is part of hadar-simulator, a python adequacy library for everyone.

1 change: 0 additions & 1 deletion tests/analyzer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
# If a copy of the Apache License, version 2.0 was not distributed with this file, you can obtain one at http://www.apache.org/licenses/LICENSE-2.0.
# SPDX-License-Identifier: Apache-2.0
# This file is part of hadar-simulator, a python adequacy library for everyone.

Loading

0 comments on commit bb18cfd

Please sign in to comment.