From 1cc8f978f64be8ba71d22bda0ccf6dd1289b0803 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 20 Apr 2022 11:04:48 -0700 Subject: [stable-2.9] ansible-test - Pin rstcheck version. (#77584) * ansible-test - Pin rstcheck version. * ansible-test - Support newer Jinja2 versions for rstcheck sanity test. (cherry picked from commit 5859e99a30e863112a108f2cd5017e19be5a3419) Co-authored-by: Matt Clay --- changelogs/fragments/ansible-test-rstcheck-pin.yml | 3 +++ .../ansible_test/_data/requirements/constraints.txt | 1 + .../_data/sanity/rstcheck/rstcheck-cli.py | 19 +++++++++++++++++++ test/lib/ansible_test/_internal/sanity/rstcheck.py | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-rstcheck-pin.yml create mode 100644 test/lib/ansible_test/_data/sanity/rstcheck/rstcheck-cli.py diff --git a/changelogs/fragments/ansible-test-rstcheck-pin.yml b/changelogs/fragments/ansible-test-rstcheck-pin.yml new file mode 100644 index 0000000000..7134c56364 --- /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 63137c3e7f..bdb3767aee 100644 --- a/test/lib/ansible_test/_data/requirements/constraints.txt +++ b/test/lib/ansible_test/_data/requirements/constraints.txt @@ -9,6 +9,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 0000000000..b826b8fb82 --- /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 b0fbb91626..5ceacbab0c 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 -- cgit v1.2.1