Skip to content

Commit 8f99ff6

Browse files
PGijsbersNeeratyoyjoaquinvanschoren
authored
[WIP] Add 781 (#922)
* Add Flake8 configuration Uses the configuration from ci_scripts * Add mypy configuration file Based on the ci_scripts parameters. * Pre-commit mypy flake8, add flake8 excludes Any venv folder does not need flake8. The example directory got flake8 warnings so I assumed it should be excluded. * Add Black to pre-commit Add ignore E203 as Black will observe PEPs specification for white space around a colon it is next to an expression. * Set max line length to 100 * Blacken code There are a few places where big indentation is introduced that may warrant refactoring so it looks better. I did not refactor anything yet, but did exlude three (?) lists (of ids) to not be formatted. * Add unit tests to flake8 and mypy pre-commit * Use pre-commit for flake8, mypy and black checks This ensures it runs with the same versions and settings as developers. * Update docs, add 'test' dependencies Add two other developer dependencies not strictly required for unit tests, but required for development. I think the overlap between people who want to execute unit tests and perform commits is (close to) 100% anyway. * Uninstall pytest-cov on appveyor ci It seems to cause an error on import due to a missing sqlite3 dll. As we don't check coverage anyway, hopefully just uninstalling is sufficient. * Add -y to uninstall * Sphinx issue fix (#923) * Sphinx issue fix * Removing comment * More robust handling of openml_url (#921) I ran into issues when the openml server config is not exactly 'https://www.openml.org/api/v1/xml', e.g. I had 'https://www.openml.org/api/v1'. I only noticed when getting a bad dataset url. This edit makes the API more robust against how exactly the server URL is set in the config. * format for black artifacts * Add Flake8 configuration Uses the configuration from ci_scripts * Add mypy configuration file Based on the ci_scripts parameters. * Pre-commit mypy flake8, add flake8 excludes Any venv folder does not need flake8. The example directory got flake8 warnings so I assumed it should be excluded. * Add Black to pre-commit Add ignore E203 as Black will observe PEPs specification for white space around a colon it is next to an expression. * Set max line length to 100 * Blacken code There are a few places where big indentation is introduced that may warrant refactoring so it looks better. I did not refactor anything yet, but did exlude three (?) lists (of ids) to not be formatted. * Add unit tests to flake8 and mypy pre-commit * Use pre-commit for flake8, mypy and black checks This ensures it runs with the same versions and settings as developers. * Update docs, add 'test' dependencies Add two other developer dependencies not strictly required for unit tests, but required for development. I think the overlap between people who want to execute unit tests and perform commits is (close to) 100% anyway. * Uninstall pytest-cov on appveyor ci It seems to cause an error on import due to a missing sqlite3 dll. As we don't check coverage anyway, hopefully just uninstalling is sufficient. * Add -y to uninstall * format for black artifacts Co-authored-by: Neeratyoy Mallik <[email protected]> Co-authored-by: Joaquin Vanschoren <[email protected]>
1 parent 861600b commit 8f99ff6

File tree

93 files changed

+5751
-5428
lines changed

Some content is hidden

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

93 files changed

+5751
-5428
lines changed

.flake8

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[flake8]
2+
max-line-length = 100
3+
show-source = True
4+
select = C,E,F,W,B
5+
ignore = E203, E402, W503
6+
per-file-ignores =
7+
*__init__.py:F401
8+
exclude =
9+
venv
10+
examples

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 19.10b0
4+
hooks:
5+
- id: black
6+
args: [--line-length=100]
7+
- repo: https://github.com/pre-commit/mirrors-mypy
8+
rev: v0.761
9+
hooks:
10+
- id: mypy
11+
name: mypy openml
12+
files: openml/*
13+
- id: mypy
14+
name: mypy tests
15+
files: tests/*
16+
- repo: https://gitlab.com/pycqa/flake8
17+
rev: 3.8.3
18+
hooks:
19+
- id: flake8
20+
name: flake8 openml
21+
files: openml/*
22+
- id: flake8
23+
name: flake8 tests
24+
files: tests/*

CONTRIBUTING.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,37 @@ following rules before you submit a pull request:
109109
- If any source file is being added to the repository, please add the BSD 3-Clause license to it.
110110

111111

112-
You can also check for common programming errors with the following
113-
tools:
114-
115-
- Code with good unittest **coverage** (at least 80%), check with:
116-
112+
First install openml with its test dependencies by running
117113
```bash
118-
$ pip install pytest pytest-cov
119-
$ pytest --cov=. path/to/tests_for_package
114+
$ pip install -e .[test]
120115
```
121-
122-
- No style warnings, check with:
123-
116+
from the repository folder.
117+
This will install dependencies to run unit tests, as well as [pre-commit](https://pre-commit.com/).
118+
To run the unit tests, and check their code coverage, run:
124119
```bash
125-
$ pip install flake8
126-
$ flake8 --ignore E402,W503 --show-source --max-line-length 100
120+
$ pytest --cov=. path/to/tests_for_package
127121
```
128-
129-
- No mypy (typing) issues, check with:
130-
122+
Make sure your code has good unittest **coverage** (at least 80%).
123+
124+
Pre-commit is used for various style checking and code formatting.
125+
Before each commit, it will automatically run:
126+
- [black](https://black.readthedocs.io/en/stable/) a code formatter.
127+
This will automatically format your code.
128+
Make sure to take a second look after any formatting takes place,
129+
if the resulting code is very bloated, consider a (small) refactor.
130+
*note*: If Black reformats your code, the commit will automatically be aborted.
131+
Make sure to add the formatted files (back) to your commit after checking them.
132+
- [mypy](https://mypy.readthedocs.io/en/stable/) a static type checker.
133+
In particular, make sure each function you work on has type hints.
134+
- [flake8](https://flake8.pycqa.org/en/latest/index.html) style guide enforcement.
135+
Almost all of the black-formatted code should automatically pass this check,
136+
but make sure to make adjustments if it does fail.
137+
138+
If you want to run the pre-commit tests without doing a commit, run:
131139
```bash
132-
$ pip install mypy
133-
$ mypy openml --ignore-missing-imports --follow-imports skip
140+
$ pre-commit run --all-files
134141
```
142+
Make sure to do this at least once before your first commit to check your setup works.
135143

136144
Filing bugs
137145
-----------

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ install:
3636
- "cd C:\\projects\\openml-python"
3737
- "pip install .[examples,test]"
3838
- "pip install scikit-learn==0.21"
39+
# Uninstall coverage, as it leads to an error on appveyor
40+
- "pip uninstall -y pytest-cov"
3941

4042

4143
# Not a .NET project, we build scikit-learn in the install step instead

ci_scripts/flake8_diff.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

ci_scripts/install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ if [[ "$COVERAGE" == "true" ]]; then
5858
pip install codecov pytest-cov
5959
fi
6060
if [[ "$RUN_FLAKE8" == "true" ]]; then
61-
pip install flake8 mypy
61+
pip install pre-commit
62+
pre-commit install
6263
fi
6364

6465
# Install scikit-learn last to make sure the openml package installation works

ci_scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ run_tests() {
2828
}
2929

3030
if [[ "$RUN_FLAKE8" == "true" ]]; then
31-
source ci_scripts/flake8_diff.sh
31+
pre-commit run --all-files
3232
fi
3333

3434
if [[ "$SKIP_TESTS" != "true" ]]; then

doc/conf.py

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# documentation root, use os.path.abspath to make it absolute, like shown here.
2424
# sys.path.insert(0, os.path.abspath('.')# )
2525

26-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
27-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
26+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
27+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
2828

2929
# -- General configuration ------------------------------------------------
3030

@@ -35,38 +35,38 @@
3535
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3636
# ones.
3737
extensions = [
38-
'sphinx.ext.autodoc',
39-
'sphinx.ext.autosummary',
40-
'sphinx.ext.doctest',
41-
'sphinx.ext.coverage',
42-
'sphinx.ext.mathjax',
43-
'sphinx.ext.ifconfig',
44-
'sphinx.ext.autosectionlabel',
45-
'sphinx_gallery.gen_gallery',
46-
'numpydoc'
38+
"sphinx.ext.autodoc",
39+
"sphinx.ext.autosummary",
40+
"sphinx.ext.doctest",
41+
"sphinx.ext.coverage",
42+
"sphinx.ext.mathjax",
43+
"sphinx.ext.ifconfig",
44+
"sphinx.ext.autosectionlabel",
45+
"sphinx_gallery.gen_gallery",
46+
"numpydoc",
4747
]
4848

4949
autosummary_generate = True
5050
numpydoc_show_class_members = False
5151

52-
autodoc_default_flags = ['members', 'inherited-members']
52+
autodoc_default_flags = ["members", "inherited-members"]
5353

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

5757
# The suffix of source filenames.
58-
source_suffix = '.rst'
58+
source_suffix = ".rst"
5959

6060
# The encoding of source files.
6161
# source_encoding = 'utf-8-sig'
6262

6363
# The master toctree document.
64-
master_doc = 'index'
64+
master_doc = "index"
6565

6666
# General information about the project.
67-
project = u'OpenML'
68-
copyright = (
69-
u'2014-{}, the OpenML-Python team.'.format(time.strftime("%Y,%m,%d,%H,%M,%S").split(',')[0])
67+
project = u"OpenML"
68+
copyright = u"2014-{}, the OpenML-Python team.".format(
69+
time.strftime("%Y,%m,%d,%H,%M,%S").split(",")[0]
7070
)
7171

7272
# The version info for the project you're documenting, acts as replacement for
@@ -90,7 +90,7 @@
9090

9191
# List of patterns, relative to source directory, that match files and
9292
# directories to ignore when looking for source files.
93-
exclude_patterns = ['_build', '_templates', '_static']
93+
exclude_patterns = ["_build", "_templates", "_static"]
9494

9595
# The reST default role (used for this markup: `text`) to use for all
9696
# documents.
@@ -108,7 +108,7 @@
108108
# show_authors = False
109109

110110
# The name of the Pygments (syntax highlighting) style to use.
111-
pygments_style = 'sphinx'
111+
pygments_style = "sphinx"
112112

113113
# A list of ignored prefixes for module index sorting.
114114
# modindex_common_prefix = []
@@ -121,69 +121,57 @@
121121

122122
# The theme to use for HTML and HTML Help pages. See the documentation for
123123
# a list of builtin themes.
124-
html_theme = 'bootstrap'
124+
html_theme = "bootstrap"
125125

126126
html_theme_options = {
127127
# Navigation bar title. (Default: ``project`` value)
128-
'navbar_title': "OpenML",
129-
128+
"navbar_title": "OpenML",
130129
# Tab name for entire site. (Default: "Site")
131130
# 'navbar_site_name': "Site",
132-
133131
# A list of tuples containting pages to link to. The value should
134132
# be in the form [(name, page), ..]
135-
'navbar_links': [
136-
('Start', 'index'),
137-
('User Guide', 'usage'),
138-
('API', 'api'),
139-
('Examples', 'examples/index'),
140-
('Contributing', 'contributing'),
141-
('Changelog', 'progress'),
133+
"navbar_links": [
134+
("Start", "index"),
135+
("User Guide", "usage"),
136+
("API", "api"),
137+
("Examples", "examples/index"),
138+
("Contributing", "contributing"),
139+
("Changelog", "progress"),
142140
],
143-
144141
# Render the next and previous page links in navbar. (Default: true)
145-
'navbar_sidebarrel': False,
146-
142+
"navbar_sidebarrel": False,
147143
# Render the current pages TOC in the navbar. (Default: true)
148-
'navbar_pagenav': False,
149-
144+
"navbar_pagenav": False,
150145
# Tab name for the current pages TOC. (Default: "Page")
151-
'navbar_pagenav_name': "On this page",
152-
146+
"navbar_pagenav_name": "On this page",
153147
# Global TOC depth for "site" navbar tab. (Default: 1)
154148
# Switching to -1 shows all levels.
155-
'globaltoc_depth': 1,
156-
149+
"globaltoc_depth": 1,
157150
# Include hidden TOCs in Site navbar?
158151
#
159152
# Note: If this is "false", you cannot have mixed ``:hidden:`` and
160153
# non-hidden ``toctree`` directives in the same page, or else the build
161154
# will break.
162155
#
163156
# Values: "true" (default) or "false"
164-
'globaltoc_includehidden': "false",
165-
157+
"globaltoc_includehidden": "false",
166158
# HTML navbar class (Default: "navbar") to attach to <div> element.
167159
# For black navbar, do "navbar navbar-inverse"
168-
'navbar_class': "navbar",
169-
160+
"navbar_class": "navbar",
170161
# Fix navigation bar to top of page?
171162
# Values: "true" (default) or "false"
172-
'navbar_fixed_top': "true",
173-
163+
"navbar_fixed_top": "true",
174164
# Location of link to source.
175165
# Options are "nav" (default), "footer" or anything else to exclude.
176-
'source_link_position': "None",
177-
166+
"source_link_position": "None",
178167
# Bootswatch (http://bootswatch.com/) theme.
179168
#
180169
# Options are nothing with "" (default) or the name of a valid theme
181170
# such as "amelia" or "cosmo".
182-
'bootswatch_theme': "flatly",
183-
171+
"bootswatch_theme": "flatly",
184172
# Choose Bootstrap version.
185173
# Values: "3" (default) or "2" (in quotes)
186-
'bootstrap_version': "3",
174+
"bootstrap_version": "3",
187175
}
188176

189177
# Add any paths that contain custom themes here, relative to this directory.
@@ -224,7 +212,7 @@
224212
# html_use_smartypants = True
225213

226214
# Custom sidebar templates, maps document names to template names.
227-
html_sidebars = {'**': ['localtoc.html']}
215+
html_sidebars = {"**": ["localtoc.html"]}
228216

229217
# Additional templates that should be rendered to pages, maps page names to
230218
# template names.
@@ -257,27 +245,26 @@
257245
# html_file_suffix = None
258246

259247
# Output file base name for HTML help builder.
260-
htmlhelp_basename = 'OpenMLdoc'
248+
htmlhelp_basename = "OpenMLdoc"
261249

262250

263251
# -- Options for LaTeX output ---------------------------------------------
264252

265253
latex_elements = {
266254
# The paper size ('letterpaper' or 'a4paper').
267255
# 'papersize': 'letterpaper',
268-
269256
# The font size ('10pt', '11pt' or '12pt').
270257
# 'pointsize': '10pt',
271-
272258
# Additional stuff for the LaTeX preamble.
273259
# 'preamble': '',
274260
}
275261

276262
# Grouping the document tree into LaTeX files. List of tuples
277263
# (source start file, target name, title,
278264
# author, documentclass [howto, manual, or own class]).
279-
latex_documents = [('index', 'OpenML.tex', u'OpenML Documentation',
280-
u'Matthias Feurer', 'manual'), ]
265+
latex_documents = [
266+
("index", "OpenML.tex", u"OpenML Documentation", u"Matthias Feurer", "manual"),
267+
]
281268

282269
# The name of an image file (relative to this directory) to place at the top of
283270
# the title page.
@@ -304,10 +291,7 @@
304291

305292
# One entry per manual page. List of tuples
306293
# (source start file, name, description, authors, manual section).
307-
man_pages = [
308-
('index', 'openml', u'OpenML Documentation',
309-
[u'Matthias Feurer'], 1)
310-
]
294+
man_pages = [("index", "openml", u"OpenML Documentation", [u"Matthias Feurer"], 1)]
311295

312296
# If true, show URL addresses after external links.
313297
# man_show_urls = False
@@ -319,9 +303,15 @@
319303
# (source start file, target name, title, author,
320304
# dir menu entry, description, category)
321305
texinfo_documents = [
322-
('index', 'OpenML', u'OpenML Documentation',
323-
u'Matthias Feurer', 'OpenML', 'One line description of project.',
324-
'Miscellaneous'),
306+
(
307+
"index",
308+
"OpenML",
309+
u"OpenML Documentation",
310+
u"Matthias Feurer",
311+
"OpenML",
312+
"One line description of project.",
313+
"Miscellaneous",
314+
),
325315
]
326316

327317
# Documents to append as an appendix to all manuals.
@@ -343,13 +333,13 @@
343333
# Sphinx-gallery configuration.
344334
sphinx_gallery_conf = {
345335
# disable mini galleries clustered by the used functions
346-
'backreferences_dir': None,
336+
"backreferences_dir": None,
347337
# path to the examples
348-
'examples_dirs': '../examples',
338+
"examples_dirs": "../examples",
349339
# path where to save gallery generated examples
350-
'gallery_dirs': 'examples',
340+
"gallery_dirs": "examples",
351341
# compile execute examples in the examples dir
352-
'filename_pattern': '.*example.py$|.*tutorial.py$',
342+
"filename_pattern": ".*example.py$|.*tutorial.py$",
353343
# TODO: fix back/forward references for the examples.
354344
}
355345

0 commit comments

Comments
 (0)