ansible-community/ara

Run linters also on tests and docs

hille721 opened this issue · 3 comments

What is the idea ?

Due to #421 I was wondering why there were files found where isort will change things, because we have isort configured in our linter checks.
Now I realized that we are running the linter checks only on ${PROJECT_ROOT}/ara.

Imo we should also run the linters on tests and docs to ensure high quality. Will submit a PR with

Following linter violations would be detected when running the linting also on tests and docs files:

black

--- /home/hille/gitrepos/ara/setup.py   2022-08-08 06:46:48.864957 +0000
+++ /home/hille/gitrepos/ara/setup.py   2022-09-12 11:35:50.307203 +0000
@@ -1,8 +1,6 @@
 # Copyright (c) 2022 The ARA Records Ansible authors
 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
 
 import setuptools
 
-setuptools.setup(
-    setup_requires=['pbr'],
-    pbr=True)
+setuptools.setup(setup_requires=["pbr"], pbr=True)
would reformat /home/hille/gitrepos/ara/setup.py
--- /home/hille/gitrepos/ara/doc/source/conf.py 2022-09-12 08:54:44.369215 +0000
+++ /home/hille/gitrepos/ara/doc/source/conf.py 2022-09-12 11:35:50.388287 +0000
@@ -3,38 +3,35 @@
 
 import os
 import sys
 import sphinx_rtd_theme
 import pbr.version
-version_info = pbr.version.VersionInfo('ara')
 
-sys.path.insert(0, os.path.abspath('../..'))
+version_info = pbr.version.VersionInfo("ara")
+
+sys.path.insert(0, os.path.abspath("../.."))
 # -- General configuration ----------------------------------------------------
 
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = [
-    'sphinxcontrib.programoutput',
-    'sphinx.ext.autodoc',
-    'sphinx.ext.autosectionlabel'
-]
+extensions = ["sphinxcontrib.programoutput", "sphinx.ext.autodoc", "sphinx.ext.autosectionlabel"]
 autosectionlabel_prefix_document = True
 
 # autodoc generation is a bit aggressive and a nuisance when doing heavy
 # text edit cycles.
 # execute "export SPHINX_DEBUG=1" in your terminal to disable
 
 # The suffix 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'ara'
-copyright = u'2022, ARA Records Ansible authors'
-author = 'ARA Records Ansible authors'
+project = "ara"
+copyright = "2022, ARA Records Ansible authors"
+author = "ARA Records Ansible authors"
 
 # The short X.Y version.
 version = version_info.version_string()
 # The full version, including alpha/beta/rc tags.
 release = version_info.release_string()
@@ -45,30 +42,27 @@
 # If true, the current module name will be prepended to all description
 # unit titles (such as .. function::).
 add_module_names = True
 
 # The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'default'
+pygments_style = "default"
 
 # -- Options for HTML output --------------------------------------------------
 
 # The theme to use for HTML and HTML Help pages.  Major themes that come with
 # Sphinx are currently 'default' and 'sphinxdoc'.
-html_theme = 'sphinx_rtd_theme'
+html_theme = "sphinx_rtd_theme"
 html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
-html_static_path = ['_static']
+html_static_path = ["_static"]
 
 # Output file base name for HTML help builder.
-htmlhelp_basename = '%sdoc' % project
+htmlhelp_basename = "%sdoc" % project
 
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, documentclass
 # [howto/manual]).
 latex_documents = [
-    ('index',
-     '%s.tex' % project,
-     u'%s Documentation' % project,
-     u'ARA Records Ansible authors', 'manual'),
+    ("index", "%s.tex" % project, "%s Documentation" % project, "ARA Records Ansible authors", "manual"),
 ]
 
 # Example configuration for intersphinx: refer to the Python standard library.
-#intersphinx_mapping = {'http://docs.python.org/': None}
+# intersphinx_mapping = {'http://docs.python.org/': None}
would reformat /home/hille/gitrepos/ara/doc/source/conf.py
--- /home/hille/gitrepos/ara/tests/with_ansible-runner.py       2022-09-12 08:55:23.009215 +0000
+++ /home/hille/gitrepos/ara/tests/with_ansible-runner.py       2022-09-12 11:35:50.848458 +0000
@@ -10,13 +10,14 @@
 try:
     from ara.setup import callback_plugins, action_plugins, lookup_plugins
     from ara.clients.utils import get_client
 except ImportError as e:
     print("ara must be installed first: https://github.com/ansible-community/ara#getting-started")
