importing: make importlib_importer recognize .pyc cache (#13239)

Our importer was always parsing from source (which is considerably
slower) because the source size recorded in the .pyc file differed from
the size of the input file.

Override path_stats in the prepending importer to fool it into thinking
that the source size is the size *with* the prepended code.
This commit is contained in:
Todd Gamblin 2019-10-16 17:07:18 -07:00 committed by GitHub
parent ffe87ed49f
commit e65b7f8ebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,12 @@ def __init__(self, full_name, path, prepend=None):
super(PrependFileLoader, self).__init__(full_name, path)
self.prepend = prepend
def path_stats(self, path):
stats = super(PrependFileLoader, self).path_stats(path)
if self.prepend:
stats["size"] += len(self.prepend) + 1
return stats
def get_data(self, path):
data = super(PrependFileLoader, self).get_data(path)
if path != self.path or self.prepend is None: