diff --git a/changelogs/fragments/ansible-test-rstcheck-pin.yml b/changelogs/fragments/ansible-test-rstcheck-pin.yml new file mode 100644 index 00000000000..7134c563644 --- /dev/null +++ b/changelogs/fragments/ansible-test-rstcheck-pin.yml @@ -0,0 +1,3 @@ +bugfixes: + - ansible-test - Add ``rstcheck == 3.3.1`` constraint to avoid breaking changes in newer releases. + - ansible-test - Support newer Jinja2 versions in the ``rstcheck`` sanity test. diff --git a/test/lib/ansible_test/_data/requirements/constraints.txt b/test/lib/ansible_test/_data/requirements/constraints.txt index 23afa24e88c..9afe915d26b 100644 --- a/test/lib/ansible_test/_data/requirements/constraints.txt +++ b/test/lib/ansible_test/_data/requirements/constraints.txt @@ -10,6 +10,7 @@ urllib3 < 1.24 ; python_version < '2.7' # urllib3 1.24 and later require python pywinrm >= 0.3.0 # message encryption support sphinx < 1.6 ; python_version < '2.7' # sphinx 1.6 and later require python 2.7 or later sphinx < 1.8 ; python_version >= '2.7' # sphinx 1.8 and later are currently incompatible with rstcheck 3.3 +rstcheck == 3.3.1 # avoid compatibility issues with newer versions pygments >= 2.4.0 # Pygments 2.4.0 includes bugfixes for YAML and YAML+Jinja lexers wheel < 0.30.0 ; python_version < '2.7' # wheel 0.30.0 and later require python 2.7 or later yamllint != 1.8.0, < 1.14.0 ; python_version < '2.7' # yamllint 1.8.0 and 1.14.0+ require python 2.7+ diff --git a/test/lib/ansible_test/_data/sanity/rstcheck/rstcheck-cli.py b/test/lib/ansible_test/_data/sanity/rstcheck/rstcheck-cli.py new file mode 100644 index 00000000000..b826b8fb828 --- /dev/null +++ b/test/lib/ansible_test/_data/sanity/rstcheck/rstcheck-cli.py @@ -0,0 +1,19 @@ +"""Wrapper around rstcheck to provide Jinja2 compatibility for Sphinx.""" +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import runpy +import sys + +try: + from jinja2.filters import pass_context as _passctx, pass_environment as _passenv + _mod = sys.modules['jinja2'] # pylint: disable=invalid-name + _mod.contextfunction = _passctx + _mod.environmentfilter = _passenv +except ImportError: + pass + +sys.path.remove(os.path.dirname(__file__)) # avoid recursively running sanity test + +runpy.run_module('rstcheck', run_name='__main__', alter_sys=True) diff --git a/test/lib/ansible_test/_internal/sanity/rstcheck.py b/test/lib/ansible_test/_internal/sanity/rstcheck.py index b0fbb916268..5ceacbab0c7 100644 --- a/test/lib/ansible_test/_internal/sanity/rstcheck.py +++ b/test/lib/ansible_test/_internal/sanity/rstcheck.py @@ -56,7 +56,7 @@ class RstcheckTest(SanitySingleVersion): cmd = [ find_python(python_version), - '-m', 'rstcheck', + os.path.join(SANITY_ROOT, 'rstcheck', 'rstcheck-cli.py'), '--report', 'warning', '--ignore-substitutions', ','.join(ignore_substitutions), ] + paths