Skip to content

Commit

Permalink
STY Apply black (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
rth authored Sep 15, 2021
1 parent fca37ea commit fdcbe4f
Show file tree
Hide file tree
Showing 124 changed files with 7,497 additions and 5,887 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ jobs:
python-version: '3.7'

- name: Install dependencies
run: pip install flake8
run: pip install flake8 black==21.8b0

- name: Run flake8
run: flake8 ramp-*

- name: Run black
run: black --check .
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 21.8b0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
hooks:
Expand Down
43 changes: 23 additions & 20 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
import contextlib
import os
import pytest
import smtpd
import warnings
from sqlalchemy import create_engine, exc
from threading import Thread
from ramp_utils.testing import database_config_template
from yaml import safe_load

from ramp_utils import read_config


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def database_connection():
"""
Create a Postgres database for the tests, and drop it when the tests are
done.
"""
config = safe_load(open("db_engine.yml"))
dbowner = config.get('db_owner')
dbowner = config.get("db_owner")

engine = create_engine(f'postgresql://{dbowner}:@localhost/postgres',
isolation_level='AUTOCOMMIT')
engine = create_engine(
f"postgresql://{dbowner}:@localhost/postgres",
isolation_level="AUTOCOMMIT",
)

connection = engine.connect()

database_config = read_config(database_config_template())
username = database_config['sqlalchemy']['username']
database_name = database_config['sqlalchemy']['database']
username = database_config["sqlalchemy"]["username"]
database_name = database_config["sqlalchemy"]["database"]
try:
connection.execute(f"""CREATE USER {username}
connection.execute(
f"""CREATE USER {username}
WITH PASSWORD '{username}';
ALTER USER {username} WITH SUPERUSER""")
ALTER USER {username} WITH SUPERUSER"""
)
except exc.ProgrammingError:
warnings.warn(f'user {username} already exists')
warnings.warn(f"user {username} already exists")

try:
connection.execute(f'CREATE DATABASE {database_name} OWNER {username}')
connection.execute(f"CREATE DATABASE {database_name} OWNER {username}")
except exc.ProgrammingError as e:
raise ValueError(
f'{database_name} database used for testing already exists'
f"{database_name} database used for testing already exists"
) from e

# close the connection and remove the database in the end
yield
connection.execute("""SELECT pg_terminate_backend(pid)
connection.execute(
"""SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'databoard_test';""")
connection.execute(f'DROP DATABASE {database_name}')
connection.execute(f'DROP USER {username}')
WHERE datname = 'databoard_test';"""
)
connection.execute(f"DROP DATABASE {database_name}")
connection.execute(f"DROP USER {username}")
print(f"deleted database 'databoard_test' and removed user '{username}'")


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def dask_scheduler():
try:
from dask.distributed import LocalCluster

cluster = LocalCluster(n_workers=4)
yield cluster.scheduler_address
cluster.close()
Expand Down
108 changes: 65 additions & 43 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

# flake8: noqa

import os
import sys
import sphinx_rtd_theme

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('sphinxext'))
sys.path.insert(0, os.path.abspath("sphinxext"))
from github_link import make_linkcode_resolve
import generate_database_schema

Expand All @@ -32,13 +34,13 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx_click.ext',
'numpydoc',
'sphinx_issues',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx_click.ext",
"numpydoc",
"sphinx_issues",
]

# this is needed for some reason...
Expand All @@ -48,21 +50,22 @@
# pngmath / imgmath compatibility layer for different sphinx versions
import sphinx
from distutils.version import LooseVersion
if LooseVersion(sphinx.__version__) < LooseVersion('1.4'):
extensions.append('sphinx.ext.pngmath')

if LooseVersion(sphinx.__version__) < LooseVersion("1.4"):
extensions.append("sphinx.ext.pngmath")
else:
extensions.append('sphinx.ext.imgmath')
extensions.append("sphinx.ext.imgmath")

autodoc_default_flags = ['members', 'inherited-members']
autodoc_default_flags = ["members", "inherited-members"]

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

