Skip to content

Commit

Permalink
Use fissix to replace lib2to3 under Python >=3.13
Browse files Browse the repository at this point in the history
Add entries to `sys.modules` so that `future`/`past` can find
lib2to3 modules.
  • Loading branch information
nsoranzo committed Oct 31, 2024
1 parent ac480e7 commit febd6f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/galaxy/dependencies/pinned-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ email-validator==2.2.0
exceptiongroup==1.2.2 ; python_full_version < '3.11'
fastapi-slim==0.115.4
filelock==3.16.1
fissix==24.4.24 ; python_full_version >= '3.13'
frozenlist==1.5.0
fs==2.4.16
fsspec==2024.10.0
Expand Down
20 changes: 18 additions & 2 deletions lib/galaxy/util/template.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
"""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")]
Expand Down
1 change: 1 addition & 0 deletions packages/util/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jstree =
dictobj
template =
CT3>=3.3.3
fissix;python_version>='3.13'
future>=1.0.0
config_template =
Jinja2
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies = [
"dparse",
"edam-ontology",
"fastapi-slim>=0.111.0",
"fissix ; python_version>='3.13'",
"fs",
"future>=1.0.0", # Python 3.12 support
"graphene",
Expand Down

0 comments on commit febd6f9

Please sign in to comment.