Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge #31420
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Sep 9, 2021
2 parents f9154a9 + af6642f commit 2ba4c43
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
61 changes: 3 additions & 58 deletions src/sage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
__all__ = ['all']
# Do not add anything to this file.
# It will be removed soon in order to turn 'sage' into a native namespace package.
# See https://trac.sagemath.org/ticket/29705

# Set sage.__version__ to the current version number. This is analogous
# to many other Python packages.
from sage.version import version as __version__

import sys
# Make sure that the correct zlib library is loaded. This is needed
# to prevent the system zlib to be loaded instead of the Sage one.
# See https://trac.sagemath.org/ticket/23122
import zlib

# IPython calls this when starting up
def load_ipython_extension(*args):
Expand Down Expand Up @@ -44,51 +37,3 @@ def isfunction(obj):
deprecation(32479, "sage.isfunction is deprecated; use callable or sage.misc.sageinspect.is_function_or_cython_function instead")
from sage.misc.sageinspect import is_function_or_cython_function
return is_function_or_cython_function(obj)


# Monkey-patch ExtensionFileLoader to allow IPython to find the sources
# of Cython files. See https://trac.sagemath.org/ticket/24681
try:
from importlib.machinery import ExtensionFileLoader
except ImportError:
pass # Python 2
else:
del ExtensionFileLoader.get_source


# Work around a Cygwin-specific bug caused by sqlite3; see
# https://trac.sagemath.org/ticket/30157 and the docstring for
# fix_for_ticket_30157
# Here we monkey-patch the sqlite3 module to ensure the fix is
# applied the very first time a connection is made to a sqlite3
# database
if sys.platform == 'cygwin':
def patch_sqlite3():
try:
from sage.misc.sage_ostools import fix_for_ticket_30157
except ImportError:
# The module might not have been re-built yet; don't worry about it
# then
return

import sqlite3
import functools
orig_sqlite3_connect = sqlite3.connect

@functools.wraps(orig_sqlite3_connect)
def connect(*args, **kwargs):
if fix_for_ticket_30157():
raise RuntimeError(
'patch for Trac ticket #30157 failed; please report this '
'bug to https://trac.sagemath.org')

# Undo the monkey-patch
try:
return orig_sqlite3_connect(*args, **kwargs)
finally:
sqlite3.connect = orig_sqlite3_connect

sqlite3.connect = connect

patch_sqlite3()
del patch_sqlite3
55 changes: 55 additions & 0 deletions src/sage/cpython/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# sage.cpython is an ordinary package, not a namespace package.

# This package is imported very early, which is why workarounds/monkey-patching
# are done in this file.

# Make sure that the correct zlib library is loaded. This is needed
# to prevent the system zlib to be loaded instead of the Sage one.
# See https://trac.sagemath.org/ticket/23122
import zlib as _zlib
del _zlib

# Monkey-patch ExtensionFileLoader to allow IPython to find the sources
# of Cython files. See https://trac.sagemath.org/ticket/24681
from importlib.machinery import ExtensionFileLoader as _ExtensionFileLoader
del _ExtensionFileLoader.get_source
del _ExtensionFileLoader

# Work around a Cygwin-specific bug caused by sqlite3; see
# https://trac.sagemath.org/ticket/30157 and the docstring for
# fix_for_ticket_30157
# Here we monkey-patch the sqlite3 module to ensure the fix is
# applied the very first time a connection is made to a sqlite3
# database
import sys as _sys
if _sys.platform == 'cygwin':
def _patch_sqlite3():
try:
from sage.misc.sage_ostools import fix_for_ticket_30157
except ImportError:
# The module might not have been re-built yet; don't worry about it
# then
return

import sqlite3
import functools
orig_sqlite3_connect = sqlite3.connect

@functools.wraps(orig_sqlite3_connect)
def connect(*args, **kwargs):
if fix_for_ticket_30157():
raise RuntimeError(
'patch for Trac ticket #30157 failed; please report this '
'bug to https://trac.sagemath.org')

# Undo the monkey-patch
try:
return orig_sqlite3_connect(*args, **kwargs)
finally:
sqlite3.connect = orig_sqlite3_connect

sqlite3.connect = connect

_patch_sqlite3()
del _patch_sqlite3
del _sys

0 comments on commit 2ba4c43

Please sign in to comment.