From 0e175a2d34779f936212be5cf940e957238691b3 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Fri, 23 Jan 2026 09:56:32 +0100 Subject: [PATCH] fix: resolve lint issues and remove obsolete Sphinx references - Fix lint issues in test_gthread.py: - Remove unused imports (queue, partial, http) - Move fcntl import to top level - Remove unused variable assignment - Replace unnecessary lambdas with method references - Add blank lines before nested function definitions (E306) - Update .github/workflows/lint.yml: - Replace Sphinx docs check with MkDocs settings generator - docs/source directory no longer exists after MkDocs migration - Update tox.ini: - Remove docs/source/*.rst lint (directory doesn't exist) - Add tests/test_gthread.py to lint targets --- .github/workflows/lint.yml | 12 ++++++------ tests/test_gthread.py | 22 +++++++++++++--------- tox.ini | 6 +----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 11f27c83..a51f41fb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -36,17 +36,17 @@ jobs: - name: Install Dependencies (non-toxic) if: ${{ ! matrix.toxenv }} run: | - python -m pip install sphinx - - name: "Update docs" + python -m pip install --upgrade pip + python -m pip install -e . + - name: "Check generated docs" if: ${{ ! matrix.toxenv }} run: | - # this will update docs/source/settings.rst - but will not create html output - (cd docs && sphinx-build -b "dummy" -d _build/doctrees source "_build/dummy") - git update-index --assume-unchanged docs/source/settings.rst + # Regenerate settings.md and check for uncommitted changes + python scripts/build_settings_doc.py if unclean=$(git status --untracked-files=no --porcelain) && [ -z "$unclean" ]; then echo "no uncommitted changes in working tree (as it should be)" else - echo "did you forget to run `make -C docs html`?" + echo "did you forget to run 'python scripts/build_settings_doc.py'?" echo "$unclean" exit 2 fi diff --git a/tests/test_gthread.py b/tests/test_gthread.py index 71101a8d..6e215977 100644 --- a/tests/test_gthread.py +++ b/tests/test_gthread.py @@ -5,19 +5,17 @@ """Tests for the gthread worker.""" import errno +import fcntl import os -import queue import selectors import threading import time from collections import deque from concurrent import futures -from functools import partial from unittest import mock import pytest -from gunicorn import http from gunicorn.config import Config from gunicorn.workers import gthread @@ -85,7 +83,7 @@ class TestTConn: sock = FakeSocket() sock.setblocking(True) - conn = gthread.TConn(cfg, sock, ('127.0.0.1', 12345), ('127.0.0.1', 8000)) + gthread.TConn(cfg, sock, ('127.0.0.1', 12345), ('127.0.0.1', 8000)) # TConn sets socket to non-blocking in __init__ assert sock.blocking is False @@ -147,7 +145,7 @@ class TestPollableMethodQueue: q.init() results = [] - q.defer(lambda x: results.append(x), 42) + q.defer(results.append, 42) # Simulate the selector reading from the pipe q.run_callbacks(None) @@ -162,7 +160,7 @@ class TestPollableMethodQueue: results = [] for i in range(5): - q.defer(lambda x: results.append(x), i) + q.defer(results.append, i) q.run_callbacks(None) @@ -220,9 +218,6 @@ class TestPollableMethodQueue: def test_queue_nonblocking_pipe(self): """Test that pipe is non-blocking (BSD compatibility).""" - import os - import fcntl - q = gthread.PollableMethodQueue() q.init() @@ -889,18 +884,22 @@ class TestWorkerLiveness: # Track notify calls notify_calls = [] original_notify = worker.notify + def tracking_notify(): notify_calls.append(time.monotonic()) original_notify() + worker.notify = tracking_notify # Mock poller.select to exit after first iteration call_count = [0] + def mock_select(timeout): call_count[0] += 1 if call_count[0] > 1: worker.alive = False return [] + worker.poller.select.side_effect = mock_select # Mock is_parent_alive to return True @@ -1010,6 +1009,7 @@ class TestSignalHandling: # Track iterations iterations = [0] + def mock_select(timeout): iterations[0] += 1 if iterations[0] == 1: @@ -1022,6 +1022,7 @@ class TestSignalHandling: # Connection finishes worker.nr_conns = 0 return [] + worker.poller.select.side_effect = mock_select worker.is_parent_alive = mock.Mock(return_value=True) @@ -1096,9 +1097,11 @@ class TestWorkerArbiterIntegration: worker.ppid = 99999999 # Invalid ppid iterations = [0] + def mock_select(timeout): iterations[0] += 1 return [] + worker.poller.select.side_effect = mock_select worker.run() @@ -1349,6 +1352,7 @@ class TestFinishBodySSL: # Create a mock message body that returns data then raises SSLWantReadError call_count = [0] + def mock_read(size): call_count[0] += 1 if call_count[0] <= 2: diff --git a/tox.ini b/tox.ini index 359cb90b..b328e7e2 100644 --- a/tox.ini +++ b/tox.ini @@ -33,6 +33,7 @@ commands = gunicorn \ tests/test_arbiter.py \ tests/test_config.py \ + tests/test_gthread.py \ tests/test_http.py \ tests/test_invalid_requests.py \ tests/test_logger.py \ @@ -48,16 +49,11 @@ deps = [testenv:docs-lint] no_package = true -allowlist_externals = - rst-lint - bash - grep deps = restructuredtext_lint pygments commands = rst-lint README.rst docs/README.rst - bash -c "(set -o pipefail; rst-lint --encoding utf-8 docs/source/*.rst | grep -v 'Unknown interpreted text role\|Unknown directive type'); test $? == 1" [testenv:pycodestyle] no_package = true