From ad5ba9b6615f888122ee6c004a63a5a4b9b0bb77 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 17 Feb 2023 18:09:09 +0100 Subject: [PATCH] CI: Use flake8 --- .github/workflows/build.yml | 8 +- doc/conf.py | 224 +++++++++++++++++++----------------- doc/examples/plot_basic.py | 1 - ottemplate/__init__.py | 6 +- ottemplate/ottemplate.py | 9 +- test/test_class.py | 4 +- 6 files changed, 129 insertions(+), 123 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a037c71..53c3b91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,15 +4,15 @@ jobs: conda-linux: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: conda-incubator/setup-miniconda@v2 with: miniforge-version: latest - name: Build shell: bash -l {0} run: | - conda install -y openturns numpy pytest numpydoc sphinx sphinx-gallery pandoc - conda install -c conda-forge sphinx_rtd_theme + conda install -y openturns numpy pytest numpydoc sphinx sphinx-gallery sphinx_rtd_theme pandoc flake8 + flake8 --max-line-length=120 python setup.py install pytest sudo apt install -y texlive-latex-recommended texlive-fonts-recommended texlive-latex-extra @@ -30,4 +30,4 @@ jobs: git add -A . if test `git diff HEAD | wc -c` -eq 0; then exit 0; fi git commit -a -m "GitHub Actions build ${GITHUB_REPOSITORY} ${GITHUB_RUN_ID}" - git push --quiet origin main > /dev/null 2>&1 \ No newline at end of file + git push --quiet origin main > /dev/null 2>&1 diff --git a/doc/conf.py b/doc/conf.py index 8e935c3..b9731d2 100755 --- a/doc/conf.py +++ b/doc/conf.py @@ -11,75 +11,69 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os -from distutils.version import LooseVersion -import sphinx -import sphinx_gallery +import os +import sys import subprocess # 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('../')) +sys.path.insert(0, os.path.abspath("../")) # -- General configuration ------------------------------------------------ extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.todo', - 'sphinx.ext.intersphinx', - 'sphinx.ext.autosummary', - 'sphinx.ext.coverage', - 'numpydoc', - 'sphinx_gallery.gen_gallery' + "sphinx.ext.autodoc", + "sphinx.ext.todo", + "sphinx.ext.intersphinx", + "sphinx.ext.autosummary", + "sphinx.ext.coverage", + "numpydoc", + "sphinx_gallery.gen_gallery", ] sphinx_gallery_conf = { - 'examples_dirs': ['examples'], # path to + "examples_dirs": ["examples"], # path to # example scripts - 'gallery_dirs': ['auto_example'], - 'filename_pattern': '/plot_', - 'run_stale_examples': True, - 'show_signature': False, + "gallery_dirs": ["auto_example"], + "filename_pattern": "/plot_", + "run_stale_examples": True, + "show_signature": False, # directory where function/class granular galleries are stored - 'backreferences_dir' : 'gen_modules/backreferences', - + "backreferences_dir": "gen_modules/backreferences", # Modules for which function/class level galleries are created. - 'doc_module' : ('openturns'), - + "doc_module": ("openturns"), # objects to exclude from implicit backreferences. The default option # is an empty set, i.e. exclude nothing. - 'exclude_implicit_doc': {}, + "exclude_implicit_doc": {}, +} + +autodoc_default_options = { + "members": None, + "inherited-members": None, + "exclude-members": "thisown", } -if LooseVersion(sphinx.__version__) >= LooseVersion('1.8'): - autodoc_default_options = {'members': None, 'inherited-members': None, 'exclude-members': 'thisown'} -else: - autodoc_default_flags = ['members', 'inherited-members'] - -try: - import sphinx.ext.imgmath - extensions.append('sphinx.ext.imgmath') - imgmath_latex_preamble = r'\usepackage{{{0}math_notations}}'.format( - os.path.dirname(__file__) + os.sep) - imgmath_use_preview = True - if subprocess.call('dvisvgm -V', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0: - imgmath_image_format = 'svg' - # embed image files inside html - imgmath_embed = True -except ImportError: - extensions.append('sphinx.ext.pngmath') - pngmath_latex_preamble = r'\usepackage{{{0}math_notations}}'.format( - os.path.dirname(__file__) + os.sep) - # The next option is used for smart-alignment of math images on the text. - # It only works when the preview-latex package is installed. - # See http://sphinx-doc.org/latest/ext/math.html#confval-pngmath_use_preview - pngmath_use_preview = True - -extensions.append('matplotlib.sphinxext.plot_directive') - -intersphinx_mapping = {'python': ( - 'http://openturns.github.io/openturns/1.18', 'openturns-objects.inv')} +extensions.append("sphinx.ext.imgmath") +imgmath_latex_preamble = r"\usepackage{{{0}math_notations}}".format( + os.path.dirname(__file__) + os.sep +) +imgmath_use_preview = True +if ( + subprocess.call( + "dvisvgm -V", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + == 0 +): + imgmath_image_format = "svg" +# embed image files inside html +imgmath_embed = True + +extensions.append("matplotlib.sphinxext.plot_directive") + +intersphinx_mapping = { + "python": ("http://openturns.github.io/openturns/1.18", "openturns-objects.inv") +} autosummary_generate = True numpydoc_show_class_members = True @@ -87,45 +81,45 @@ # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. -source_suffix = ['.rst'] +source_suffix = [".rst"] # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'ottemplate' -copyright = u'2005-2022 Airbus-EDF-IMACS-ONERA-Phimeca' +project = u"ottemplate" +copyright = u"2005-2022 Airbus-EDF-IMACS-ONERA-Phimeca" # 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. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [] # The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description @@ -134,13 +128,13 @@ # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'friendly' # sphinx +pygments_style = "friendly" # sphinx # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True @@ -149,67 +143,69 @@ # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'openturns' -html_sourcelink_suffix = '' +html_theme = "openturns" +html_sourcelink_suffix = "" # 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 # documentation. -#html_theme_options = {} -#import alabaster -html_theme_path = ['themes'] +# html_theme_options = {} +# import alabaster +html_theme_path = ["themes"] -html_sidebars = {'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']} +html_sidebars = { + "**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"] +} # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = 'None' +# html_favicon = 'None' # 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. -html_last_updated_fmt = '%b %d, %Y' +html_last_updated_fmt = "%b %d, %Y" # Output file base name for HTML help builder. -#htmlhelp_basename = 'ottemplatedoc' +# htmlhelp_basename = 'ottemplatedoc' # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # -- Options for LaTeX output --------------------------------------------- -latex_preamble = r''' +latex_preamble = r""" \usepackage{amsfonts} \usepackage{amsmath} \usepackage{expdlist} @@ -218,45 +214,50 @@ \let\latexdescription=\description \def\description{\latexdescription{}{} \breaklabel} \DeclareMathOperator*{\argmin}{Argmin} -''' +""" latex_elements = { # The paper size ('letterpaper' or 'a4paper'). - 'papersize': 'a4paper', + "papersize": "a4paper", # The font size ('10pt', '11pt' or '12pt'). - 'pointsize': '10pt', + "pointsize": "10pt", # Additional stuff for the LaTeX preamble. - 'preamble': latex_preamble, + "preamble": latex_preamble, } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'ottemplate.tex', u'ottemplate Documentation', - u'Airbus-EDF-IMACS-Phimeca-ONERA', 'manual'), + ( + "index", + "ottemplate.tex", + u"ottemplate Documentation", + u"Airbus-EDF-IMACS-Phimeca-ONERA", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------------- @@ -264,12 +265,17 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'ottemplate', u'ottemplate Documentation', - [u'Airbus-EDF-IMACS-Phimeca-ONERA'], 1) + ( + "index", + "ottemplate", + u"ottemplate Documentation", + [u"Airbus-EDF-IMACS-Phimeca-ONERA"], + 1, + ) ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ @@ -278,19 +284,25 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'ottemplate', u'ottemplate Documentation', - u'Airbus-EDF-IMACS-Phimeca-ONERA', 'ottemplate', 'One line description of project.', - 'Miscellaneous'), + ( + "index", + "ottemplate", + u"ottemplate Documentation", + u"Airbus-EDF-IMACS-Phimeca-ONERA", + "ottemplate", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/doc/examples/plot_basic.py b/doc/examples/plot_basic.py index ef9a9b4..9dd1772 100644 --- a/doc/examples/plot_basic.py +++ b/doc/examples/plot_basic.py @@ -13,7 +13,6 @@ from openturns.viewer import View import numpy as np import ottemplate -from matplotlib import pylab as plt # %% # | Using the module to compute power diff --git a/ottemplate/__init__.py b/ottemplate/__init__.py index 6a39edc..f9f49f5 100644 --- a/ottemplate/__init__.py +++ b/ottemplate/__init__.py @@ -8,12 +8,8 @@ """ -import sys -if sys.platform.startswith('win'): - # this ensures OT dll is loaded - import openturns +# flake8: noqa from .ottemplate import MyClass __version__ = '0.1' - diff --git a/ottemplate/ottemplate.py b/ottemplate/ottemplate.py index 7a2d67c..e9ea557 100644 --- a/ottemplate/ottemplate.py +++ b/ottemplate/ottemplate.py @@ -1,7 +1,7 @@ import numpy as np -import openturns as ot -class MyClass(object): + +class MyClass: """ Class test Applying power function @@ -10,10 +10,11 @@ class MyClass(object): ---------- value : array-like or float The considered value. - + Notes ----- - Objects of type :py:class:`openturns.Sample` or :py:class:`openturns.Point` are also accepted. + Objects of type :py:class:`openturns.Sample` or :py:class:`openturns.Point` + are also accepted. """ def __init__(self, value): # set attribute diff --git a/test/test_class.py b/test/test_class.py index aef4ac8..5a7531f 100644 --- a/test/test_class.py +++ b/test/test_class.py @@ -1,10 +1,9 @@ import ottemplate -import numpy as np import openturns as ot import pytest -import numpy.testing as npt import openturns.testing as ott + @pytest.fixture(scope="session") def data(): """Provide some data""" @@ -19,4 +18,3 @@ def test_class(data): ott.assert_almost_equal(obj.power(1), value) ott.assert_almost_equal(obj.power(2), f(value)) -