diff options
Diffstat (limited to 'test/sanity/code-smell')
-rw-r--r-- | test/sanity/code-smell/ansible-requirements.py | 1 | ||||
-rw-r--r-- | test/sanity/code-smell/deprecated-config.requirements.in | 2 | ||||
-rw-r--r-- | test/sanity/code-smell/deprecated-config.requirements.txt | 6 | ||||
-rw-r--r-- | test/sanity/code-smell/obsolete-files.json | 2 | ||||
-rw-r--r-- | test/sanity/code-smell/package-data.requirements.in | 8 | ||||
-rw-r--r-- | test/sanity/code-smell/package-data.requirements.txt | 25 | ||||
-rw-r--r-- | test/sanity/code-smell/pymarkdown.config.json | 11 | ||||
-rw-r--r-- | test/sanity/code-smell/pymarkdown.json | 7 | ||||
-rw-r--r-- | test/sanity/code-smell/pymarkdown.py | 64 | ||||
-rw-r--r-- | test/sanity/code-smell/pymarkdown.requirements.in | 1 | ||||
-rw-r--r-- | test/sanity/code-smell/pymarkdown.requirements.txt | 9 | ||||
-rw-r--r-- | test/sanity/code-smell/release-names.py | 7 | ||||
-rw-r--r-- | test/sanity/code-smell/release-names.requirements.in | 1 | ||||
-rw-r--r-- | test/sanity/code-smell/release-names.requirements.txt | 4 | ||||
-rw-r--r-- | test/sanity/code-smell/test-constraints.py | 6 | ||||
-rw-r--r-- | test/sanity/code-smell/update-bundled.requirements.txt | 3 |
16 files changed, 117 insertions, 40 deletions
diff --git a/test/sanity/code-smell/ansible-requirements.py b/test/sanity/code-smell/ansible-requirements.py index 4d1a652..25d4ec8 100644 --- a/test/sanity/code-smell/ansible-requirements.py +++ b/test/sanity/code-smell/ansible-requirements.py @@ -1,7 +1,6 @@ from __future__ import annotations import re -import sys def read_file(path): diff --git a/test/sanity/code-smell/deprecated-config.requirements.in b/test/sanity/code-smell/deprecated-config.requirements.in index 859c4ee..4e859bb 100644 --- a/test/sanity/code-smell/deprecated-config.requirements.in +++ b/test/sanity/code-smell/deprecated-config.requirements.in @@ -1,2 +1,2 @@ -jinja2 # ansible-core requirement +jinja2 pyyaml diff --git a/test/sanity/code-smell/deprecated-config.requirements.txt b/test/sanity/code-smell/deprecated-config.requirements.txt index 338e3f3..ae96cdf 100644 --- a/test/sanity/code-smell/deprecated-config.requirements.txt +++ b/test/sanity/code-smell/deprecated-config.requirements.txt @@ -1,6 +1,4 @@ # edit "deprecated-config.requirements.in" and generate with: hacking/update-sanity-requirements.py --test deprecated-config -# pre-build requirement: pyyaml == 6.0 -# pre-build constraint: Cython < 3.0 Jinja2==3.1.2 -MarkupSafe==2.1.1 -PyYAML==6.0 +MarkupSafe==2.1.3 +PyYAML==6.0.1 diff --git a/test/sanity/code-smell/obsolete-files.json b/test/sanity/code-smell/obsolete-files.json index 02d3920..3f69cdd 100644 --- a/test/sanity/code-smell/obsolete-files.json +++ b/test/sanity/code-smell/obsolete-files.json @@ -1,6 +1,8 @@ { "include_symlinks": true, "prefixes": [ + "docs/", + "examples/", "test/runner/", "test/sanity/ansible-doc/", "test/sanity/compile/", diff --git a/test/sanity/code-smell/package-data.requirements.in b/test/sanity/code-smell/package-data.requirements.in index 3162feb..81b58bc 100644 --- a/test/sanity/code-smell/package-data.requirements.in +++ b/test/sanity/code-smell/package-data.requirements.in @@ -1,8 +1,8 @@ build # required to build sdist wheel # required to build wheel jinja2 -pyyaml # ansible-core requirement -resolvelib < 0.9.0 -rstcheck < 4 # match version used in other sanity tests +pyyaml +resolvelib < 1.1.0 +rstcheck < 6 # newer versions have too many dependencies antsibull-changelog -setuptools == 45.2.0 # minimum supported setuptools +setuptools == 66.1.0 # minimum supported setuptools diff --git a/test/sanity/code-smell/package-data.requirements.txt b/test/sanity/code-smell/package-data.requirements.txt index b66079d..ce0fb9c 100644 --- a/test/sanity/code-smell/package-data.requirements.txt +++ b/test/sanity/code-smell/package-data.requirements.txt @@ -1,18 +1,17 @@ # edit "package-data.requirements.in" and generate with: hacking/update-sanity-requirements.py --test package-data -# pre-build requirement: pyyaml == 6.0 -# pre-build constraint: Cython < 3.0 -antsibull-changelog==0.16.0 -build==0.10.0 -docutils==0.17.1 +antsibull-changelog==0.23.0 +build==1.0.3 +docutils==0.18.1 Jinja2==3.1.2 -MarkupSafe==2.1.1 -packaging==21.3 +MarkupSafe==2.1.3 +packaging==23.2 pyproject_hooks==1.0.0 -pyparsing==3.0.9 -PyYAML==6.0 -resolvelib==0.8.1 -rstcheck==3.5.0 +PyYAML==6.0.1 +resolvelib==1.0.1 +rstcheck==5.0.0 semantic-version==2.10.0 -setuptools==45.2.0 +setuptools==66.1.0 tomli==2.0.1 -wheel==0.41.0 +types-docutils==0.18.3 +typing_extensions==4.8.0 +wheel==0.41.2 diff --git a/test/sanity/code-smell/pymarkdown.config.json b/test/sanity/code-smell/pymarkdown.config.json new file mode 100644 index 0000000..afe83a3 --- /dev/null +++ b/test/sanity/code-smell/pymarkdown.config.json @@ -0,0 +1,11 @@ +{ + "plugins": { + "line-length": { + "line_length": 160, + "code_block_line_length": 160 + }, + "first-line-heading": { + "enabled": false + } + } +} diff --git a/test/sanity/code-smell/pymarkdown.json b/test/sanity/code-smell/pymarkdown.json new file mode 100644 index 0000000..986848d --- /dev/null +++ b/test/sanity/code-smell/pymarkdown.json @@ -0,0 +1,7 @@ +{ + "output": "path-line-column-code-message", + "error_code": "ansible-test", + "extensions": [ + ".md" + ] +} diff --git a/test/sanity/code-smell/pymarkdown.py b/test/sanity/code-smell/pymarkdown.py new file mode 100644 index 0000000..721c893 --- /dev/null +++ b/test/sanity/code-smell/pymarkdown.py @@ -0,0 +1,64 @@ +"""Sanity test for Markdown files.""" +from __future__ import annotations + +import pathlib +import re +import subprocess +import sys + +import typing as t + + +def main() -> None: + paths = sys.argv[1:] or sys.stdin.read().splitlines() + + cmd = [ + sys.executable, + '-m', 'pymarkdown', + '--config', pathlib.Path(__file__).parent / 'pymarkdown.config.json', + '--strict-config', + 'scan', + ] + paths + + process = subprocess.run( + cmd, + stdin=subprocess.DEVNULL, + capture_output=True, + check=False, + text=True, + ) + + if process.stderr: + print(process.stderr.strip(), file=sys.stderr) + sys.exit(1) + + if not (stdout := process.stdout.strip()): + return + + pattern = re.compile(r'^(?P<path_line_column>[^:]*:[0-9]+:[0-9]+): (?P<code>[^:]*): (?P<message>.*) \((?P<aliases>.*)\)$') + matches = parse_to_list_of_dict(pattern, stdout) + results = [f"{match['path_line_column']}: {match['aliases'].split(', ')[0]}: {match['message']}" for match in matches] + + print('\n'.join(results)) + + +def parse_to_list_of_dict(pattern: re.Pattern, value: str) -> list[dict[str, t.Any]]: + matched = [] + unmatched = [] + + for line in value.splitlines(): + match = re.search(pattern, line) + + if match: + matched.append(match.groupdict()) + else: + unmatched.append(line) + + if unmatched: + raise Exception('Pattern {pattern!r} did not match values:\n' + '\n'.join(unmatched)) + + return matched + + +if __name__ == '__main__': + main() diff --git a/test/sanity/code-smell/pymarkdown.requirements.in b/test/sanity/code-smell/pymarkdown.requirements.in new file mode 100644 index 0000000..f007771 --- /dev/null +++ b/test/sanity/code-smell/pymarkdown.requirements.in @@ -0,0 +1 @@ +pymarkdownlnt diff --git a/test/sanity/code-smell/pymarkdown.requirements.txt b/test/sanity/code-smell/pymarkdown.requirements.txt new file mode 100644 index 0000000..f906e14 --- /dev/null +++ b/test/sanity/code-smell/pymarkdown.requirements.txt @@ -0,0 +1,9 @@ +# edit "pymarkdown.requirements.in" and generate with: hacking/update-sanity-requirements.py --test pymarkdown +application-properties==0.8.1 +Columnar==1.4.1 +pymarkdownlnt==0.9.13.4 +PyYAML==6.0.1 +tomli==2.0.1 +toolz==0.12.0 +typing_extensions==4.8.0 +wcwidth==0.2.8 diff --git a/test/sanity/code-smell/release-names.py b/test/sanity/code-smell/release-names.py index 81d90d8..cac3071 100644 --- a/test/sanity/code-smell/release-names.py +++ b/test/sanity/code-smell/release-names.py @@ -22,7 +22,7 @@ Test that the release name is present in the list of used up release names from __future__ import annotations -from yaml import safe_load +import pathlib from ansible.release import __codename__ @@ -30,8 +30,7 @@ from ansible.release import __codename__ def main(): """Entrypoint to the script""" - with open('.github/RELEASE_NAMES.yml') as f: - releases = safe_load(f.read()) + releases = pathlib.Path('.github/RELEASE_NAMES.txt').read_text().splitlines() # Why this format? The file's sole purpose is to be read by a human when they need to know # which release names have already been used. So: @@ -41,7 +40,7 @@ def main(): if __codename__ == name: break else: - print('.github/RELEASE_NAMES.yml: Current codename was not present in the file') + print(f'.github/RELEASE_NAMES.txt: Current codename {__codename__!r} not present in the file') if __name__ == '__main__': diff --git a/test/sanity/code-smell/release-names.requirements.in b/test/sanity/code-smell/release-names.requirements.in deleted file mode 100644 index c3726e8..0000000 --- a/test/sanity/code-smell/release-names.requirements.in +++ /dev/null @@ -1 +0,0 @@ -pyyaml diff --git a/test/sanity/code-smell/release-names.requirements.txt b/test/sanity/code-smell/release-names.requirements.txt deleted file mode 100644 index bb6a130..0000000 --- a/test/sanity/code-smell/release-names.requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -# edit "release-names.requirements.in" and generate with: hacking/update-sanity-requirements.py --test release-names -# pre-build requirement: pyyaml == 6.0 -# pre-build constraint: Cython < 3.0 -PyYAML==6.0 diff --git a/test/sanity/code-smell/test-constraints.py b/test/sanity/code-smell/test-constraints.py index df30fe1..ac5bb4e 100644 --- a/test/sanity/code-smell/test-constraints.py +++ b/test/sanity/code-smell/test-constraints.py @@ -65,12 +65,6 @@ def main(): # keeping constraints for tests other than sanity tests in one file helps avoid conflicts print('%s:%d:%d: put the constraint (%s%s) in `%s`' % (path, lineno, 1, name, raw_constraints, constraints_path)) - for name, requirements in frozen_sanity.items(): - if len(set(req[3].group('constraints').strip() for req in requirements)) != 1: - for req in requirements: - print('%s:%d:%d: sanity constraint (%s) does not match others for package `%s`' % ( - req[0], req[1], req[3].start('constraints') + 1, req[3].group('constraints'), name)) - def check_ansible_test(path: str, requirements: list[tuple[int, str, re.Match]]) -> None: sys.path.insert(0, str(pathlib.Path(__file__).parent.parent.parent.joinpath('lib'))) diff --git a/test/sanity/code-smell/update-bundled.requirements.txt b/test/sanity/code-smell/update-bundled.requirements.txt index d9785e7..53f1e43 100644 --- a/test/sanity/code-smell/update-bundled.requirements.txt +++ b/test/sanity/code-smell/update-bundled.requirements.txt @@ -1,3 +1,2 @@ # edit "update-bundled.requirements.in" and generate with: hacking/update-sanity-requirements.py --test update-bundled -packaging==21.3 -pyparsing==3.0.9 +packaging==23.2 |