Skip to content

Commit

Permalink
gh-35160: Move filterwarnings calls from sage.all to `sage.all__s…
Browse files Browse the repository at this point in the history
…agemath_repl`

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
### 📚 Description
We can use `sage -t` to test with a top-level environment other than
`sage.all` using the parameter
`--environment=sage.all__sagemath_categories` etc.
<!-- Describe your changes here in detail -->
To make sure that the warnings configuration is also set up in this
case, we move the `filterwarnings` calls from `sage.all` to
`sage.all__sagemath_repl`. (The doctester loads `sage.repl`.)
<!-- Why is this change required? What problem does it solve? -->
<!-- If it resolves an open issue, please link to the issue here. For
example "Closes #1337" -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [ ] I have linked an issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies
<!-- List all open pull requests that this PR logically depends on -->
<!--
- #xyz: short description why this is a dependency
- #abc: ...
-->
    
URL: #35160
Reported by: Matthias Köppe
Reviewer(s): Gonzalo Tornaría
  • Loading branch information
Release Manager committed Mar 24, 2023
2 parents 6d14679 + a2c64dc commit 366d0cf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 79 deletions.
79 changes: 1 addition & 78 deletions src/sage/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

###################################################################

Expand All @@ -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 *
Expand Down
75 changes: 74 additions & 1 deletion src/sage/all__sagemath_repl.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down

0 comments on commit 366d0cf

Please sign in to comment.