summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.config/constraints.txt (renamed from requirements.txt)261
-rw-r--r--.config/requirements-docs.in3
-rw-r--r--.config/requirements-test.in5
-rw-r--r--.config/requirements.in7
-rw-r--r--.git_archival.txt8
-rw-r--r--.github/dependabot.yml9
-rw-r--r--.github/workflows/ack.yml2
-rw-r--r--.github/workflows/push.yml4
-rw-r--r--.github/workflows/release.yml6
-rw-r--r--.github/workflows/tox.yml15
-rw-r--r--.pre-commit-config.yaml20
-rw-r--r--.readthedocs.yml2
-rw-r--r--pyproject.toml33
-rw-r--r--src/ansible_compat/runtime.py23
-rw-r--r--test/test_runtime.py13
-rw-r--r--tox.ini4
16 files changed, 207 insertions, 208 deletions
diff --git a/requirements.txt b/.config/constraints.txt
index 1d4ed20..17f80d3 100644
--- a/requirements.txt
+++ b/.config/constraints.txt
@@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
-# pip-compile --extra=docs --extra=test --output-file=requirements.txt --strip-extras --unsafe-package=ansible-core --unsafe-package=resolvelib --unsafe-package=typing_extensions pyproject.toml
+# pip-compile --all-extras --output-file=.config/constraints.txt --strip-extras --unsafe-package=ansible-core --unsafe-package=resolvelib --unsafe-package=typing_extensions pyproject.toml
#
argparse-manpage==4.5
# via ansible-compat (pyproject.toml)
@@ -10,324 +10,265 @@ attrs==23.2.0
# via
# jsonschema
# referencing
-babel==2.13.1
- # via
- # mkdocs-ansible
- # mkdocs-material
-beautifulsoup4==4.12.2
+babel==2.15.0
+ # via mkdocs-material
+beautifulsoup4==4.12.3
# via
# linkchecker
- # mkdocs-ansible
# mkdocs-htmlproofer-plugin
-black==23.12.1
+black==24.4.2
# via ansible-compat (pyproject.toml)
-build==1.0.3
+build==1.2.1
# via pip-tools
-cairocffi==1.6.1
- # via
- # cairosvg
- # mkdocs-ansible
+cairocffi==1.7.0
+ # via cairosvg
cairosvg==2.7.1
# via mkdocs-ansible
-certifi==2023.11.17
- # via
- # mkdocs-ansible
- # requests
+certifi==2024.2.2
+ # via requests
cffi==1.16.0
# via
# cairocffi
# cryptography
- # mkdocs-ansible
charset-normalizer==3.3.2
- # via
- # mkdocs-ansible
- # requests
+ # via requests
click==8.1.7
# via
# black
# mkdocs
- # mkdocs-ansible
# mkdocstrings
# pip-tools
colorama==0.4.6
# via
# griffe
- # mkdocs-ansible
# mkdocs-material
-coverage==7.4.0
+coverage==7.5.1
# via ansible-compat (pyproject.toml)
-cryptography==41.0.7
+cryptography==42.0.7
# via ansible-core
csscompressor==0.9.5
- # via
- # mkdocs-ansible
- # mkdocs-minify-plugin
+ # via mkdocs-minify-plugin
cssselect2==0.7.0
- # via
- # cairosvg
- # mkdocs-ansible
+ # via cairosvg
defusedxml==0.7.1
- # via
- # cairosvg
- # mkdocs-ansible
-dnspython==2.4.2
- # via
- # linkchecker
- # mkdocs-ansible
-exceptiongroup==1.2.0
+ # via cairosvg
+dnspython==2.6.1
+ # via linkchecker
+exceptiongroup==1.2.1
# via pytest
ghp-import==2.1.0
- # via
- # mkdocs
- # mkdocs-ansible
-griffe==0.38.0
- # via
- # mkdocs-ansible
- # mkdocstrings-python
+ # via mkdocs
+griffe==0.44.0
+ # via mkdocstrings-python
htmlmin2==0.1.13
- # via
- # mkdocs-ansible
- # mkdocs-minify-plugin
-idna==3.4
- # via
- # mkdocs-ansible
- # requests
-importlib-metadata==6.8.0
- # via mkdocs-ansible
+ # via mkdocs-minify-plugin
+idna==3.7
+ # via requests
iniconfig==2.0.0
# via pytest
-jinja2==3.1.2
+jinja2==3.1.4
# via
# ansible-core
# mkdocs
- # mkdocs-ansible
+ # mkdocs-macros-plugin
# mkdocs-material
# mkdocstrings
jsmin==3.0.1
- # via
- # mkdocs-ansible
- # mkdocs-minify-plugin
-jsonschema==4.20.0
+ # via mkdocs-minify-plugin
+jsonschema==4.22.0
# via ansible-compat (pyproject.toml)
jsonschema-specifications==2023.12.1
# via jsonschema
-linkchecker==10.3.0
+linkchecker==10.4.0
# via mkdocs-ansible
-markdown==3.5.1
+markdown==3.6
# via
# markdown-include
# mkdocs
- # mkdocs-ansible
# mkdocs-autorefs
# mkdocs-htmlproofer-plugin
# mkdocs-material
# mkdocstrings
# pymdown-extensions
-markdown-exec==1.8.0
+markdown-exec==1.8.1
# via mkdocs-ansible
markdown-include==0.8.1
# via mkdocs-ansible
-markupsafe==2.1.3
+markupsafe==2.1.5
# via
# jinja2
# mkdocs
- # mkdocs-ansible
+ # mkdocs-autorefs
# mkdocstrings
mergedeep==1.3.4
# via
# mkdocs
- # mkdocs-ansible
-mkdocs==1.5.3
+ # mkdocs-get-deps
+mkdocs==1.6.0
# via
# mkdocs-ansible
# mkdocs-autorefs
# mkdocs-gen-files
# mkdocs-htmlproofer-plugin
+ # mkdocs-macros-plugin
# mkdocs-material
# mkdocs-minify-plugin
# mkdocs-monorepo-plugin
# mkdocstrings
-mkdocs-ansible==0.2.1
- # via
- # ansible-compat (pyproject.toml)
- # mkdocs-ansible
-mkdocs-autorefs==0.5.0
- # via
- # mkdocs-ansible
- # mkdocstrings
+mkdocs-ansible==24.3.1
+ # via ansible-compat (pyproject.toml)
+mkdocs-autorefs==1.0.1
+ # via mkdocstrings
mkdocs-gen-files==0.5.0
# via mkdocs-ansible
-mkdocs-htmlproofer-plugin==1.0.0
+mkdocs-get-deps==0.2.0
+ # via mkdocs
+mkdocs-htmlproofer-plugin==1.2.1
+ # via mkdocs-ansible
+mkdocs-macros-plugin==1.0.5
# via mkdocs-ansible
-mkdocs-material==9.5.3
+mkdocs-material==9.5.21
# via mkdocs-ansible
mkdocs-material-extensions==1.3.1
# via
# mkdocs-ansible
# mkdocs-material
-mkdocs-minify-plugin==0.7.2
+mkdocs-minify-plugin==0.8.0
# via mkdocs-ansible
mkdocs-monorepo-plugin==1.1.0
# via mkdocs-ansible
-mkdocstrings==0.24.0
+mkdocstrings==0.25.1
# via
# mkdocs-ansible
# mkdocstrings-python
-mkdocstrings-python==1.7.5
+mkdocstrings-python==1.10.0
# via mkdocs-ansible
mypy-extensions==1.0.0
# via black
-packaging==23.2
+packaging==24.0
# via
# ansible-compat (pyproject.toml)
# ansible-core
# black
# build
# mkdocs
- # mkdocs-ansible
+ # pipdeptree
# pytest
paginate==0.5.6
- # via
- # mkdocs-ansible
- # mkdocs-material
-pathspec==0.11.2
+ # via mkdocs-material
+pathspec==0.12.1
# via
# black
# mkdocs
- # mkdocs-ansible
-pillow==10.2.0
+pillow==10.3.0
# via
# cairosvg
# mkdocs-ansible
-pip==23.3.2
- # via pip-tools
-pip-tools==7.3.0
+pip==24.0
+ # via
+ # pip-tools
+ # pipdeptree
+pip-tools==7.4.1
# via ansible-compat (pyproject.toml)
-pipdeptree==2.13.1
+pipdeptree==2.20.0
# via mkdocs-ansible
-platformdirs==4.0.0
+platformdirs==4.2.1
# via
# black
- # mkdocs
- # mkdocs-ansible
+ # mkdocs-get-deps
# mkdocstrings
-pluggy==1.3.0
+pluggy==1.5.0
# via pytest
-pycparser==2.21
- # via
- # cffi
- # mkdocs-ansible
-pygments==2.17.1
- # via
- # mkdocs-ansible
- # mkdocs-material
-pymdown-extensions==10.7
+pycparser==2.22
+ # via cffi
+pygments==2.18.0
+ # via mkdocs-material
+pymdown-extensions==10.8.1
# via
# markdown-exec
# mkdocs-ansible
# mkdocs-material
# mkdocstrings
-pyproject-hooks==1.0.0
- # via build
-pytest==7.4.4
+pyproject-hooks==1.1.0
+ # via
+ # build
+ # pip-tools
+pytest==8.2.0
# via
# ansible-compat (pyproject.toml)
# pytest-mock
# pytest-plus
-pytest-mock==3.12.0
+pytest-mock==3.14.0
# via ansible-compat (pyproject.toml)
-pytest-plus==0.6.1
+pytest-plus==0.7.0
# via ansible-compat (pyproject.toml)
-python-dateutil==2.8.2
+python-dateutil==2.9.0.post0
# via
# ghp-import
- # mkdocs-ansible
-python-slugify==8.0.1
- # via
- # mkdocs-ansible
- # mkdocs-monorepo-plugin
+ # mkdocs-macros-plugin
+python-slugify==8.0.4
+ # via mkdocs-monorepo-plugin
pyyaml==6.0.1
# via
# ansible-compat (pyproject.toml)
# ansible-core
# mkdocs
- # mkdocs-ansible
+ # mkdocs-get-deps
+ # mkdocs-macros-plugin
# pymdown-extensions
# pyyaml-env-tag
pyyaml-env-tag==0.1
- # via
- # mkdocs
- # mkdocs-ansible
-referencing==0.32.1
+ # via mkdocs
+referencing==0.35.1
# via
# jsonschema
# jsonschema-specifications
-regex==2023.10.3
- # via
- # mkdocs-ansible
- # mkdocs-material
+regex==2024.4.28
+ # via mkdocs-material
requests==2.31.0
# via
# linkchecker
- # mkdocs-ansible
# mkdocs-htmlproofer-plugin
# mkdocs-material
-rpds-py==0.16.2
+rpds-py==0.18.1
# via
# jsonschema
# referencing
-setuptools==69.0.3
+setuptools==69.5.1
# via pip-tools
six==1.16.0
- # via
- # mkdocs-ansible
- # python-dateutil
+ # via python-dateutil
soupsieve==2.5
- # via
- # beautifulsoup4
- # mkdocs-ansible
+ # via beautifulsoup4
subprocess-tee==0.4.1
# via ansible-compat (pyproject.toml)
+termcolor==2.4.0
+ # via mkdocs-macros-plugin
text-unidecode==1.3
- # via
- # mkdocs-ansible
- # python-slugify
-tinycss2==1.2.1
+ # via python-slugify
+tinycss2==1.3.0
# via
# cairosvg
# cssselect2
- # mkdocs-ansible
tomli==2.0.1
# via
# argparse-manpage
# black
# build
# pip-tools
- # pyproject-hooks
# pytest
-typing-extensions==4.8.0
- # via
- # black
- # mkdocs-ansible
-urllib3==2.1.0
- # via
- # mkdocs-ansible
- # requests
-watchdog==3.0.0
- # via
- # mkdocs
- # mkdocs-ansible
+typing-extensions==4.11.0
+ # via black
+urllib3==2.2.1
+ # via requests
+watchdog==4.0.0
+ # via mkdocs
webencodings==0.5.1
# via
# cssselect2
- # mkdocs-ansible
# tinycss2
-wheel==0.42.0
+wheel==0.43.0
# via pip-tools
-zipp==3.17.0
- # via
- # importlib-metadata
- # mkdocs-ansible
# The following packages are considered to be unsafe in a requirements file:
# ansible-core
diff --git a/.config/requirements-docs.in b/.config/requirements-docs.in
new file mode 100644
index 0000000..e4b17c4
--- /dev/null
+++ b/.config/requirements-docs.in
@@ -0,0 +1,3 @@
+argparse-manpage
+black
+mkdocs-ansible>=24.3.1
diff --git a/.config/requirements-test.in b/.config/requirements-test.in
new file mode 100644
index 0000000..85d4c2d
--- /dev/null
+++ b/.config/requirements-test.in
@@ -0,0 +1,5 @@
+coverage
+pip-tools
+pytest-mock
+pytest-plus>=0.6.1
+pytest>=7.2.0
diff --git a/.config/requirements.in b/.config/requirements.in
new file mode 100644
index 0000000..29c2662
--- /dev/null
+++ b/.config/requirements.in
@@ -0,0 +1,7 @@
+# https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html
+ansible-core>=2.12
+packaging
+PyYAML
+subprocess-tee>=0.4.1
+jsonschema>=4.6.0
+typing-extensions>=4.5.0;python_version<'3.10'
diff --git a/.git_archival.txt b/.git_archival.txt
index d6cf91b..1f151b2 100644
--- a/.git_archival.txt
+++ b/.git_archival.txt
@@ -1,4 +1,4 @@
-node: 1ff572c26b20363436af440921fec1b3d6d1d19f
-node-date: 2024-03-11T15:50:46+00:00
-describe-name: v4.1.12
-ref-names: tag: v4.1.12
+node: 77f4aa656f20def28864421bd8a3c94fceeb61b4
+node-date: 2024-05-08T17:33:47+01:00
+describe-name: v24.5.1
+ref-names: HEAD -> main, tag: v24.5.1a0, tag: v24.5.1
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 45874a7..3d396cc 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,10 +1,8 @@
---
-# Until bug below is sorted we will not allow dependabot to run by itself
-# https://github.com/dependabot/dependabot-core/issues/369
version: 2
updates:
- package-ecosystem: pip
- directory: /
+ directory: ".config"
schedule:
day: sunday
interval: weekly
@@ -12,7 +10,10 @@ updates:
- dependabot-deps-updates
- skip-changelog
versioning-strategy: lockfile-only
- open-pull-requests-limit: 0 # neutered
+ groups:
+ dependencies:
+ patterns:
+ - "*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
diff --git a/.github/workflows/ack.yml b/.github/workflows/ack.yml
index 1a73a9d..376206b 100644
--- a/.github/workflows/ack.yml
+++ b/.github/workflows/ack.yml
@@ -1,4 +1,4 @@
-# See https://github.com/ansible/devtools/blob/main/.github/workflows/ack.yml
+# See https://github.com/ansible/team-devtools/blob/main/.github/workflows/ack.yml
name: ack
on:
pull_request_target:
diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index c0c8e95..5b400b4 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -1,4 +1,4 @@
-# See https://github.com/ansible/devtools/blob/main/.github/workflows/push.yml
+# See https://github.com/ansible/team-devtools/blob/main/.github/workflows/push.yml
name: push
on:
push:
@@ -9,4 +9,4 @@ on:
jobs:
ack:
- uses: ansible/devtools/.github/workflows/push.yml@main
+ uses: ansible/team-devtools/.github/workflows/push.yml@main
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b05de88..e207cb2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -5,12 +5,8 @@ on:
types: [published]
jobs:
- before-release:
- uses: ansible/ansible-compat/.github/workflows/tox.yml@main
-
release:
name: release ${{ github.event.ref }}
- needs: before-release
# unable to use environment with uses/with, basically cannot reuse release pipelines
environment: release
runs-on: ubuntu-22.04
@@ -34,6 +30,6 @@ jobs:
with:
fetch-depth: 0 # needed by setuptools-scm
- name: Build dists
- run: python -m tox -e pkg
+ run: python3 -m tox -e pkg
- name: Publish to pypi.org
uses: pypa/gh-action-pypi-publish@unstable/v1
diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml
index c767c48..26df89b 100644
--- a/.github/workflows/tox.yml
+++ b/.github/workflows/tox.yml
@@ -78,15 +78,15 @@ jobs:
run: python3 -m pip install --upgrade 'tox>=4.0.3'
- name: Initialize tox envs
- run: python -m tox --notest --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }}
+ run: python3 -m tox --notest --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }}
- name: Test with tox
- run: python -m tox -e ${{ matrix.passed_name }}
+ run: python3 -m tox -e ${{ matrix.passed_name }}
- name: Archive logs
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
- name: logs.zip
+ name: logs-${{ matrix.name }}.zip
path: .tox/**/log/
- name: Upload coverage data
@@ -105,6 +105,13 @@ jobs:
- build
runs-on: ubuntu-22.04
steps:
+ - name: Merge logs into a single archive
+ uses: actions/upload-artifact/merge@v4
+ with:
+ name: logs.zip
+ pattern: logs*.zip
+ delete-merged: true
+
- name: Check codecov.io status
if: github.event_name == 'pull_request'
uses: coactions/codecov-status@main
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 57030ab..e8fed89 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -22,7 +22,7 @@ exclude: |
)$
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: "v0.2.0"
+ rev: "v0.4.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
@@ -40,7 +40,7 @@ repos:
- prettier-plugin-toml
- prettier-plugin-sort-json
- repo: https://github.com/pre-commit/pre-commit-hooks.git
- rev: v4.5.0
+ rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
@@ -60,19 +60,19 @@ repos:
hooks:
- id: codespell
- repo: https://github.com/adrienverge/yamllint.git
- rev: v1.33.0
+ rev: v1.35.1
hooks:
- id: yamllint
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/psf/black
- rev: 24.1.1
+ rev: 24.4.2
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
- rev: v1.8.0
+ rev: v1.10.0
hooks:
- id: mypy
# empty args needed in order to match mypy cli behavior
@@ -89,7 +89,7 @@ repos:
- types-pkg_resources
- types-jsonschema>=4.4.9
- repo: https://github.com/pycqa/pylint
- rev: v3.0.3
+ rev: v3.1.0
hooks:
- id: pylint
additional_dependencies:
@@ -104,20 +104,20 @@ repos:
name: Upgrade constraints files and requirements
files: ^(pyproject\.toml|requirements\.txt)$
language: python
- entry: python -m piptools compile --resolver=backtracking --upgrade -q --strip-extras --extra docs --extra test --output-file=requirements.txt pyproject.toml --unsafe-package ansible-core --unsafe-package resolvelib --unsafe-package typing_extensions
+ entry: python3 -m piptools compile --resolver=backtracking --upgrade -q --strip-extras --all-extras --output-file=.config/constraints.txt pyproject.toml --unsafe-package ansible-core --unsafe-package resolvelib --unsafe-package typing_extensions
pass_filenames: false
stages:
- manual
additional_dependencies:
- - pip-tools>=6.11.0
+ - pip-tools>=7.4.1
- id: pip-compile
name: Check constraints files and requirements
files: ^(pyproject\.toml|requirements\.txt)$
language: python
- entry: python -m piptools compile --resolver=backtracking -q --strip-extras --extra docs --extra test --output-file=requirements.txt pyproject.toml --unsafe-package ansible-core --unsafe-package resolvelib --unsafe-package typing_extensions
+ entry: python3 -m piptools compile --resolver=backtracking -q --strip-extras --all-extras --output-file=.config/constraints.txt pyproject.toml --unsafe-package ansible-core --unsafe-package resolvelib --unsafe-package typing_extensions
pass_filenames: false
additional_dependencies:
- - pip-tools>=6.11.0
+ - pip-tools>=7.4.1
- repo: https://github.com/packit/pre-commit-hooks
rev: v1.2.0
hooks:
diff --git a/.readthedocs.yml b/.readthedocs.yml
index a36c386..66a051a 100644
--- a/.readthedocs.yml
+++ b/.readthedocs.yml
@@ -36,7 +36,7 @@ python:
version: "3.9"
install:
# On https://readthedocs.org/dashboard/ansible-lint/environmentvariables/ we
- # do have PIP_CONSTRAINTS=requirements.txt which ensures we install only
+ # do have PIP_CONSTRAINTS=.config/constraints.txt which ensures we install only
# pinned requirements that that we know to be working.
- method: pip
path: .
diff --git a/pyproject.toml b/pyproject.toml
index 0e7d843..51b6a80 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
[project]
# https://peps.python.org/pep-0621/#readme
requires-python = ">=3.9"
-dynamic = ["version"]
+dynamic = ["version", "dependencies", "optional-dependencies"]
name = "ansible-compat"
description = "Ansible compatibility goodies"
readme = "README.md"
@@ -36,23 +36,10 @@ classifiers = [
"Topic :: Utilities"
]
keywords = ["ansible"]
-dependencies = [
- # https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html
- "ansible-core>=2.12",
- "packaging",
- "PyYAML",
- "subprocess-tee>=0.4.1",
- "jsonschema>=4.6.0",
- "typing-extensions>=4.5.0;python_version<'3.10'"
-]
-
-[project.optional-dependencies]
-docs = ["argparse-manpage", "black", "mkdocs-ansible[lock]>=0.1.2"]
-test = ["coverage", "pip-tools", "pytest>=7.2.0", "pytest-mock", "pytest-plus>=0.6.1"]
[project.urls]
homepage = "https://github.com/ansible/ansible-compat"
-documentation = "https://ansible-compat.readthedocs.io/"
+documentation = "https://ansible.readthedocs.io/projects/compat/"
repository = "https://github.com/ansible/ansible-compat"
changelog = "https://github.com/ansible/ansible-compat/releases"
@@ -160,6 +147,22 @@ known-third-party = ["packaging"]
[tool.ruff.pydocstyle]
convention = "pep257"
+[tool.setuptools.dynamic]
+dependencies = {file = [".config/requirements.in"]}
+optional-dependencies.docs = {file = [".config/requirements-docs.in"]}
+optional-dependencies.test = {file = [".config/requirements-test.in"]}
+
[tool.setuptools_scm]
local_scheme = "no-local-version"
+tag_regex = "^(?P<prefix>v)?(?P<version>\\d+[^\\+]*)(?P<suffix>.*)?$"
write_to = "src/ansible_compat/_version.py"
+# To prevent accidental pick of mobile version tags such 'v6'
+git_describe_command = [
+ "git",
+ "describe",
+ "--dirty",
+ "--tags",
+ "--long",
+ "--match",
+ "v*.*"
+]
diff --git a/src/ansible_compat/runtime.py b/src/ansible_compat/runtime.py
index 4556b7e..fbeaa98 100644
--- a/src/ansible_compat/runtime.py
+++ b/src/ansible_compat/runtime.py
@@ -156,6 +156,7 @@ class Runtime:
# to do it multiple tilmes will cause runtime warnings from within ansible-core
initialized: bool = False
plugins: Plugins
+ _has_playbook_cache: dict[tuple[str, Path | None], bool] = {}
def __init__(
self,
@@ -432,6 +433,28 @@ class Runtime:
return False
return True
+ def has_playbook(self, playbook: str, *, basedir: Path | None = None) -> bool:
+ """Return true if ansible can load a given playbook.
+
+ This is also used for checking if playbooks from within collections
+ are present and if they pass syntax check.
+ """
+ if (playbook, basedir) in self._has_playbook_cache:
+ return self._has_playbook_cache[playbook, basedir]
+
+ proc = self.run(["ansible-playbook", "--syntax-check", playbook], cwd=basedir)
+ result = proc.returncode == 0
+ if not result:
+ if not basedir:
+ basedir = Path()
+ msg = f"has_playbook returned false for '{basedir / playbook}' due to syntax check returning {proc.returncode}"
+ logging.debug(msg)
+
+ # cache the result
+ self._has_playbook_cache[playbook, basedir] = result
+
+ return result
+
def install_collection(
self,
collection: str | Path,
diff --git a/test/test_runtime.py b/test/test_runtime.py
index 6a110d4..0823f60 100644
--- a/test/test_runtime.py
+++ b/test/test_runtime.py
@@ -893,3 +893,16 @@ def test_get_galaxy_role_name_invalid() -> None:
"role_name": False, # <-- invalid data, should be string
}
assert _get_galaxy_role_name(galaxy_infos) == ""
+
+
+def test_runtime_has_playbook() -> None:
+ """Tests has_playbook method."""
+ runtime = Runtime(require_module=True)
+
+ assert not runtime.has_playbook("this-does-not-exist.yml")
+ # call twice to ensure cache is used:
+ assert not runtime.has_playbook("this-does-not-exist.yml")
+
+ assert not runtime.has_playbook("this-does-not-exist.yml", basedir=Path())
+ # this is part of community.molecule collection
+ assert runtime.has_playbook("community.molecule.validate.yml")
diff --git a/tox.ini b/tox.ini
index 88ce66a..6f6c82b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -85,9 +85,9 @@ setenv =
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
PIP_DISABLE_PIP_VERSION_CHECK = 1
- PIP_CONSTRAINT = {toxinidir}/requirements.txt
+ PIP_CONSTRAINT = {toxinidir}/.config/constraints.txt
PRE_COMMIT_COLOR = always
- PYTEST_REQPASS = 93
+ PYTEST_REQPASS = 94
FORCE_COLOR = 1
allowlist_externals =
ansible