MCPcopy Index your code
hub / github.com/python/cpython / _load_templates

Method _load_templates

Lib/profiling/sampling/heatmap_collector.py:191–224  ·  view source on GitHub ↗

Load all template files from _heatmap_assets.

(self)

Source from the content-addressed store, hash-verified

189 self._load_templates()
190
191 def _load_templates(self):
192 """Load all template files from _heatmap_assets."""
193 try:
194 template_dir = importlib.resources.files(__package__)
195 assets_dir = template_dir / "_heatmap_assets"
196
197 # Load HTML templates
198 self.index_template = (assets_dir / "heatmap_index_template.html").read_text(encoding="utf-8")
199 self.file_template = (assets_dir / "heatmap_pyfile_template.html").read_text(encoding="utf-8")
200
201 # Load CSS (same file used for both index and file pages)
202 css_content = get_combined_css("heatmap")
203 self.index_css = css_content
204 self.file_css = css_content
205
206 # Load JS
207 base_js = (template_dir / "_shared_assets" / "base.js").read_text(encoding="utf-8")
208 heatmap_shared_js = (assets_dir / "heatmap_shared.js").read_text(encoding="utf-8")
209 shared_js = f"{base_js}\n{heatmap_shared_js}"
210 self.index_js = f"{shared_js}\n{(assets_dir / 'heatmap_index.js').read_text(encoding='utf-8')}"
211 self.file_js = f"{shared_js}\n{(assets_dir / 'heatmap.js').read_text(encoding='utf-8')}"
212
213 # Load Tachyon logo
214 logo_dir = template_dir / "_assets"
215 try:
216 png_path = logo_dir / "tachyon-logo.png"
217 b64_logo = base64.b64encode(png_path.read_bytes()).decode("ascii")
218 self.logo_html = f'<img src="data:image/png;base64,{b64_logo}" alt="Tachyon logo" class="python-logo"/>'
219 except (FileNotFoundError, IOError) as e:
220 self.logo_html = '<div class="python-logo-placeholder"></div>'
221 print(f"Warning: Could not load Tachyon logo: {e}")
222
223 except (FileNotFoundError, IOError) as e:
224 raise RuntimeError(f"Failed to load heatmap template files: {e}") from e
225
226
227class _TreeBuilder:

Callers 1

__init__Method · 0.95

Calls 5

get_combined_cssFunction · 0.85
filesMethod · 0.45
read_textMethod · 0.45
decodeMethod · 0.45
read_bytesMethod · 0.45

Tested by

no test coverage detected