mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-28 20:09:01 +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.
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import base64
|
|
import os
|
|
import random
|
|
import string
|
|
|
|
DEFAULT_GALAXY_MASTER_API_KEY = "TEST123"
|
|
DEFAULT_GALAXY_USER_API_KEY = None
|
|
|
|
DEFAULT_TEST_USER = "user@bx.psu.edu"
|
|
DEFAULT_ADMIN_TEST_USER = "test@bx.psu.edu"
|
|
DEFAULT_OTHER_USER = "otheruser@bx.psu.edu" # A second user for API testing.
|
|
|
|
TEST_USER = os.environ.get("GALAXY_TEST_USER_EMAIL", DEFAULT_TEST_USER)
|
|
ADMIN_TEST_USER = os.environ.get("GALAXY_TEST_ADMIN_USER_EMAIL", DEFAULT_ADMIN_TEST_USER)
|
|
OTHER_USER = os.environ.get("GALAXY_TEST_OTHER_USER_EMAIL", DEFAULT_OTHER_USER)
|
|
|
|
|
|
def get_admin_api_key() -> str:
|
|
"""Test admin API key to use for functional tests.
|
|
|
|
This key should be configured as a admin API key and should be able
|
|
to create additional users and keys.
|
|
"""
|
|
for key in ["GALAXY_CONFIG_MASTER_API_KEY", "GALAXY_CONFIG_OVERRIDE_MASTER_API_KEY"]:
|
|
value = os.environ.get(key, None)
|
|
if value:
|
|
return value
|
|
return DEFAULT_GALAXY_MASTER_API_KEY
|
|
|
|
|
|
def get_user_api_key() -> str | None:
|
|
"""Test user API key to use for functional tests.
|
|
|
|
If set, this should drive API based testing - if not set an admin API key will
|
|
be used to create a new user and API key for tests.
|
|
"""
|
|
return os.environ.get("GALAXY_TEST_USER_API_KEY", DEFAULT_GALAXY_USER_API_KEY)
|
|
|
|
|
|
def baseauth_headers(username: str, password: str) -> dict[str, str]:
|
|
unencoded_credentials = f"{username}:{password}"
|
|
authorization = base64.b64encode(unencoded_credentials.encode("utf-8")).decode("utf-8")
|
|
headers = {
|
|
"Authorization": authorization,
|
|
}
|
|
return headers
|
|
|
|
|
|
def random_name(prefix: str | None = None, suffix: str | None = None, len: int = 10) -> str:
|
|
return "{}{}{}".format(
|
|
prefix or "",
|
|
"".join(random.choice(string.ascii_lowercase + string.digits) for _ in range(len)),
|
|
suffix or "",
|
|
)
|