# generate autosummary even if no references
autosummary_generate = True

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'
Expand All @@ -71,18 +74,19 @@
plot_gallery = True

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'RAMP'
copyright = '2015 - 2019, Paris-Saclay Center for Data Science'
project = "RAMP"
copyright = "2015 - 2019, Paris-Saclay Center for Data Science"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
from ramp_database import __version__

version = __version__
# The full version, including alpha/beta/rc tags.
release = __version__
Expand All @@ -99,11 +103,11 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build', '_templates']
exclude_patterns = ["_build", "_templates"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
default_role = 'literal'
default_role = "literal"

# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = False
Expand All @@ -117,10 +121,10 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# Custom style
html_style = 'css/ramp.css'
html_style = "css/ramp.css"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -132,7 +136,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -161,7 +165,7 @@
# 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"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -210,17 +214,15 @@
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'ramp-learndoc'
htmlhelp_basename = "ramp-learndoc"

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
Expand All @@ -229,8 +231,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'ramp.tex', 'RAMP Documentation',
'Paris-Saclay Center for Data Science', 'manual'),
(
"index",
"ramp.tex",
"RAMP Documentation",
"Paris-Saclay Center for Data Science",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -252,12 +259,14 @@

# intersphinx configuration
intersphinx_mapping = {
'python': ('https://docs.python.org/{.major}'.format(
sys.version_info), None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
'matplotlib': ('https://matplotlib.org/', None),
'sklearn': ('http://scikit-learn.org/stable', None)
"python": (
"https://docs.python.org/{.major}".format(sys.version_info),
None,
),
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
"matplotlib": ("https://matplotlib.org/", None),
"sklearn": ("http://scikit-learn.org/stable", None),
}

# -- Options for manual page output ---------------------------------------
Expand All @@ -268,8 +277,15 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [('index', 'RAMP', 'RAMP Documentation',
['Paris-Saclay Center for Data Science'], 1)]
man_pages = [
(
"index",
"RAMP",
"RAMP Documentation",
["Paris-Saclay Center for Data Science"],
1,
)
]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -280,9 +296,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'RAMP', 'RAMP Documentation',
'Paris-Saclay Center for Data Science', 'RAMP',
'Rapid Analytics and Model Prototyping', 'Machine Learning'),
(
"index",
"RAMP",
"RAMP Documentation",
"Paris-Saclay Center for Data Science",
"RAMP",
"Rapid Analytics and Model Prototyping",
"Machine Learning",
),
]


Expand All @@ -298,9 +320,9 @@

# Config for sphinx_issues

issues_uri = 'https://github.com/paris-saclay-cds/ramp-board/issues/{issue}'
issues_github_path = 'paris-saclay-cds/ramp-board'
issues_user_uri = 'https://github.com/{user}'
issues_uri = "https://github.com/paris-saclay-cds/ramp-board/issues/{issue}"
issues_github_path = "paris-saclay-cds/ramp-board"
issues_user_uri = "https://github.com/{user}"


# Temporary work-around for spacing problem between parameter and parameter
Expand All @@ -310,7 +332,7 @@
# In an ideal world, this would get fixed in this PR:
# https://github.com/readthedocs/sphinx_rtd_theme/pull/747/files
def setup(app):
app.add_javascript('js/copybutton.js')
app.add_javascript("js/copybutton.js")
app.add_stylesheet("basic.css")
# app.connect('autodoc-process-docstring', generate_example_rst)

Expand Down
18 changes: 10 additions & 8 deletions doc/sphinxext/generate_database_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@

def main():
database_config = read_config(
database_config_template(), filter_section='sqlalchemy'
database_config_template(), filter_section="sqlalchemy"
)
setup_db(database_config)

render_er(
"{}://{}:{}@{}:{}/{}"
.format(
database_config['drivername'], database_config['username'],
database_config['password'], database_config['host'],
database_config['port'], database_config['database']
"{}://{}:{}@{}:{}/{}".format(
database_config["drivername"],
database_config["username"],
database_config["password"],
database_config["host"],
database_config["port"],
database_config["database"],
),
os.path.join('..', '_static', 'img', 'schema_db.png')
os.path.join("..", "_static", "img", "schema_db.png"),
)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit fdcbe4f

Please sign in to comment.