-    raise(e)
+    raise (e)
 
 PLAYBOOK = os.path.join(os.path.dirname(__file__), "runner-playbook.yml")
+
 
 def main():
     # Configure Ansible to use the ara Ansible plugins
     os.environ["ANSIBLE_ACTION_PLUGINS"] = action_plugins
     os.environ["ANSIBLE_CALLBACK_PLUGINS"] = callback_plugins
@@ -61,20 +62,23 @@
     task = tasks["results"][0]
     results = client.get("/api/v1/results", task=task["id"])
     for result in results["results"]:
         host = client.get("/api/v1/hosts/%s" % result["host"])
 
-        print(template.format(
-            timestamp=result["ended"],
-            host=host["name"],
-            status=result["status"],
-            task=task["name"],
-            task_file=task["path"],
-            lineno=task["lineno"]
-        ))
+        print(
+            template.format(
+                timestamp=result["ended"],
+                host=host["name"],
+                status=result["status"],
+                task=task["name"],
+                task_file=task["path"],
+                lineno=task["lineno"],
+            )
+        )
 
         # Result list doesn't have a detailed view of the result including the content
         detailed_result = client.get("/api/v1/results/%s" % result["id"])
         print(json.dumps(detailed_result["content"], indent=2))
 
+
 if __name__ == "__main__":
     main()
would reformat /home/hille/gitrepos/ara/tests/with_ansible-runner.py

isort

ERROR: /home/hille/gitrepos/ara/tests/with_ansible-runner.py Imports are incorrectly sorted and/or formatted.
--- /home/hille/gitrepos/ara/tests/with_ansible-runner.py:before        2022-09-12 10:55:23.009215
+++ /home/hille/gitrepos/ara/tests/with_ansible-runner.py:after 2022-09-12 13:35:51.503252
@@ -5,11 +5,12 @@
 # Example using ara with ansible-runner
 import json
 import os
+
 import ansible_runner
 
 try:
-    from ara.setup import callback_plugins, action_plugins, lookup_plugins
     from ara.clients.utils import get_client
+    from ara.setup import action_plugins, callback_plugins, lookup_plugins
 except ImportError as e:
     print("ara must be installed first: https://github.com/ansible-community/ara#getting-started")
     raise(e)
ERROR: /home/hille/gitrepos/ara/doc/source/conf.py Imports are incorrectly sorted and/or formatted.
--- /home/hille/gitrepos/ara/doc/source/conf.py:before  2022-09-12 10:54:44.369215
+++ /home/hille/gitrepos/ara/doc/source/conf.py:after   2022-09-12 13:35:51.526890
@@ -3,8 +3,10 @@
 
 import os
 import sys
+
+import pbr.version
 import sphinx_rtd_theme
-import pbr.version
+
 version_info = pbr.version.VersionInfo('ara')
 
 sys.path.insert(0, os.path.abspath('../..'))

flake8

/home/hille/gitrepos/ara/tests/with_ansible-runner.py:15:10: E275 missing whitespace after keyword
    raise(e)
         ^
/home/hille/gitrepos/ara/tests/with_ansible-runner.py:19:1: E302 expected 2 blank lines, found 1
def main():
^
/home/hille/gitrepos/ara/tests/with_ansible-runner.py:40:5: F841 local variable 'r' is assigned to but never used
    r = ansible_runner.run(
    ^
/home/hille/gitrepos/ara/tests/with_ansible-runner.py:79:1: E305 expected 2 blank lines after class or function definition, found 1
if __name__ == "__main__":
gaby commented

@hille721 Yeah, I ran black on the code in my PR and it found around 40 files that needed changes. I was debating whether to make those changes in the same PR or a separate PR ?

I also have an example github-actions that will check the code for formatting.

@hille721 Yeah, I ran black on the code in my PR and it found around 40 files that needed changes. I was debating whether to make those changes in the same PR or a separate PR ?

you have to run black with specifying our config: black --config .black.toml. There we are excluding some files and also setting the line length to 120.

I also have an example github-actions that will check the code for formatting.

We have a zuul pipeline for that too. You can also test it locally via tox -e linters