MCPcopy Index your code
hub / github.com/RustPython/RustPython / replace_paths_in_code

Method replace_paths_in_code

Lib/modulefinder.py:584–605  ·  view source on GitHub ↗
(self, co)

Source from the content-addressed store, hash-verified

582 return missing, maybe
583
584 def replace_paths_in_code(self, co):
585 new_filename = original_filename = os.path.normpath(co.co_filename)
586 for f, r in self.replace_paths:
587 if original_filename.startswith(f):
588 new_filename = r + original_filename[len(f):]
589 break
590
591 if self.debug and original_filename not in self.processed_paths:
592 if new_filename != original_filename:
593 self.msgout(2, "co_filename %r changed to %r" \
594 % (original_filename,new_filename,))
595 else:
596 self.msgout(2, "co_filename %r remains unchanged" \
597 % (original_filename,))
598 self.processed_paths.append(original_filename)
599
600 consts = list(co.co_consts)
601 for i in range(len(consts)):
602 if isinstance(consts[i], type(co)):
603 consts[i] = self.replace_paths_in_code(consts[i])
604
605 return co.replace(co_consts=tuple(consts), co_filename=new_filename)
606
607
608def test():

Callers 1

load_moduleMethod · 0.95

Calls 7

msgoutMethod · 0.95
lenFunction · 0.85
listClass · 0.85
isinstanceFunction · 0.85
startswithMethod · 0.45
appendMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected