Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Use vanilla MathJax distribution, fall back to vendored scipy-mathjax if not available #20518

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,27 @@

htmlhelp_basename = 'scipy'

mathjax_path = "scipy-mathjax/MathJax.js?config=scipy-mathjax"

# Temporary workaround for https://github.com/executablebooks/MyST-NB/issues/590
# Check if we have access to the internet. If so, use MathJax via its CDN. If not
# we are most likely building locally without internet access and therefore we use
# the local vendored MathJax distribution present in the scipy-mathjax directory.

import socket # noqa: E402

INTERNET_AVAILABLE = False # assume no internet connection + use local MathJax

try:
# Attributed to https://stackoverflow.com/a/33117579/14001839
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit awkward because SciPy's license is not compatible with StackOverflow's.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍 we cannot use this code and need to come up with our own solution or use a MIT/BSD existing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comment, I had not noticed that – let me try to find another code snippet that is compatible with SciPy's license and revise this functionality with that.

Copy link
Contributor Author

@agriyakhetarpal agriyakhetarpal Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I added a much simpler check with the socket module in 4c18fef, which also resolves a ResourceWarning that I had missed earlier, by closing the socket. It works locally and should be compliant with SciPy's license. I'm not sure if pinging Google out of all is the best website, so we can switch to IANA-reserved example domains to test a connection with if that makes sense (https://www.iana.org/help/example-domains)

socket.setdefaulttimeout(1)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("8.8.8.8", 53))
socket.socket(socket.AF_INET, socket.SOCK_STREAM).close()
print("Internet connection available.")
INTERNET_AVAILABLE = True
except socket.error as err: # noqa: UP024
print("No internet connection available. Error:", err)
print("Using local MathJax distribution.")
mathjax_path = "scipy-mathjax/MathJax.js?config=scipy-mathjax"

# -----------------------------------------------------------------------------
# Intersphinx configuration
Expand Down
Loading