This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |