From 2cada2c6899fd7bf5f44e22f93e51d896bc8c257 Mon Sep 17 00:00:00 2001
From: Matthias Koeppe <mkoeppe@math.ucdavis.edu>
Date: Sat, 18 Feb 2023 22:17:35 -0800
Subject: [PATCH] sage.all: Import from sage.all__sagemath_repl, move
 filterwarnings there

---
 src/sage/all.py                | 79 +---------------------------------
 src/sage/all__sagemath_repl.py | 75 +++++++++++++++++++++++++++++++-
 2 files changed, 75 insertions(+), 79 deletions(-)

diff --git a/src/sage/all.py b/src/sage/all.py
index 93588df1b93..288039a72f4 100644
--- a/src/sage/all.py
+++ b/src/sage/all.py
@@ -54,87 +54,12 @@
 # ****************************************************************************
 
 import os
-import sys
 import operator
 import math
 
-############ setup warning filters before importing Sage stuff ####
-import warnings
-
-__with_pydebug = hasattr(sys, 'gettotalrefcount')   # This is a Python debug build (--with-pydebug)
-if __with_pydebug:
-    # a debug build does not install the default warning filters. Sadly, this breaks doctests so we
-    # have to re-add them:
-    warnings.filterwarnings('ignore', category=PendingDeprecationWarning)
-    warnings.filterwarnings('ignore', category=ImportWarning)
-    warnings.filterwarnings('ignore', category=ResourceWarning)
-else:
-    deprecationWarning = ('ignore', None, DeprecationWarning, None, 0)
-    if deprecationWarning in warnings.filters:
-        warnings.filters.remove(deprecationWarning)
-
-# Ignore all deprecations from IPython etc.
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-    module='(IPython|ipykernel|jupyter_client|jupyter_core|nbformat|notebook|ipywidgets|storemagic|jedi)')
-
-# scipy 1.18 introduced reprecation warnings on a number of things they are moving to
-# numpy, e.g. DeprecationWarning: scipy.array is deprecated
-#             and will be removed in SciPy 2.0.0, use numpy.array instead
-# This affects networkx 2.2 up and including 2.4 (cf. :trac:29766)
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-    module='(scipy|networkx)')
-
-# However, be sure to keep OUR deprecation warnings
-warnings.filterwarnings('default', category=DeprecationWarning,
-    message=r'[\s\S]*See https?://trac\.sagemath\.org/[0-9]* for details.')
-
-# Ignore Python 3.9 deprecation warnings
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-    module='ast')
-
-# Ignore packaging 20.5 deprecation warnings
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-    module='(.*[.]_vendor[.])?packaging')
-
-# Ignore numpy warnings triggered by pythran
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        module='pythran')
-
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        message='The distutils(.sysconfig module| package) is deprecated',
-                        module='Cython|distutils|numpy|sage.env|sage.features')
-
-# triggered by cython 0.29.32
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        message="'cgi' is deprecated and slated for removal in Python 3.13",
-                        module='Cython')
-
-# triggered by pyparsing 2.4.7
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        message="module 'sre_constants' is deprecated",
-                        module='pyparsing')
-
-# importlib.resources.path and ...read_binary are deprecated in python 3.11,
-# but the replacement importlib.resources.files needs python 3.9
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        message=r'(path|read_binary) is deprecated\. Use files\(\) instead\.',
-                        module='sage.repl.rich_output.output_(graphics|graphics3d|video)')
-
-# triggered by sphinx
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        message="'imghdr' is deprecated and slated for removal in Python 3.13",
-                        module='sphinx.util.images')
-
-# triggered by docutils 0.19 on Python 3.11
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        message=r"Use setlocale\(\), getencoding\(\) and getlocale\(\) instead",
-                        module='docutils.io')
-
 ################ end setup warnings ###############################
 
-
-from .all__sagemath_environment import *
-
+from .all__sagemath_repl import *  # includes .all__sagemath_objects, .all__sagemath_environment
 
 ###################################################################
 
@@ -149,13 +74,11 @@
 
 from sage.misc.all       import *         # takes a while
 from sage.typeset.all    import *
-from sage.repl.all       import *
 
 from sage.misc.sh import sh
 
 from sage.libs.all       import *
 from sage.data_structures.all import *
-from sage.doctest.all    import *
 
 from sage.structure.all  import *
 from sage.rings.all      import *
diff --git a/src/sage/all__sagemath_repl.py b/src/sage/all__sagemath_repl.py
index c9508c15bbe..95dc2a15a80 100644
--- a/src/sage/all__sagemath_repl.py
+++ b/src/sage/all__sagemath_repl.py
@@ -1,7 +1,80 @@
+############ setup warning filters before importing Sage stuff ####
+import sys
+import warnings
+
+__with_pydebug = hasattr(sys, 'gettotalrefcount')   # This is a Python debug build (--with-pydebug)
+if __with_pydebug:
+    # a debug build does not install the default warning filters. Sadly, this breaks doctests so we
+    # have to re-add them:
+    warnings.filterwarnings('ignore', category=PendingDeprecationWarning)
+    warnings.filterwarnings('ignore', category=ImportWarning)
+    warnings.filterwarnings('ignore', category=ResourceWarning)
+else:
+    deprecationWarning = ('ignore', None, DeprecationWarning, None, 0)
+    if deprecationWarning in warnings.filters:
+        warnings.filters.remove(deprecationWarning)
+
+# Ignore all deprecations from IPython etc.
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+    module='(IPython|ipykernel|jupyter_client|jupyter_core|nbformat|notebook|ipywidgets|storemagic|jedi)')
+
+# scipy 1.18 introduced reprecation warnings on a number of things they are moving to
+# numpy, e.g. DeprecationWarning: scipy.array is deprecated
+#             and will be removed in SciPy 2.0.0, use numpy.array instead
+# This affects networkx 2.2 up and including 2.4 (cf. :trac:29766)
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+    module='(scipy|networkx)')
+
+# However, be sure to keep OUR deprecation warnings
+warnings.filterwarnings('default', category=DeprecationWarning,
+    message=r'[\s\S]*See https?://trac\.sagemath\.org/[0-9]* for details.')
+
+# Ignore Python 3.9 deprecation warnings
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+    module='ast')
+
+# Ignore packaging 20.5 deprecation warnings
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+    module='(.*[.]_vendor[.])?packaging')
+
+# Ignore numpy warnings triggered by pythran
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        module='pythran')
+
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        message='The distutils(.sysconfig module| package) is deprecated',
+                        module='Cython|distutils|numpy|sage.env|sage.features')
+
+# triggered by cython 0.29.32
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        message="'cgi' is deprecated and slated for removal in Python 3.13",
+                        module='Cython')
+
+# triggered by pyparsing 2.4.7
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        message="module 'sre_constants' is deprecated",
+                        module='pyparsing')
+
+# importlib.resources.path and ...read_binary are deprecated in python 3.11,
+# but the replacement importlib.resources.files needs python 3.9
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        message=r'(path|read_binary) is deprecated\. Use files\(\) instead\.',
+                        module='sage.repl.rich_output.output_(graphics|graphics3d|video)')
+
+# triggered by sphinx
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        message="'imghdr' is deprecated and slated for removal in Python 3.13",
+                        module='sphinx.util.images')
+
+# triggered by docutils 0.19 on Python 3.11
+warnings.filterwarnings('ignore', category=DeprecationWarning,
+                        message=r"Use setlocale\(\), getencoding\(\) and getlocale\(\) instead",
+                        module='docutils.io')
+
+
 from .all__sagemath_objects import *
 from .all__sagemath_environment import *
 
-# FIXME: all.py should import from here and remove these imports.
 from sage.doctest.all    import *
 from sage.repl.all       import *
 from sage.misc.all__sagemath_repl import *