mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-28 11:32:24 +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.
97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
from pydantic import ValidationError
|
|
|
|
from galaxy.tool_util_models import Tests
|
|
from galaxy.tool_util_models.test_job import Job
|
|
from galaxy.util import galaxy_directory
|
|
from galaxy.util.unittest_utils import skip_unless_environ
|
|
|
|
TEST_WORKFLOW_DIRECTORY = os.path.join(galaxy_directory(), "lib", "galaxy_test", "workflow")
|
|
IWC_WORKFLOWS_USING_UNVERIFIED_SYNTAX: list[str] = []
|
|
|
|
# replacement_parameters_legacy.gxwf-tests.yml is a deliberate regression test
|
|
# for Planemo-era implicit replacement_parameters: {...} dicts embedded in
|
|
# job:. That key is popped out by WorkflowPopulator.run_workflow before
|
|
# staging, so the runtime accepts it but it is not canonical workflow-test
|
|
# input syntax and the strict Job schema does not model it.
|
|
WORKFLOW_TESTS_SKIP_STRICT_VALIDATION: list[str] = [
|
|
"replacement_parameters_legacy.gxwf-tests.yml",
|
|
]
|
|
|
|
TEST_JOB_FIXTURES_DIR = Path(__file__).parent / "test_data" / "test_job_fixtures"
|
|
|
|
|
|
def _load_fixture(name: str):
|
|
with open(TEST_JOB_FIXTURES_DIR / name) as f:
|
|
return yaml.safe_load(f)
|
|
|
|
|
|
JOB_POSITIVE_FIXTURES = [
|
|
"file_path.yml",
|
|
"file_location.yml",
|
|
"file_composite.yml",
|
|
"file_contents.yml",
|
|
"file_with_tags_and_dbkey.yml",
|
|
"collection_list.yml",
|
|
"collection_paired.yml",
|
|
"collection_nested.yml",
|
|
"directory.yml",
|
|
"scalars.yml",
|
|
"list_of_files.yml",
|
|
"list_of_scalars.yml",
|
|
]
|
|
|
|
JOB_NEGATIVE_FIXTURES = [
|
|
"neg_legacy_type_file.yml",
|
|
"neg_legacy_type_raw.yml",
|
|
"neg_elements_without_class.yml",
|
|
"neg_file_no_path_or_location.yml",
|
|
"neg_unknown_field.yml",
|
|
"neg_bad_collection_type.yml",
|
|
"neg_top_level_not_dict.yml",
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("fixture", JOB_POSITIVE_FIXTURES)
|
|
def test_job_positive_fixtures(fixture: str) -> None:
|
|
Job.model_validate(_load_fixture(fixture))
|
|
|
|
|
|
@pytest.mark.parametrize("fixture", JOB_NEGATIVE_FIXTURES)
|
|
def test_job_negative_fixtures(fixture: str) -> None:
|
|
with pytest.raises(ValidationError):
|
|
Job.model_validate(_load_fixture(fixture))
|
|
|
|
|
|
def test_validate_workflow_tests():
|
|
path = Path(TEST_WORKFLOW_DIRECTORY)
|
|
test_files = path.glob("*.gxwf-tests.yml")
|
|
for test_file in test_files:
|
|
if test_file.name in WORKFLOW_TESTS_SKIP_STRICT_VALIDATION:
|
|
continue
|
|
with open(test_file) as f:
|
|
json = yaml.safe_load(f)
|
|
Tests.model_validate(json)
|
|
|
|
|
|
@skip_unless_environ("GALAXY_TEST_IWC_DIRECTORY")
|
|
def test_iwc_directory():
|
|
path = Path(os.environ["GALAXY_TEST_IWC_DIRECTORY"])
|
|
test_files = path.glob("workflows/**/*-test*.yml")
|
|
|
|
for test_file in test_files:
|
|
print(test_file)
|
|
skip_file = False
|
|
for unverified in IWC_WORKFLOWS_USING_UNVERIFIED_SYNTAX:
|
|
if str(test_file).endswith(unverified):
|
|
skip_file = True
|
|
if skip_file:
|
|
continue
|
|
with open(test_file) as f:
|
|
json = yaml.safe_load(f)
|
|
Tests.model_validate(json)
|