mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-02 19:52:14 +08:00
Drop Python 3.8 support in 5 Pulsar-compatible packages (job_metrics, tool_util, tool_util_models, util, objectstore) and run pyupgrade --py310-plus on their source code. - Bump requires-python from >=3.8 to >=3.10 in all 5 packages - Remove Python 3.8 and 3.9 classifiers - Remove ruff per-file-ignores for UP rules on these paths - Remove backports.zoneinfo conditional dependency - Remove pydyf<0.11 pin from conditional-requirements.txt - Update Makefile pyupgrade target (remove PY38_PYUPGRADE_PATHS) - Update CI workflow to test with Python 3.10 instead of 3.8 Clean up unused deprecated typing imports after pyupgrade Remove now-unused typing imports (Dict, List, Optional, Set, Tuple, Type, Union) that became dead after pyupgrade --py310-plus converted annotations to use built-in types and | syntax. Also run ruff check --fix --select=UP007,UP045 across the entire codebase to convert remaining Optional[X] -> X | None and Union[X, Y] -> X | Y patterns. Enable ruff UP007/UP045 for Python 3.10 union syntax Remove UP007 (Union[X,Y] -> X | Y) and UP045 (Optional[X] -> X | None) from the ruff ignore list and convert all type aliases across the codebase. These rules were deferred while Python 3.9 was supported; requires-python is now >=3.10. A custom script was used because neither ruff --fix nor pyupgrade --py310-plus converts Optional[X]/Union[X,Y] in type alias positions (e.g. X = Union[A, B]) — they only handle annotation positions (e.g. def f(x: Optional[int])). All 167 violations were module-level type aliases. A few edge cases were fixed manually: single-element Union[X,], typing.Union qualified refs, runtime Optional[type] calls, and Annotated[Optional[...]] pydantic fields. Fix UP007 autofix regression with string forward reference type aliases Commit fa6bd955a0 enabled ruff UP007/UP045 and auto-fixed module-level type aliases using Union with string forward references, producing invalid 'str | str' expressions. This was a known ruff bug (charliermarsh/ruff#826) that has since been fixed in later ruff versions, but this codebase was converted before the fix was in place. Revert to Union syntax and restore TYPE_CHECKING imports that ruff's TCH rule cleaned up as a side effect when it thought the forward references were unused.
83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
"""Test server infrastructure for running selenium tests locally."""
|
|
|
|
import http.server
|
|
import socketserver
|
|
import threading
|
|
from pathlib import Path
|
|
|
|
|
|
class TestHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|
"""Custom request handler for serving test HTML files."""
|
|
|
|
def __init__(self, *args, directory: str | None = None, **kwargs):
|
|
"""Initialize handler with custom directory."""
|
|
super().__init__(*args, directory=directory, **kwargs)
|
|
|
|
def log_message(self, format: str, *args):
|
|
"""Suppress log messages during tests."""
|
|
pass
|
|
|
|
def end_headers(self):
|
|
"""Override to add test cookies to all responses."""
|
|
self.send_header("Set-Cookie", "test_cookie=test_value; Path=/")
|
|
super().end_headers()
|
|
|
|
|
|
class TestHTTPServer:
|
|
"""Simple HTTP server for serving test HTML pages."""
|
|
|
|
def __init__(self, port: int = 0, directory: Path | None = None):
|
|
"""
|
|
Initialize test HTTP server.
|
|
|
|
Args:
|
|
port: Port to bind to (0 for random available port)
|
|
directory: Directory to serve files from
|
|
"""
|
|
self.port = port
|
|
self.directory = directory or Path(__file__).parent / "fixtures"
|
|
self.server: socketserver.TCPServer | None = None
|
|
self.thread: threading.Thread | None = None
|
|
|
|
def start(self):
|
|
"""Start the HTTP server in a background thread."""
|
|
|
|
def handler(*args, **kwargs):
|
|
return TestHTTPRequestHandler(*args, directory=str(self.directory), **kwargs)
|
|
|
|
self.server = socketserver.TCPServer(("localhost", self.port), handler)
|
|
self.port = self.server.server_address[1] # Get actual port if 0 was specified
|
|
|
|
self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
|
|
self.thread.start()
|
|
|
|
def stop(self):
|
|
"""Stop the HTTP server."""
|
|
if self.server:
|
|
self.server.shutdown()
|
|
self.server.server_close()
|
|
if self.thread:
|
|
self.thread.join(timeout=5)
|
|
|
|
def get_url(self, path: str = "") -> str:
|
|
"""
|
|
Get full URL for a given path.
|
|
|
|
Args:
|
|
path: Path relative to served directory
|
|
|
|
Returns:
|
|
Full URL including protocol, host, port, and path
|
|
"""
|
|
path = path.lstrip("/")
|
|
return f"http://localhost:{self.port}/{path}"
|
|
|
|
def __enter__(self):
|
|
"""Context manager entry."""
|
|
self.start()
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
"""Context manager exit."""
|
|
self.stop()
|