Files
paperbenni bec3d3ad9c Drop support for Python 3.8
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.
2026-06-25 15:12:05 +01:00

64 lines
1.9 KiB
Python

import os
import tempfile
import pytest
try:
import psycopg
except ImportError:
psycopg = None # type: ignore[assignment, unused-ignore]
from galaxy.app_unittest_utils import galaxy_mock
def create_base_test(connection, amqp_type: str, amqp_connection: str | None = None):
app = galaxy_mock.MockApp(database_connection=connection)
app.config.database_connection = connection
app.config.amqp_internal_connection = amqp_connection or f"sqlalchemy+{app.config.database_connection}"
app.amqp_type = amqp_type
return app
@pytest.fixture()
def sqlite_connection(request):
with tempfile.NamedTemporaryFile() as temp:
yield f"sqlite:////{temp.name}"
@pytest.fixture()
def sqlite_rabbitmq_app(sqlite_connection):
def create_app():
amqp_connection = os.environ.get("GALAXY_TEST_AMQP_INTERNAL_CONNECTION")
return create_base_test(sqlite_connection, amqp_type="rabbitmq", amqp_connection=amqp_connection)
return create_app
@pytest.fixture()
def sqlite_app(sqlite_connection):
def create_app():
return create_base_test(sqlite_connection, amqp_type="sqlite")
return create_app
@pytest.fixture()
def postgres_app(postgresql_proc):
connection = f"postgresql+psycopg://{postgresql_proc.user}@{postgresql_proc.host}:{postgresql_proc.port}/"
def create_app():
return create_base_test(connection, amqp_type="postgres")
return create_app
@pytest.fixture(params=["postgres_app", "sqlite_app", "sqlite_rabbitmq_app"])
def database_app(request):
if request.param == "postgres_app":
if not psycopg:
pytest.skip("psycopg must be installed for postgresql_proc fixture")
if request.param == "sqlite_rabbitmq_app":
if not os.environ.get("GALAXY_TEST_AMQP_INTERNAL_CONNECTION"):
pytest.skip("rabbitmq tests will be skipped if GALAXY_TEST_AMQP_INTERNAL_CONNECTION env var is unset")
return request.getfixturevalue(request.param)