From 2a41350596a81892475edfc4a9e00d8f99a4af75 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 23 Oct 2024 11:57:55 +0100 Subject: [PATCH] Use fissix to replace lib2to3 under Python >=3.13 Add entries to `sys.modules` so that `future`/`past` can find lib2to3 modules. --- .../dependencies/pinned-requirements.txt | 1 + lib/galaxy/util/template.py | 18 ++++++++++++++++-- packages/util/setup.cfg | 1 + pyproject.toml | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/dependencies/pinned-requirements.txt b/lib/galaxy/dependencies/pinned-requirements.txt index 55078397df8c..593e014fa0b2 100644 --- a/lib/galaxy/dependencies/pinned-requirements.txt +++ b/lib/galaxy/dependencies/pinned-requirements.txt @@ -67,6 +67,7 @@ email-validator==2.2.0 ; python_version >= "3.8" and python_version < "3.14" exceptiongroup==1.2.2 ; python_version >= "3.8" and python_version < "3.11" fastapi-slim==0.115.2 ; python_version >= "3.8" and python_version < "3.14" filelock==3.16.1 ; python_version >= "3.8" and python_version < "3.14" +fissix==24.4.24 ; python_version >= "3.13" and python_version < "3.14" frozenlist==1.4.1 ; python_version >= "3.8" and python_version < "3.14" fs==2.4.16 ; python_version >= "3.8" and python_version < "3.14" fsspec==2024.9.0 ; python_version >= "3.8" and python_version < "3.14" diff --git a/lib/galaxy/util/template.py b/lib/galaxy/util/template.py index 9b7f7965592e..d7872691cb60 100644 --- a/lib/galaxy/util/template.py +++ b/lib/galaxy/util/template.py @@ -1,18 +1,32 @@ """Entry point for the usage of Cheetah templating within Galaxy.""" +import sys import traceback -from lib2to3.refactor import RefactoringTool from Cheetah.Compiler import Compiler from Cheetah.NameMapper import NotFound from Cheetah.Parser import ParseError from Cheetah.Template import Template from packaging.version import Version -from past.translation import myfixes from galaxy.util.tree_dict import TreeDict from . import unicodify +if sys.version_info >= (3, 13): + import fissix + from fissix import ( + fixes as fissix_fixes, + pgen2 as fissix_pgen2, + refactor as fissix_refactor, + ) + sys.modules["lib2to3"] = fissix + sys.modules["lib2to3.fixes"] = fissix_fixes + sys.modules["lib2to3.pgen2"] = fissix_pgen2 + sys.modules["lib2to3.refactor"] = fissix_refactor + +from lib2to3.refactor import RefactoringTool +from past.translation import myfixes + # Skip libpasteurize fixers, which make sure code is py2 and py3 compatible. # This is not needed, we only translate code on py3. myfixes = [f for f in myfixes if not f.startswith("libpasteurize")] diff --git a/packages/util/setup.cfg b/packages/util/setup.cfg index ad9dff07b28d..7865c54eb421 100644 --- a/packages/util/setup.cfg +++ b/packages/util/setup.cfg @@ -54,6 +54,7 @@ jstree = dictobj template = CT3 + fissix;python>=3.13 future>=1.0.0 config_template = Jinja2 diff --git a/pyproject.toml b/pyproject.toml index c83ef32abc89..ac2cc7b90eeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,7 @@ docutils = "!=0.17, !=0.17.1" dparse = "*" edam-ontology = "*" fastapi-slim = ">=0.111.0" +fissix = { version = "*", python = ">=3.13" } fs = "*" future = ">=1.0.0" # Python 3.12 support graphene = "*"