mirror of
https://github.com/facebook/proxygen.git
synced 2025-08-05 19:55:47 +03:00
DebugWipeFinder fixes for 3.12
Summary: X-link: https://github.com/facebookincubator/zstrong/pull/662 find_module has been deprecated for some time. Instead use find_spec Reviewed By: itamaro Differential Revision: D52495680 fbshipit-source-id: 9b827a783af2d858816a8d197530874f680502f3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
09e1ca006b
commit
0dc2acaa7d
@@ -22,11 +22,8 @@ import time
|
||||
import traceback
|
||||
import unittest
|
||||
import warnings
|
||||
from importlib.machinery import PathFinder
|
||||
|
||||
# Hide warning about importing "imp"; remove once python2 is gone.
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||
import imp
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
@@ -82,7 +79,7 @@ class PathMatcher(object):
|
||||
return not self.omit(path)
|
||||
|
||||
|
||||
class DebugWipeFinder(object):
|
||||
class DebugWipeFinder(PathFinder):
|
||||
"""
|
||||
PEP 302 finder that uses a DebugWipeLoader for all files which do not need
|
||||
coverage
|
||||
@@ -91,28 +88,15 @@ class DebugWipeFinder(object):
|
||||
def __init__(self, matcher):
|
||||
self.matcher = matcher
|
||||
|
||||
def find_module(self, fullname, path=None):
|
||||
_, _, basename = fullname.rpartition(".")
|
||||
try:
|
||||
fd, pypath, (_, _, kind) = imp.find_module(basename, path)
|
||||
except Exception:
|
||||
# Finding without hooks using the imp module failed. One reason
|
||||
# could be that there is a zip file on sys.path. The imp module
|
||||
# does not support loading from there. Leave finding this module to
|
||||
# the others finders in sys.meta_path.
|
||||
def find_spec(self, fullname, path=None, target=None):
|
||||
spec = super().find_spec(fullname, path=path, target=target)
|
||||
if spec is None or spec.origin is None:
|
||||
return None
|
||||
|
||||
if hasattr(fd, "close"):
|
||||
fd.close()
|
||||
if kind != imp.PY_SOURCE:
|
||||
if not spec.origin.endswith(".py"):
|
||||
return None
|
||||
if self.matcher.include(pypath):
|
||||
if self.matcher.include(spec.origin):
|
||||
return None
|
||||
|
||||
"""
|
||||
This is defined to match CPython's PyVarObject struct
|
||||
"""
|
||||
|
||||
class PyVarObject(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("ob_refcnt", ctypes.c_long),
|
||||
@@ -126,7 +110,7 @@ class DebugWipeFinder(object):
|
||||
"""
|
||||
|
||||
def get_code(self, fullname):
|
||||
code = super(DebugWipeLoader, self).get_code(fullname)
|
||||
code = super().get_code(fullname)
|
||||
if code:
|
||||
# Ideally we'd do
|
||||
# code.co_lnotab = b''
|
||||
@@ -136,7 +120,8 @@ class DebugWipeFinder(object):
|
||||
code_impl.ob_size = 0
|
||||
return code
|
||||
|
||||
return DebugWipeLoader(fullname, pypath)
|
||||
spec.loader = DebugWipeLoader(fullname, spec.origin)
|
||||
return spec
|
||||
|
||||
|
||||
def optimize_for_coverage(cov, include_patterns, omit_patterns):
|
||||
|
Reference in New Issue
Block a user