Skip to content

Commit b1148db

Browse files
akash-sureshchkoarglemaitre
authored
MNT blackify source code and add pre-commit (#722)
Co-authored-by: chkoar <[email protected]> Co-authored-by: Guillaume Lemaitre <[email protected]>
1 parent 1086fb6 commit b1148db

File tree

91 files changed

+1658
-1870
lines changed

Some content is hidden

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

91 files changed

+1658
-1870
lines changed

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/python/black
3+
rev: stable
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v2.3.0
8+
hooks:
9+
- id: check-yaml
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
- repo: https://gitlab.com/pycqa/flake8
13+
rev: 3.7.8
14+
hooks:
15+
- id: flake8
16+
types: [file, python]
17+
# only check for unused imports for now, as long as
18+
# the code is not fully PEP8 compatible
19+
args: [--select=F401]

build_tools/circle/linting.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ check_files() {
130130
if [ -n "$files" ]; then
131131
# Conservative approach: diff without context (--unified=0) so that code
132132
# that was not changed does not create failures
133-
git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --show-source $options
133+
git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --max-line-length=88 --show-source $options
134134
fi
135135
}
136136

conftest.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
import numpy as np
1313

1414
try:
15-
np.set_printoptions(legacy='1.13')
15+
np.set_printoptions(legacy="1.13")
1616
except TypeError:
1717
pass
1818

1919

2020
def pytest_runtest_setup(item):
2121
fname = item.fspath.strpath
22-
if (fname.endswith(os.path.join('keras', '_generator.py')) or
23-
fname.endswith('miscellaneous.rst')):
22+
if fname.endswith(os.path.join("keras", "_generator.py")) or fname.endswith(
23+
"miscellaneous.rst"
24+
):
2425
try:
2526
import keras
2627
except ImportError:
27-
pytest.skip('The keras package is not installed.')
28-
elif (fname.endswith(os.path.join('tensorflow', '_generator.py')) or
29-
fname.endswith('miscellaneous.rst')):
28+
pytest.skip("The keras package is not installed.")
29+
elif fname.endswith(os.path.join("tensorflow", "_generator.py")) or fname.endswith(
30+
"miscellaneous.rst"
31+
):
3032
try:
3133
import tensorflow
3234
except ImportError:
33-
pytest.skip('The tensorflow package is not installed.')
35+
pytest.skip("The tensorflow package is not installed.")

doc/conf.py

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# If extensions (or modules to document with autodoc) are in another directory,
2020
# add these directories to sys.path here. If the directory is relative to the
2121
# documentation root, use os.path.abspath to make it absolute, like shown here.
22-
sys.path.insert(0, os.path.abspath('sphinxext'))
22+
sys.path.insert(0, os.path.abspath("sphinxext"))
2323
from github_link import make_linkcode_resolve
2424
import sphinx_gallery
2525

@@ -32,15 +32,15 @@
3232
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3333
# ones.
3434
extensions = [
35-
'sphinx.ext.autodoc',
36-
'sphinx.ext.autosummary',
37-
'sphinx.ext.doctest',
38-
'sphinx.ext.intersphinx',
39-
'sphinx.ext.linkcode',
40-
'sphinxcontrib.bibtex',
41-
'numpydoc',
42-
'sphinx_issues',
43-
'sphinx_gallery.gen_gallery',
35+
"sphinx.ext.autodoc",
36+
"sphinx.ext.autosummary",
37+
"sphinx.ext.doctest",
38+
"sphinx.ext.intersphinx",
39+
"sphinx.ext.linkcode",
40+
"sphinxcontrib.bibtex",
41+
"numpydoc",
42+
"sphinx_issues",
43+
"sphinx_gallery.gen_gallery",
4444
]
4545

4646
# bibtex file
@@ -50,22 +50,22 @@
5050
# see https://github.com/numpy/numpydoc/issues/69
5151
numpydoc_show_class_members = False
5252

53-
extensions.append('sphinx.ext.imgmath')
54-
imgmath_image_format = 'svg'
53+
extensions.append("sphinx.ext.imgmath")
54+
imgmath_image_format = "svg"
5555

5656
autodoc_default_options = {
5757
"members": True,
5858
"inherited-members": True,
5959
}
6060

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

6464
# generate autosummary even if no references
6565
autosummary_generate = True
6666

6767
# The suffix of source filenames.
68-
source_suffix = '.rst'
68+
source_suffix = ".rst"
6969

7070
# The encoding of source files.
7171
# source_encoding = 'utf-8-sig'
@@ -74,7 +74,7 @@
7474
plot_gallery = True
7575

7676
# The master toctree document.
77-
master_doc = 'index'
77+
master_doc = "index"
7878

7979
# General information about the project.
8080
project = 'imbalanced-learn'
@@ -86,6 +86,7 @@
8686
#
8787
# The short X.Y version.
8888
from imblearn import __version__
89+
8990
version = __version__
9091
# The full version, including alpha/beta/rc tags.
9192
release = __version__
@@ -102,11 +103,11 @@
102103

103104
# List of patterns, relative to source directory, that match files and
104105
# directories to ignore when looking for source files.
105-
exclude_patterns = ['_build', '_templates']
106+
exclude_patterns = ["_build", "_templates"]
106107

107108
# The reST default role (used for this markup: `text`) to use for all
108109
# documents.
109-
default_role = 'literal'
110+
default_role = "literal"
110111

111112

112113
# If true, '()' will be appended to :func: etc. cross-reference text.
@@ -121,10 +122,10 @@
121122
# show_authors = False
122123

123124
# The name of the Pygments (syntax highlighting) style to use.
124-
pygments_style = 'sphinx'
125+
pygments_style = "sphinx"
125126

126127
# Custom style
127-
html_style = 'css/imbalanced-learn.css'
128+
html_style = "css/imbalanced-learn.css"
128129

129130
# A list of ignored prefixes for module index sorting.
130131
# modindex_common_prefix = []
@@ -136,7 +137,7 @@
136137

137138
# The theme to use for HTML and HTML Help pages. See the documentation for
138139
# a list of builtin themes.
139-
html_theme = 'sphinx_rtd_theme'
140+
html_theme = "sphinx_rtd_theme"
140141

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

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

216217
# Output file base name for HTML help builder.
217-
htmlhelp_basename = 'imbalanced-learndoc'
218+
htmlhelp_basename = "imbalanced-learndoc"
218219

219220
# -- Options for LaTeX output ---------------------------------------------
220221

221222
latex_elements = {
222223
# The paper size ('letterpaper' or 'a4paper').
223224
# 'papersize': 'letterpaper',
224-
225225
# The font size ('10pt', '11pt' or '12pt').
226226
# 'pointsize': '10pt',
227-
228227
# Additional stuff for the LaTeX preamble.
229228
# 'preamble': '',
230229
}
@@ -233,8 +232,13 @@
233232
# (source start file, target name, title,
234233
# author, documentclass [howto, manual, or own class]).
235234
latex_documents = [
236-
('index', 'imbalanced-learn.tex', 'imbalanced-learn Documentation',
237-
'G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas', 'manual'),
235+
(
236+
"index",
237+
"imbalanced-learn.tex",
238+
"imbalanced-learn Documentation",
239+
"G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas",
240+
"manual",
241+
),
238242
]
239243

240244
# The name of an image file (relative to this directory) to place at the top of
@@ -256,21 +260,19 @@
256260

257261
# intersphinx configuration
258262
intersphinx_mapping = {
259-
'python': ('https://docs.python.org/{.major}'.format(
260-
sys.version_info), None),
261-
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
262-
'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
263-
'matplotlib': ('https://matplotlib.org/', None),
264-
'sklearn': ('http://scikit-learn.org/stable', None)
263+
"python": ("https://docs.python.org/{.major}".format(sys.version_info), None,),
264+
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
265+
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
266+
"matplotlib": ("https://matplotlib.org/", None),
267+
"sklearn": ("http://scikit-learn.org/stable", None),
265268
}
266269

267270
# sphinx-gallery configuration
268271
sphinx_gallery_conf = {
269-
'doc_module': 'imblearn',
270-
'backreferences_dir': os.path.join('generated'),
271-
'show_memory': True,
272-
'reference_url': {
273-
'imblearn': None}
272+
"doc_module": "imblearn",
273+
"backreferences_dir": os.path.join("generated"),
274+
"show_memory": True,
275+
"reference_url": {"imblearn": None},
274276
}
275277

276278
# -- Options for manual page output ---------------------------------------
@@ -281,8 +283,15 @@
281283

282284
# One entry per manual page. List of tuples
283285
# (source start file, name, description, authors, manual section).
284-
man_pages = [('index', 'imbalanced-learn', 'imbalanced-learn Documentation',
285-
['G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas'], 1)]
286+
man_pages = [
287+
(
288+
"index",
289+
"imbalanced-learn",
290+
"imbalanced-learn Documentation",
291+
["G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas"],
292+
1,
293+
)
294+
]
286295

287296
# If true, show URL addresses after external links.
288297
# man_show_urls = False
@@ -293,9 +302,15 @@
293302
# (source start file, target name, title, author,
294303
# dir menu entry, description, category)
295304
texinfo_documents = [
296-
('index', 'imbalanced-learn', 'imbalanced-learn Documentation',
297-
'G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas', 'imbalanced-learn',
298-
'Toolbox for imbalanced dataset in machine learning.', 'Miscellaneous'),
305+
(
306+
"index",
307+
"imbalanced-learn",
308+
"imbalanced-learn Documentation",
309+
"G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas",
310+
"imbalanced-learn",
311+
"Toolbox for imbalanced dataset in machine learning.",
312+
"Miscellaneous",
313+
),
299314
]
300315

301316

@@ -311,9 +326,9 @@
311326

312327
# Config for sphinx_issues
313328

314-
issues_uri = 'https://github.com/scikit-learn-contrib/imbalanced-learn/issues/{issue}'
315-
issues_github_path = 'scikit-learn-contrib/imbalanced-learn'
316-
issues_user_uri = 'https://github.com/{user}'
329+
issues_uri = "https://github.com/scikit-learn-contrib/imbalanced-learn/issues/{issue}"
330+
issues_github_path = "scikit-learn-contrib/imbalanced-learn"
331+
issues_user_uri = "https://github.com/{user}"
317332

318333
# Hack to get kwargs to appear in docstring #18434
319334
# TODO: Remove when https://github.com/sphinx-doc/sphinx/pull/8234 gets
@@ -366,7 +381,9 @@ def setup(app):
366381
# texinfo_no_detailmenu = False
367382

368383
# The following is used by sphinx.ext.linkcode to provide links to github
369-
linkcode_resolve = make_linkcode_resolve('imblearn',
370-
'https://github.com/scikit-learn-contrib/'
371-
'imbalanced-learn/blob/{revision}/'
372-
'{package}/{path}#L{lineno}')
384+
linkcode_resolve = make_linkcode_resolve(
385+
"imblearn",
386+
"https://github.com/scikit-learn-contrib/"
387+
"imbalanced-learn/blob/{revision}/"
388+
"{package}/{path}#L{lineno}",
389+
)

doc/install.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ The imbalanced-learn package requires the following dependencies:
1717
Install
1818
=======
1919

20+
From PyPi or conda-forge repositories
21+
.....................................
22+
2023
imbalanced-learn is currently available on the PyPi's repositories and you can
2124
install it via `pip`::
2225

@@ -26,16 +29,25 @@ The package is release also in Anaconda Cloud platform::
2629

2730
conda install -c conda-forge imbalanced-learn
2831

32+
From source available on GitHub
33+
...............................
34+
2935
If you prefer, you can clone it and run the setup.py file. Use the following
3036
commands to get a copy from Github and install all dependencies::
3137

3238
git clone https://github.com/scikit-learn-contrib/imbalanced-learn.git
3339
cd imbalanced-learn
3440
pip install .
3541

36-
Or install using pip and GitHub::
42+
Be aware that you can install in developer mode with::
43+
44+
pip install --no-build-isolation --editable .
45+
46+
If you wish to make pull-requests on GitHub, we advise you to install
47+
pre-commit::
3748

38-
pip install -U git+https://github.com/scikit-learn-contrib/imbalanced-learn.git
49+
pip install pre-commit
50+
pre-commit install
3951

4052
Test and coverage
4153
=================

doc/miscellaneous.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ data and minimizing the loss previously defined::
121121
... # For each epoch, run accuracy on train and test
122122
... feed_dict = dict()
123123
... predicts_train = sess.run(predict, feed_dict={data: X})
124-
... print("epoch: {} train accuracy: {:.3f}"
125-
... .format(e, accuracy(y, predicts_train)))
124+
... print(f"epoch: {e} train accuracy: {accuracy(y, predicts_train):.3f}")
126125
... # doctest: +ELLIPSIS
127126
Starting training
128127
[...
@@ -169,4 +168,4 @@ will be passed to ``fit_generator``::
169168

170169
.. topic:: References
171170

172-
* :ref:`sphx_glr_auto_examples_applications_porto_seguro_keras_under_sampling.py`
171+
* :ref:`sphx_glr_auto_examples_applications_porto_seguro_keras_under_sampling.py`

0 commit comments

Comments
 (0)