Description: Remove astunparse package
 python3-astunparse is not going to support Python 3.13 and is not needed for
 modern code and so we want to remove it from Debian
Author: Emmanuel Arias <eamanu@debiang.org>
Bug-Debian: https://bugs.debian.org/1086772
Forwarded: <URL|no|not-needed, useless if you have a Bug field, optional>
Last-Update: 2024-12-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/psychopy/experiment/py2js_transpiler.py
+++ b/psychopy/experiment/py2js_transpiler.py
@@ -14,9 +14,6 @@
 except ImportError:
     pass  # metapensiero not installed
 
-import astunparse
-
-
 namesJS = {
     'sin': 'Math.sin',
     'cos': 'Math.cos',
@@ -573,7 +570,7 @@
 
     # turn the transformed AST into code:
     try:
-        transformedPsychoPyCode = astunparse.unparse(transformedAstNode)
+        transformedPsychoPyCode = ast.unparse(transformedAstNode)
     # print('>>> transformed PsychoPy code:\n' + transformedPsychoPyCode)
     except Exception as error:
         raise Exception('unable to turn the transformed abstract syntax tree back into code: ' + str(error))
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -71,7 +71,6 @@
     "cryptography",  # for sshkeys
     # psychoJS conversions
     "javascripthon>=0.12",
-    "astunparse",
     "esprima",
     "jedi >= 0.16",
     # hardware
--- a/setupApp.py
+++ b/setupApp.py
@@ -92,7 +92,7 @@
             'json_tricks',  # allows saving arrays/dates in json
             'git', 'gitlab',
             'msgpack', 'yaml', 'gevent',  # for ioHub
-            'astunparse', 'esprima',  # for translating/adapting py/JS
+            'esprima',  # for translating/adapting py/JS
             'metapensiero.pj', 'dukpy', 
             'jedi', 'parso',
             'bidi', 'arabic_reshaper', 'charset_normalizer', # for (natural) language conversions
--- a/psychopy/experiment/py2js.py
+++ b/psychopy/experiment/py2js.py
@@ -12,7 +12,6 @@
 import ast
 from pathlib import Path
 
-import astunparse
 import esprima
 from os import path
 from psychopy import logging
@@ -33,19 +32,32 @@
         return ast.List(node.elts, node.ctx)
 
 
-class Unparser(astunparse.Unparser):
-    """astunparser had buried the future_imports option underneath its init()
-    so we need to override that method and change it."""
+class Unparser:
+    """
+    Class mimic the astunparse.Unparser behaviour, also it can modify the 'future_imports'.
+    """
 
     def __init__(self, tree, file):
-        """Unparser(tree, file=sys.stdout) -> None.
-         Print the source for tree to file."""
         self.f = file
         self.future_imports = ['unicode_literals']
         self._indent = 0
-        self.dispatch(tree)
+        transformed_tree = self.add_future_imports(tree)
+        source_code = ast.unparse(transformed_tree)
+        self.f.write(source_code)
         self.f.flush()
 
+    def add_future_imports(self, tree):
+        if not self.future_imports:
+            return tree
+
+        future_imports = [
+            ast.ImportFrom(module="__future__", names=[ast.alias(name=name, asname=None)], level=0)
+            for name in self.future_imports
+        ]
+
+        tree.body = future_imports + tree.body
+        return tree
+
 
 def unparse(tree):
     v = StringIO()
