Skip to content

Commit fdcbe4f

Browse files
authored
STY Apply black (#540)
1 parent fca37ea commit fdcbe4f

File tree

124 files changed

+7497
-5887
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+7497
-5887
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203

.github/workflows/main.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ jobs:
124124
python-version: '3.7'
125125

126126
- name: Install dependencies
127-
run: pip install flake8
127+
run: pip install flake8 black==21.8b0
128128

129129
- name: Run flake8
130130
run: flake8 ramp-*
131+
132+
- name: Run black
133+
run: black --check .

.pre-commit-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ repos:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 21.8b0
10+
hooks:
11+
- id: black
812
- repo: https://gitlab.com/pycqa/flake8
913
rev: 3.7.8
1014
hooks:

conftest.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
1-
import contextlib
2-
import os
31
import pytest
4-
import smtpd
52
import warnings
63
from sqlalchemy import create_engine, exc
7-
from threading import Thread
84
from ramp_utils.testing import database_config_template
95
from yaml import safe_load
106

117
from ramp_utils import read_config
128

139

14-
@pytest.fixture(scope='session')
10+
@pytest.fixture(scope="session")
1511
def database_connection():
1612
"""
1713
Create a Postgres database for the tests, and drop it when the tests are
1814
done.
1915
"""
2016
config = safe_load(open("db_engine.yml"))
21-
dbowner = config.get('db_owner')
17+
dbowner = config.get("db_owner")
2218

23-
engine = create_engine(f'postgresql://{dbowner}:@localhost/postgres',
24-
isolation_level='AUTOCOMMIT')
19+
engine = create_engine(
20+
f"postgresql://{dbowner}:@localhost/postgres",
21+
isolation_level="AUTOCOMMIT",
22+
)
2523

2624
connection = engine.connect()
2725

2826
database_config = read_config(database_config_template())
29-
username = database_config['sqlalchemy']['username']
30-
database_name = database_config['sqlalchemy']['database']
27+
username = database_config["sqlalchemy"]["username"]
28+
database_name = database_config["sqlalchemy"]["database"]
3129
try:
32-
connection.execute(f"""CREATE USER {username}
30+
connection.execute(
31+
f"""CREATE USER {username}
3332
WITH PASSWORD '{username}';
34-
ALTER USER {username} WITH SUPERUSER""")
33+
ALTER USER {username} WITH SUPERUSER"""
34+
)
3535
except exc.ProgrammingError:
36-
warnings.warn(f'user {username} already exists')
36+
warnings.warn(f"user {username} already exists")
3737

3838
try:
39-
connection.execute(f'CREATE DATABASE {database_name} OWNER {username}')
39+
connection.execute(f"CREATE DATABASE {database_name} OWNER {username}")
4040
except exc.ProgrammingError as e:
4141
raise ValueError(
42-
f'{database_name} database used for testing already exists'
42+
f"{database_name} database used for testing already exists"
4343
) from e
4444

4545
# close the connection and remove the database in the end
4646
yield
47-
connection.execute("""SELECT pg_terminate_backend(pid)
47+
connection.execute(
48+
"""SELECT pg_terminate_backend(pid)
4849
FROM pg_stat_activity
49-
WHERE datname = 'databoard_test';""")
50-
connection.execute(f'DROP DATABASE {database_name}')
51-
connection.execute(f'DROP USER {username}')
50+
WHERE datname = 'databoard_test';"""
51+
)
52+
connection.execute(f"DROP DATABASE {database_name}")
53+
connection.execute(f"DROP USER {username}")
5254
print(f"deleted database 'databoard_test' and removed user '{username}'")
5355

5456

55-
@pytest.fixture(scope='session')
57+
@pytest.fixture(scope="session")
5658
def dask_scheduler():
5759
try:
5860
from dask.distributed import LocalCluster
61+
5962
cluster = LocalCluster(n_workers=4)
6063
yield cluster.scheduler_address
6164
cluster.close()

doc/conf.py

+65-43
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15+
# flake8: noqa
16+
1517
import os
1618
import sys
1719
import sphinx_rtd_theme
1820

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

@@ -32,13 +34,13 @@
3234
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3335
# ones.
3436
extensions = [
35-
'sphinx.ext.autodoc',
36-
'sphinx.ext.autosummary',
37-
'sphinx.ext.doctest',
38-
'sphinx.ext.intersphinx',
39-
'sphinx_click.ext',
40-
'numpydoc',
41-
'sphinx_issues',
37+
"sphinx.ext.autodoc",
38+
"sphinx.ext.autosummary",
39+
"sphinx.ext.doctest",
40+
"sphinx.ext.intersphinx",
41+
"sphinx_click.ext",
42+
"numpydoc",
43+
"sphinx_issues",
4244
]
4345

4446
# this is needed for some reason...
@@ -48,21 +50,22 @@
4850
# pngmath / imgmath compatibility layer for different sphinx versions
4951
import sphinx
5052
from distutils.version import LooseVersion
51-
if LooseVersion(sphinx.__version__) < LooseVersion('1.4'):
52-
extensions.append('sphinx.ext.pngmath')
53+
54+
if LooseVersion(sphinx.__version__) < LooseVersion("1.4"):
55+
extensions.append("sphinx.ext.pngmath")
5356
else:
54-
extensions.append('sphinx.ext.imgmath')
57+
extensions.append("sphinx.ext.imgmath")
5558

56-
autodoc_default_flags = ['members', 'inherited-members']
59+
autodoc_default_flags = ["members", "inherited-members"]
5760

5861
# Add any paths that contain templates here, relative to this directory.
59-
templates_path = ['_templates']
62+
templates_path = ["_templates"]
6063

6164
# generate autosummary even if no references
6265
autosummary_generate = True
6366

6467
# The suffix of source filenames.
65-
source_suffix = '.rst'
68+
source_suffix = ".rst"
6669

6770
# The encoding of source files.
6871
# source_encoding = 'utf-8-sig'
@@ -71,18 +74,19 @@
7174
plot_gallery = True
7275

7376
# The master toctree document.
74-
master_doc = 'index'
77+
master_doc = "index"
7578

7679
# General information about the project.
77-
project = 'RAMP'
78-
copyright = '2015 - 2019, Paris-Saclay Center for Data Science'
80+
project = "RAMP"
81+
copyright = "2015 - 2019, Paris-Saclay Center for Data Science"
7982

8083
# The version info for the project you're documenting, acts as replacement for
8184
# |version| and |release|, also used in various other places throughout the
8285
# built documents.
8386
#
8487
# The short X.Y version.
8588
from ramp_database import __version__
89+
8690
version = __version__
8791
# The full version, including alpha/beta/rc tags.
8892
release = __version__
@@ -99,11 +103,11 @@
99103

100104
# List of patterns, relative to source directory, that match files and
101105
# directories to ignore when looking for source files.
102-
exclude_patterns = ['_build', '_templates']
106+
exclude_patterns = ["_build", "_templates"]
103107

104108
# The reST default role (used for this markup: `text`) to use for all
105109
# documents.
106-
default_role = 'literal'
110+
default_role = "literal"
107111

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

119123
# The name of the Pygments (syntax highlighting) style to use.
120-
pygments_style = 'sphinx'
124+
pygments_style = "sphinx"
121125

122126
# Custom style
123-
html_style = 'css/ramp.css'
127+
html_style = "css/ramp.css"
124128

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

133137
# The theme to use for HTML and HTML Help pages. See the documentation for
134138
# a list of builtin themes.
135-
html_theme = 'sphinx_rtd_theme'
139+
html_theme = "sphinx_rtd_theme"
136140

137141
# Theme options are theme-specific and customize the look and feel of a theme
138142
# further. For a list of options available for each theme, see the
@@ -161,7 +165,7 @@
161165
# Add any paths that contain custom static files (such as style sheets) here,
162166
# relative to this directory. They are copied after the builtin static files,
163167
# so a file named "default.css" will overwrite the builtin "default.css".
164-
html_static_path = ['_static']
168+
html_static_path = ["_static"]
165169

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

212216
# Output file base name for HTML help builder.
213-
htmlhelp_basename = 'ramp-learndoc'
217+
htmlhelp_basename = "ramp-learndoc"
214218

215219
# -- Options for LaTeX output ---------------------------------------------
216220

217221
latex_elements = {
218222
# The paper size ('letterpaper' or 'a4paper').
219223
# 'papersize': 'letterpaper',
220-
221224
# The font size ('10pt', '11pt' or '12pt').
222225
# 'pointsize': '10pt',
223-
224226
# Additional stuff for the LaTeX preamble.
225227
# 'preamble': '',
226228
}
@@ -229,8 +231,13 @@
229231
# (source start file, target name, title,
230232
# author, documentclass [howto, manual, or own class]).
231233
latex_documents = [
232-
('index', 'ramp.tex', 'RAMP Documentation',
233-
'Paris-Saclay Center for Data Science', 'manual'),
234+
(
235+
"index",
236+
"ramp.tex",
237+
"RAMP Documentation",
238+
"Paris-Saclay Center for Data Science",
239+
"manual",
240+
),
234241
]
235242

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

253260
# intersphinx configuration
254261
intersphinx_mapping = {
255-
'python': ('https://docs.python.org/{.major}'.format(
256-
sys.version_info), None),
257-
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
258-
'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
259-
'matplotlib': ('https://matplotlib.org/', None),
260-
'sklearn': ('http://scikit-learn.org/stable', None)
262+
"python": (
263+
"https://docs.python.org/{.major}".format(sys.version_info),
264+
None,
265+
),
266+
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
267+
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
268+
"matplotlib": ("https://matplotlib.org/", None),
269+
"sklearn": ("http://scikit-learn.org/stable", None),
261270
}
262271

263272
# -- Options for manual page output ---------------------------------------
@@ -268,8 +277,15 @@
268277

269278
# One entry per manual page. List of tuples
270279
# (source start file, name, description, authors, manual section).
271-
man_pages = [('index', 'RAMP', 'RAMP Documentation',
272-
['Paris-Saclay Center for Data Science'], 1)]
280+
man_pages = [
281+
(
282+
"index",
283+
"RAMP",
284+
"RAMP Documentation",
285+
["Paris-Saclay Center for Data Science"],
286+
1,
287+
)
288+
]
273289

274290
# If true, show URL addresses after external links.
275291
# man_show_urls = False
@@ -280,9 +296,15 @@
280296
# (source start file, target name, title, author,
281297
# dir menu entry, description, category)
282298
texinfo_documents = [
283-
('index', 'RAMP', 'RAMP Documentation',
284-
'Paris-Saclay Center for Data Science', 'RAMP',
285-
'Rapid Analytics and Model Prototyping', 'Machine Learning'),
299+
(
300+
"index",
301+
"RAMP",
302+
"RAMP Documentation",
303+
"Paris-Saclay Center for Data Science",
304+
"RAMP",
305+
"Rapid Analytics and Model Prototyping",
306+
"Machine Learning",
307+
),
286308
]
287309

288310

@@ -298,9 +320,9 @@
298320

299321
# Config for sphinx_issues
300322

301-
issues_uri = 'https://github.com/paris-saclay-cds/ramp-board/issues/{issue}'
302-
issues_github_path = 'paris-saclay-cds/ramp-board'
303-
issues_user_uri = 'https://github.com/{user}'
323+
issues_uri = "https://github.com/paris-saclay-cds/ramp-board/issues/{issue}"
324+
issues_github_path = "paris-saclay-cds/ramp-board"
325+
issues_user_uri = "https://github.com/{user}"
304326

305327

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

doc/sphinxext/generate_database_schema.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010

1111
def main():
1212
database_config = read_config(
13-
database_config_template(), filter_section='sqlalchemy'
13+
database_config_template(), filter_section="sqlalchemy"
1414
)
1515
setup_db(database_config)
1616

1717
render_er(
18-
"{}://{}:{}@{}:{}/{}"
19-
.format(
20-
database_config['drivername'], database_config['username'],
21-
database_config['password'], database_config['host'],
22-
database_config['port'], database_config['database']
18+
"{}://{}:{}@{}:{}/{}".format(
19+
database_config["drivername"],
20+
database_config["username"],
21+
database_config["password"],
22+
database_config["host"],
23+
database_config["port"],
24+
database_config["database"],
2325
),
24-
os.path.join('..', '_static', 'img', 'schema_db.png')
26+
os.path.join("..", "_static", "img", "schema_db.png"),
2527
)
2628

2729

28-
if __name__ == '__main__':
30+
if __name__ == "__main__":
2931
main()

0 commit comments

Comments
 (0)