Remove linecache.updatecache monkeypatch.

That no longer needed after changes to `renpy.python.create_store`.
This commit is contained in:
Andy_kl
2025-02-13 17:59:11 +04:00
parent ef5777d6b6
commit 5bf35c8c4f
-58
View File
@@ -20,17 +20,11 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import division, absolute_import, with_statement, print_function, unicode_literals # type: ignore
from renpy.compat import PY2, basestring, bchr, bord, chr, open, pystr, range, round, str, tobytes, unicode # *
from typing import Any
import codecs
import re
import sys
import os
import time
import linecache
import contextlib
import renpy
@@ -38,58 +32,6 @@ import renpy
from renpy.lexersupport import match_logical_word
_python_updatecache = linecache.updatecache
def _updatecache(filename: str, module_globals: dict[str, Any] | None = None) -> list[str]:
"""
Monkeypatch internal linecache.updatecache to work around RenPy python code
being in different files even in the same namespace. Assume filename is one
of '_ren.py', '.rpy' or '.rpym'.
This is needed because a lot of Python modules (namely traceback) assume
that the compiled python code is always comes from the python file and uses
linecache to get the source code, which tries to use PEP302 loader, which
for RenPy python code points to renpy.minstore.
"""
if filename.endswith(("_ren.py", ".rpy", ".rpym")):
# Assume filename also relative to basedir or renpy_base.
full_fn = renpy.lexer.unelide_filename(filename)
# If we can't find absolute path that way, assume we are
# in build, so we can't show source.
if not (os.path.isabs(full_fn) and os.path.exists(full_fn)):
linecache.cache.pop(filename, None)
return []
try:
with open(full_fn, "rb") as f:
data = f.read().decode("utf-8", "python_strict")
if full_fn.endswith("_ren.py"):
data = ren_py_to_rpy(data, None)
data += "\n\n"
lines = data.split("\n")
if lines and lines[0].startswith("\ufeff"):
lines[0] = lines[0][1:]
lines = [line.removesuffix("\r") + "\n" for line in lines]
stat = os.stat(full_fn)
linecache.cache[filename] = stat.st_size, stat.st_mtime, lines, full_fn
return lines
except Exception:
return []
return _python_updatecache(filename, module_globals)
linecache.updatecache = _updatecache
class ParseError(SyntaxError):
"""
Special exception type for syntax errors in Ren'Py.