From 3e265ff5e7c6a1bbe228e49b6cda0d21269bc7ff Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 27 Sep 2024 16:36:22 +0100 Subject: [PATCH] Minor build fixes (#386) --- .config/pydoclint-baseline.txt | 3 +++ .gitignore | 4 ++-- .pre-commit-config.yaml | 22 +++++++++++++--------- bindep.txt | 2 +- pyproject.toml | 10 ++++++++++ tests/conftest.py | 25 ++++++++++++++----------- tests/integration/test_container.py | 2 +- tox.ini | 1 + 8 files changed, 45 insertions(+), 24 deletions(-) diff --git a/.config/pydoclint-baseline.txt b/.config/pydoclint-baseline.txt index e69de29..157652a 100644 --- a/.config/pydoclint-baseline.txt +++ b/.config/pydoclint-baseline.txt @@ -0,0 +1,3 @@ +tests/conftest.py + DOC503: Method `Infrastructure.__post_init__` exceptions in the "Raises" section in the docstring do not match those in the function body Raises values in the docstring: ['ValueError', 'ValueError', 'ValueError']. Raised exceptions in the body: ['ValueError']. +-------------------- diff --git a/.gitignore b/.gitignore index 3d33320..03ae4d1 100644 --- a/.gitignore +++ b/.gitignore @@ -175,5 +175,5 @@ cython_debug/ _readthedocs # ansible-builder -context -collections +/context +/collections diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f95823..1f12d4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,27 +43,31 @@ repos: - prettier-plugin-toml - prettier-plugin-sort-json - - repo: https://github.com/psf/black - rev: 24.8.0 - hooks: - - id: black - - repo: https://github.com/pappasam/toml-sort rev: v0.23.1 hooks: - id: toml-sort-fix - repo: https://github.com/tox-dev/tox-ini-fmt - rev: 1.3.1 + rev: 1.4.1 hooks: - id: tox-ini-fmt - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.3 + rev: v0.6.8 hooks: - id: ruff args: + - --fix - --exit-non-zero-on-fix + types_or: [python, pyi] + - id: ruff-format # must be after ruff + types_or: [python, pyi] + + - repo: https://github.com/psf/black # must be after ruff + rev: 24.8.0 + hooks: + - id: black - repo: https://github.com/streetsidesoftware/cspell-cli rev: v8.13.3 @@ -72,7 +76,7 @@ repos: name: Spell check with cspell - repo: https://github.com/jsh9/pydoclint - rev: "0.5.6" + rev: "0.5.8" hooks: - id: pydoclint # This allows automatic reduction of the baseline file when needed. @@ -80,7 +84,7 @@ repos: pass_filenames: false - repo: https://github.com/pycqa/pylint.git - rev: v3.2.7 + rev: v3.3.1 hooks: - id: pylint args: diff --git a/bindep.txt b/bindep.txt index 07358a9..afcdc5e 100644 --- a/bindep.txt +++ b/bindep.txt @@ -1 +1 @@ -python3-devel +python3-devel [platform:redhat] diff --git a/pyproject.toml b/pyproject.toml index 3d58299..a9a6470 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,9 @@ homepage = "https://github.com/ansible/ansible-dev-tools" repository = "https://github.com/ansible/ansible-dev-tools" [tool.black] +enable-unstable-feature = ["string_processing"] line-length = 100 +preview = true [tool.coverage.report] exclude_also = ["if TYPE_CHECKING:", "pragma: no cover"] @@ -336,6 +338,14 @@ line-length = 100 target-version = "py310" [tool.ruff.lint] +external = [ + "DOC" # pydoclint +] +ignore = [ + # incompatible with ruff formatter + "COM812", # missing-space-after-comma + "ISC001" # implicit-str-concat +] select = ["ALL"] [tool.ruff.lint.flake8-pytest-style] diff --git a/tests/conftest.py b/tests/conftest.py index a47e7e7..a0f89c5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,6 +16,7 @@ <...> Tracing '/**/src//__init__.py' """ + from __future__ import annotations import errno @@ -315,12 +316,7 @@ def _start_container() -> None: try: subprocess.run(cmd, check=True, capture_output=True, shell=True, text=True) except subprocess.CalledProcessError as exc: - err = ( - f"Failed to start container:\n" - f"cmd: {cmd}\n" - f"stdout: {exc.stdout}\n" - f"stderr: {exc.stderr}" - ) + err = f"Failed to start container:\ncmd: {cmd}\nstdout: {exc.stdout}\nstderr: {exc.stderr}" pytest.fail(err) # image is local, can't be pulled, use default @@ -419,17 +415,24 @@ def _start_server() -> None: env=os.environ, ) tries = 0 - max_tries = 10 + timeout = 2 + max_tries = 15 # GHA macos runner showed occasional failures with 10s + msg = "Could not start the server." while tries < max_tries: try: - res = requests.get("http://localhost:8000", timeout=1) + # timeout increased to 2s due to observed GHA macos failures + res = requests.get("http://localhost:8000", timeout=timeout) if res.status_code == requests.codes.get("not_found"): return - except requests.exceptions.ConnectionError: # noqa: PERF203 + except (requests.exceptions.ConnectionError, requests.RequestException): # noqa: PERF203 tries += 1 time.sleep(1) - - msg = "Could not start the server." + INFRASTRUCTURE.proc.terminate() + stdout, stderr = INFRASTRUCTURE.proc.communicate() + msg += ( + f"Could not start the server after {tries} tries with a timeout of {timeout} seconds each." + f" Server stdout:\n{stdout.decode()}\nServer stderr:\n{stderr.decode()}" + ) raise RuntimeError(msg) diff --git a/tests/integration/test_container.py b/tests/integration/test_container.py index 6e52b8d..9434e84 100644 --- a/tests/integration/test_container.py +++ b/tests/integration/test_container.py @@ -252,7 +252,7 @@ def test_nav_playbook( assert any(output in line for line in stdout) cmd = ( f"cd {tmp_path} &&" - f" ansible-navigator run site.yml" + " ansible-navigator run site.yml" f" --pp never --eei {infrastructure.navigator_ee}" ) stdout = container_tmux.send_and_wait(cmd=cmd, wait_for="Successful", timeout=10) diff --git a/tox.ini b/tox.ini index 4d757d6..4dde7b6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ [tox] requires = tox>=4.11.3 + tox-extra>=2.0.1 env_list = py deps