From 5eebead7d56fe623aae569a2a31efda2dfc1aac1 Mon Sep 17 00:00:00 2001 From: Tomas Coufal Date: Fri, 25 Sep 2020 10:40:26 +0200 Subject: [PATCH] Make precommit happy with our Python --- .jupyter/jupyter_nbconvert_config.py | 20 ++- LICENSE | 1 - docs/conf.py | 61 ++++--- docs/make.bat | 228 +++++++++++++-------------- setup.py | 2 + src/__init__.py | 1 + src/data/__init__.py | 1 + src/data/make_dataset.py | 18 ++- src/features/__init__.py | 1 + src/features/build_features.py | 1 + src/models/__init__.py | 1 + src/models/predict_model.py | 1 + src/models/train_model.py | 1 + src/visualization/__init__.py | 1 + src/visualization/visualize.py | 1 + test_environment.py | 9 +- 16 files changed, 189 insertions(+), 159 deletions(-) diff --git a/.jupyter/jupyter_nbconvert_config.py b/.jupyter/jupyter_nbconvert_config.py index 8ccc321d..9e95e237 100644 --- a/.jupyter/jupyter_nbconvert_config.py +++ b/.jupyter/jupyter_nbconvert_config.py @@ -1,3 +1,8 @@ +# type: ignore +# flake8: noqa + +"""Configuration file for Jupyter NB Convert.""" + ## Set the log level by value or name. c.Application.log_level = "DEBUG" @@ -7,17 +12,17 @@ ## The Logging format template # Let's at least try for an logstash format c.Application.log_format = ( - '{' + "{" '"@timestamp": "%(asctime)s", ' '"@version": 1, ' '"level": "%(levelname)s", ' '"name": "%(name)s", ' '"message": "%(message)s"' - '}' + "}" ) ## Writer class used to write the results of the conversion -c.NbConvertApp.writer_class = 'FilesWriter' +c.NbConvertApp.writer_class = "FilesWriter" ## The time to wait (in seconds) for output from executions. If a cell execution # takes longer, an exception (TimeoutError on python 3+, RuntimeError on python @@ -42,15 +47,16 @@ ## Automation specific settings import os -if os.getenv('RUN_IN_AUTOMATION'): + +if os.getenv("RUN_IN_AUTOMATION"): from pathlib import Path ## Directory to write output(s) to. Defaults to output to the directory of each # notebook. To recover previous default behaviour (outputting to the current # working directory) use . as the flag value. - base_dir = Path(os.getenv('LOCAL_DATA_PATH')) - notebook_dir = Path(os.getenv('NOTEBOOK_NAME')).parent - c.FilesWriter.build_directory = str(base_dir / 'notebooks' / notebook_dir) + base_dir = Path(os.getenv("LOCAL_DATA_PATH")) + notebook_dir = Path(os.getenv("NOTEBOOK_NAME")).parent + c.FilesWriter.build_directory = str(base_dir / "notebooks" / notebook_dir) ## Whether to apply a suffix prior to the extension (only relevant when # converting to notebook format). The suffix is determined by the exporter, and diff --git a/LICENSE b/LICENSE index 8b137891..e69de29b 100644 --- a/LICENSE +++ b/LICENSE @@ -1 +0,0 @@ - diff --git a/docs/conf.py b/docs/conf.py index b864a155..4b14c924 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,3 +1,5 @@ +"""Documentation builder configuration.""" + # -*- coding: utf-8 -*- # # project-template documentation build configuration file, created by @@ -11,9 +13,6 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import os -import sys - # 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. @@ -29,28 +28,28 @@ extensions = [] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'project-template' +project = u"project-template" # 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. -version = '0.1' +version = "0.1" # The full version, including alpha/beta/rc tags. -release = '0.1' +release = "0.1" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -64,7 +63,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all documents. # default_role = None @@ -81,7 +80,7 @@ # show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] @@ -91,7 +90,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # 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 @@ -120,7 +119,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"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. @@ -164,7 +163,7 @@ # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'project-templatedoc' +htmlhelp_basename = "project-templatedoc" # -- Options for LaTeX output -------------------------------------------------- @@ -172,10 +171,8 @@ 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': '', } @@ -183,10 +180,13 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', - 'project-template.tex', - u'project-template Documentation', - u"aicoe-aiops", 'manual'), + ( + "index", + "project-template.tex", + u"project-template Documentation", + u"aicoe-aiops", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of @@ -215,8 +215,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'project-template', u'project-template Documentation', - [u"aicoe-aiops"], 1) + ( + "index", + "project-template", + u"project-template Documentation", + [u"aicoe-aiops"], + 1, + ) ] # If true, show URL addresses after external links. @@ -229,9 +234,15 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'project-template', u'project-template Documentation', - u"aicoe-aiops", 'project-template', - 'template for the team to use', 'Miscellaneous'), + ( + "index", + "project-template", + u"project-template Documentation", + u"aicoe-aiops", + "project-template", + "template for the team to use", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. diff --git a/docs/make.bat b/docs/make.bat index f8aa5dc7..2f466854 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -3,188 +3,188 @@ REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build + set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( - set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% - set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( - :help - echo.Please use `make ^` where ^ is one of - echo. html to make standalone HTML files - echo. dirhtml to make HTML files named index.html in directories - echo. singlehtml to make a single large HTML file - echo. pickle to make pickle files - echo. json to make JSON files - echo. htmlhelp to make HTML files and a HTML help project - echo. qthelp to make HTML files and a qthelp project - echo. devhelp to make HTML files and a Devhelp project - echo. epub to make an epub - echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter - echo. text to make text files - echo. man to make manual pages - echo. texinfo to make Texinfo files - echo. gettext to make PO message catalogs - echo. changes to make an overview over all changed/added/deprecated items - echo. linkcheck to check all external links for integrity - echo. doctest to run all doctests embedded in the documentation if enabled - goto end + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end ) if "%1" == "clean" ( - for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i - del /q /s %BUILDDIR%\* - goto end + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end ) if "%1" == "html" ( - %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/html. - goto end + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end ) if "%1" == "dirhtml" ( - %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. - goto end + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end ) if "%1" == "singlehtml" ( - %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. - goto end + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end ) if "%1" == "pickle" ( - %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the pickle files. - goto end + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end ) if "%1" == "json" ( - %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the JSON files. - goto end + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end ) if "%1" == "htmlhelp" ( - %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run HTML Help Workshop with the ^ + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. - goto end + goto end ) if "%1" == "qthelp" ( - %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run "qcollectiongenerator" with the ^ + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: - echo.^> qcollectiongenerator %BUILDDIR%\qthelp\project-template.qhcp - echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\project-template.ghc - goto end + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\project-template.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\project-template.ghc + goto end ) if "%1" == "devhelp" ( - %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. - goto end + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end ) if "%1" == "epub" ( - %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The epub file is in %BUILDDIR%/epub. - goto end + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end ) if "%1" == "latex" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. - goto end + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end ) if "%1" == "text" ( - %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The text files are in %BUILDDIR%/text. - goto end + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end ) if "%1" == "man" ( - %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The manual pages are in %BUILDDIR%/man. - goto end + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end ) if "%1" == "texinfo" ( - %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. - goto end + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end ) if "%1" == "gettext" ( - %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The message catalogs are in %BUILDDIR%/locale. - goto end + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end ) if "%1" == "changes" ( - %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes - if errorlevel 1 exit /b 1 - echo. - echo.The overview file is in %BUILDDIR%/changes. - goto end + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end ) if "%1" == "linkcheck" ( - %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck - if errorlevel 1 exit /b 1 - echo. - echo.Link check complete; look for any errors in the above output ^ + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. - goto end + goto end ) if "%1" == "doctest" ( - %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest - if errorlevel 1 exit /b 1 - echo. - echo.Testing of doctests in the sources finished, look at the ^ + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. - goto end + goto end ) :end diff --git a/setup.py b/setup.py index b8c305b2..f7e3ec7b 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +"""Package manifest for this template repo.""" + from setuptools import find_packages, setup setup( diff --git a/src/__init__.py b/src/__init__.py index e69de29b..408f7ee5 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -0,0 +1 @@ +"""Analytics compiled into python code.""" diff --git a/src/data/__init__.py b/src/data/__init__.py index e69de29b..db5d274d 100644 --- a/src/data/__init__.py +++ b/src/data/__init__.py @@ -0,0 +1 @@ +"""Data collection module.""" diff --git a/src/data/make_dataset.py b/src/data/make_dataset.py index 96b377a2..60ed23be 100644 --- a/src/data/make_dataset.py +++ b/src/data/make_dataset.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +"""Data collection code.""" import click import logging from pathlib import Path @@ -6,18 +6,20 @@ @click.command() -@click.argument('input_filepath', type=click.Path(exists=True)) -@click.argument('output_filepath', type=click.Path()) +@click.argument("input_filepath", type=click.Path(exists=True)) +@click.argument("output_filepath", type=click.Path()) def main(input_filepath, output_filepath): - """ Runs data processing scripts to turn raw data from (../raw) into - cleaned data ready to be analyzed (saved in ../processed). + """Run data processing scripts to turn raw data to cleaned data. + + Transforms raw data from (../raw) into cleaned data ready to be analyzed + (saved in ../processed). """ logger = logging.getLogger(__name__) - logger.info('making final data set from raw data') + logger.info("making final data set from raw data") -if __name__ == '__main__': - log_fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' +if __name__ == "__main__": + log_fmt = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" logging.basicConfig(level=logging.INFO, format=log_fmt) # not used in this stub but often useful for finding various files diff --git a/src/features/__init__.py b/src/features/__init__.py index e69de29b..0482c9bf 100644 --- a/src/features/__init__.py +++ b/src/features/__init__.py @@ -0,0 +1 @@ +"""Feature extraction module.""" diff --git a/src/features/build_features.py b/src/features/build_features.py index e69de29b..9adb1629 100644 --- a/src/features/build_features.py +++ b/src/features/build_features.py @@ -0,0 +1 @@ +"""Feature extraction code.""" diff --git a/src/models/__init__.py b/src/models/__init__.py index e69de29b..cbd01c12 100644 --- a/src/models/__init__.py +++ b/src/models/__init__.py @@ -0,0 +1 @@ +"""Module for models.""" diff --git a/src/models/predict_model.py b/src/models/predict_model.py index e69de29b..d42b0c8d 100644 --- a/src/models/predict_model.py +++ b/src/models/predict_model.py @@ -0,0 +1 @@ +"""Here goes the prediction code.""" diff --git a/src/models/train_model.py b/src/models/train_model.py index e69de29b..75dae17e 100644 --- a/src/models/train_model.py +++ b/src/models/train_model.py @@ -0,0 +1 @@ +"""Here goes the training code.""" diff --git a/src/visualization/__init__.py b/src/visualization/__init__.py index e69de29b..66e87d39 100644 --- a/src/visualization/__init__.py +++ b/src/visualization/__init__.py @@ -0,0 +1 @@ +"""Visualizations module.""" diff --git a/src/visualization/visualize.py b/src/visualization/visualize.py index e69de29b..67bb6105 100644 --- a/src/visualization/visualize.py +++ b/src/visualization/visualize.py @@ -0,0 +1 @@ +"""Visualizations code.""" diff --git a/test_environment.py b/test_environment.py index d0ac4a72..53818506 100644 --- a/test_environment.py +++ b/test_environment.py @@ -10,16 +10,17 @@ def main(): elif REQUIRED_PYTHON == "python3": required_major = 3 else: - raise ValueError("Unrecognized python interpreter: {}".format( - REQUIRED_PYTHON)) + raise ValueError("Unrecognized python interpreter: {}".format(REQUIRED_PYTHON)) if system_major != required_major: raise TypeError( "This project requires Python {}. Found: Python {}".format( - required_major, sys.version)) + required_major, sys.version + ) + ) else: print(">>> Development environment passes all tests!") -if __name__ == '__main__': +if __name__ == "__main__": main()