From ff156664e6d388fe7310bb15b90e23aebee08f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Tue, 21 Jul 2020 13:43:23 +0200 Subject: [PATCH] Adding pre-commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced changes: - pre-commit config and rules - Add pre-commit to pep8 gate, Flake8 is covered in the pre-commit hooks. - Applying fixes for pre-commit compliance in all code. Also commit hash will be used instead of version tags in pre-commit to prevend arbitrary code from running in developer's machines. pre-commit will be used to: - trailing whitespace; - Replaces or checks mixed line ending (mixed-line-ending); - Forbid files which have a UTF-8 byte-order marker (check-byte-order-marker); - Checks that non-binary executables have a proper shebang (check-executables-have-shebangs); - Check for files that contain merge conflict strings (check-merge-conflict); - Check for debugger imports and py37+ breakpoint() calls in python source (debug-statements); - Attempts to load all yaml files to verify syntax (check-yaml); - Run flake8 checks (flake8) (local) For further details about tests please refer to: https://github.com/pre-commit/pre-commit-hooks Change-Id: I9b979afcd45e6a51252ccccb686b01beeb9157f8 Signed-off-by: Moisés Guimarães de Medeiros --- .pre-commit-config.yaml | 35 +++++++ api-ref/source/conf.py | 95 +++---------------- doc/source/conf.py | 13 +++ .../demo/create_and_manage_databases.rst | 2 +- .../static/fonts/fontawesome-webfont.svg | 2 +- .../fonts/glyphicons-halflings-regular.svg | 2 +- .../static/images/openstack-logo-full.svg | 2 +- .../static/images/openstack-logo-vert.svg | 2 +- .../notes/badge-6f8713da36a7e570.yaml | 1 - test-requirements.txt | 2 + tox.ini | 1 + 11 files changed, 69 insertions(+), 88 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..9d945567 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +# We from the Oslo project decided to pin repos based on the +# commit hash instead of the version tag to prevend arbitrary +# code from running in developer's machines. To update to a +# newer version, run `pre-commit autoupdate` and then replace +# the newer versions with their commit hash. + +default_language_version: + python: python3 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: ebc15addedad713c86ef18ae9632c88e187dd0af # v3.1.0 + hooks: + - id: trailing-whitespace + # Replaces or checks mixed line ending + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + # Forbid files which have a UTF-8 byte-order marker + - id: check-byte-order-marker + # Checks that non-binary executables have a proper shebang + - id: check-executables-have-shebangs + # Check for files that contain merge conflict strings. + - id: check-merge-conflict + # Check for debugger imports and py37+ breakpoint() + # calls in python source + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://gitlab.com/pycqa/flake8 + rev: 181bb46098dddf7e2d45319ea654b4b4d58c2840 # 3.8.3 + hooks: + - id: flake8 + additional_dependencies: + - hacking>=3.0.1,<3.1.0 diff --git a/api-ref/source/conf.py b/api-ref/source/conf.py index 7c9e5d65..acff19d1 100644 --- a/api-ref/source/conf.py +++ b/api-ref/source/conf.py @@ -1,4 +1,17 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # # This file is execfile()d with the current directory set to its # containing dir. @@ -9,19 +22,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys -import os - -# 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('.')) - # -- General configuration ------------------------------------------------ -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. @@ -32,15 +34,9 @@ extensions = [ ] -# Add any paths that contain templates here, relative to this directory. -# templates_path = ['_templates'] - # The suffix of source filenames. source_suffix = '.rst' -# The encoding of source files. -#source_encoding = 'utf-8-sig' - # The master toctree document. master_doc = 'index' @@ -66,45 +62,13 @@ release = '1.0' openstackdocs_bug_tag = "doc-builds" openstackdocs_bug_project = 'openstack-doc-tools' -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#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 = ['_build'] -# The reST default role (used for this markup: `text`) to use for all -# documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False - - # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -123,36 +87,3 @@ html_theme = 'openstackdocs' html_theme_options = {"sidebar_dropdown": "api_ref", "display_badge": False, "sidebar_mode": "toc"} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -#html_logo = None - -# 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 - -# 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/css'] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -#html_extra_path = [] - -# 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' diff --git a/doc/source/conf.py b/doc/source/conf.py index a9596bec..ef98684f 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,17 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # # openstackdocstheme documentation build configuration file diff --git a/doc/source/demo/create_and_manage_databases.rst b/doc/source/demo/create_and_manage_databases.rst index 9e0e94a6..b3318b2c 100644 --- a/doc/source/demo/create_and_manage_databases.rst +++ b/doc/source/demo/create_and_manage_databases.rst @@ -149,6 +149,6 @@ a new database instance. #. Click the :guilabel:`Restore From Database` tab and make sure that this new instance is based on the correct backup. -#. Click :guilabel:`Launch`. +#. Click :guilabel:`Launch`. The new instance appears in the database instances list. diff --git a/openstackdocstheme/theme/openstackdocs/static/fonts/fontawesome-webfont.svg b/openstackdocstheme/theme/openstackdocs/static/fonts/fontawesome-webfont.svg index 8b66187f..26d438c5 100644 --- a/openstackdocstheme/theme/openstackdocs/static/fonts/fontawesome-webfont.svg +++ b/openstackdocstheme/theme/openstackdocs/static/fonts/fontawesome-webfont.svg @@ -682,4 +682,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/openstackdocstheme/theme/openstackdocs/static/fonts/glyphicons-halflings-regular.svg b/openstackdocstheme/theme/openstackdocs/static/fonts/glyphicons-halflings-regular.svg index 94fb5490..f155876e 100644 --- a/openstackdocstheme/theme/openstackdocs/static/fonts/glyphicons-halflings-regular.svg +++ b/openstackdocstheme/theme/openstackdocs/static/fonts/glyphicons-halflings-regular.svg @@ -285,4 +285,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-full.svg b/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-full.svg index 1cb36468..a0a3debe 100644 --- a/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-full.svg +++ b/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-full.svg @@ -50,7 +50,7 @@ c-3.237,0-5.635,2.655-5.635,6.334v0.233c0,3.679,2.329,6.264,5.542,6.264C116.597,23.915,117.831,23.147,118.809,22.053z"/> - diff --git a/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-vert.svg b/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-vert.svg index 5d81a04e..7b09ed91 100644 --- a/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-vert.svg +++ b/openstackdocstheme/theme/openstackdocs/static/images/openstack-logo-vert.svg @@ -41,7 +41,7 @@ c-1.808,0-3.147,1.482-3.147,3.537v0.13c0,2.055,1.3,3.498,3.095,3.498C48.599,48.84,49.288,48.412,49.834,47.8z"/> - diff --git a/releasenotes/notes/badge-6f8713da36a7e570.yaml b/releasenotes/notes/badge-6f8713da36a7e570.yaml index 41b46583..e0ef4bdf 100644 --- a/releasenotes/notes/badge-6f8713da36a7e570.yaml +++ b/releasenotes/notes/badge-6f8713da36a7e570.yaml @@ -4,4 +4,3 @@ features: for repositories that have ``stable/`` branches. The badge is not displayed for api-ref, api-guide and releasenotes documents. It can be disabled with the ``display_badge`` html theme option. - \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index 9d7e0fd7..dbb099e3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,3 +6,5 @@ hacking>=3.0.1,<3.1.0 # Apache-2.0 # this is required for the docs build jobs sphinx>=2.0.0,!=2.1.0 # BSD + +pre-commit>=2.6.0 # MIT diff --git a/tox.ini b/tox.ini index 91359f8a..176dab62 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ whitelist_externals = [testenv:pep8] commands = + pre-commit run -a flake8 openstackdocstheme [testenv:venv]