From 5f29cd5e6053de29251944b34b7dddc8d1cece75 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Sun, 17 Dec 2017 03:23:54 +1000 Subject: [PATCH] Add validation test for new copyright (#32919) * Update validation test for new copyright Ensure new modules without the new copyright header fail validation Ensure existing modules without copyright in top 20 lines fail * Add documentation of 108 error Create label in developing modules documentation so that the validation page can point to it * Ensure new style copyright header passes test! --- .../developing_modules_documenting.rst | 1 + .../dev_guide/testing_validate-modules.rst | 1 + test/sanity/validate-modules/main.py | 20 ++++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/docsite/rst/dev_guide/developing_modules_documenting.rst b/docs/docsite/rst/dev_guide/developing_modules_documenting.rst index 817d2dd1db..91fd17f7bb 100644 --- a/docs/docsite/rst/dev_guide/developing_modules_documenting.rst +++ b/docs/docsite/rst/dev_guide/developing_modules_documenting.rst @@ -30,6 +30,7 @@ All modules must have the following sections defined in this order: If you look at some existing older modules, you may find imports at the bottom of the file. Do not copy that idiom into new modules as it is a historical oddity due to how modules used to be combined with libraries. Over time we're moving the imports to be in their proper place. +.. _copyright: Copyright ---------------------- diff --git a/docs/docsite/rst/dev_guide/testing_validate-modules.rst b/docs/docsite/rst/dev_guide/testing_validate-modules.rst index 1c8ee2f86a..625c1ed265 100644 --- a/docs/docsite/rst/dev_guide/testing_validate-modules.rst +++ b/docs/docsite/rst/dev_guide/testing_validate-modules.rst @@ -69,6 +69,7 @@ Errors 106 Import found before documentation variables. All imports must appear below ``DOCUMENTATION``/``EXAMPLES``/``RETURN``/``ANSIBLE_METADATA`` 107 Imports should be directly below ``DOCUMENTATION``/``EXAMPLES``/``RETURN``/``ANSIBLE_METADATA`` + 108 GPLv3 license header should be the :ref:`short form ` for new modules .. --------- ------------------- **2xx** **Imports** diff --git a/test/sanity/validate-modules/main.py b/test/sanity/validate-modules/main.py index 5909dc7b3c..599f8d4965 100755 --- a/test/sanity/validate-modules/main.py +++ b/test/sanity/validate-modules/main.py @@ -375,14 +375,24 @@ class ModuleValidator(Validator): msg='sys.exit() call found. Should be exit_json/fail_json' ) - def _check_for_gpl3_header(self): - if ('GNU General Public License' not in self.text and - 'version 3' not in self.text): + def _check_gpl3_header(self): + header = '\n'.join(self.text.split('\n')[:20]) + if ('GNU General Public License' not in header or + ('version 3' not in header and 'v3.0' not in header)): self.reporter.error( path=self.object_path, code=105, - msg='GPLv3 license header not found' + msg='GPLv3 license header not found in the first 20 lines of the module' ) + elif self._is_new_module(): + if len([line for line in header + if 'GNU General Public License' in line]) > 1: + self.reporter.error( + path=self.object_path, + code=108, + msg='Found old style GPLv3 license header: ' + 'https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#copyright' + ) def _check_for_tabs(self): for line_no, line in enumerate(self.text.splitlines()): @@ -1118,7 +1128,7 @@ class ModuleValidator(Validator): self._validate_ps_replacers() self._find_ps_docs_py_file() - self._check_for_gpl3_header() + self._check_gpl3_header() if not self._just_docs(): self._check_interpreter(powershell=self._powershell_module()) self._check_type_instead_of_isinstance(