From 1bd541fe6198775d14edafde2c25dda9691039e7 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 15 Aug 2025 15:57:31 +0200 Subject: [PATCH] Use jinja2 FileSystemLoader instead of PackageLoader for compat with newer meson-python and editable installs Co-Authored-By: Will Ayd --- pandas/io/formats/style_render.py | 5 ++++- pandas/tests/io/formats/style/test_html.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 0747e7c84e1b0..11ef37a0d69f3 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -6,6 +6,7 @@ Sequence, ) from functools import partial +import pathlib import re from typing import ( TYPE_CHECKING, @@ -70,7 +71,9 @@ class StylerRenderer: Base class to process rendering a Styler with a specified jinja2 template. """ - loader = jinja2.PackageLoader("pandas", "io/formats/templates") + this_dir = pathlib.Path(__file__).parent.resolve() + template_dir = this_dir / "templates" + loader = jinja2.FileSystemLoader(template_dir) env = jinja2.Environment(loader=loader, trim_blocks=True) template_html = env.get_template("html.tpl") template_html_table = env.get_template("html_table.tpl") diff --git a/pandas/tests/io/formats/style/test_html.py b/pandas/tests/io/formats/style/test_html.py index 752b9b391f9cb..e46a59197a3b7 100644 --- a/pandas/tests/io/formats/style/test_html.py +++ b/pandas/tests/io/formats/style/test_html.py @@ -1,3 +1,4 @@ +import pathlib from textwrap import ( dedent, indent, @@ -18,7 +19,9 @@ @pytest.fixture def env(): - loader = jinja2.PackageLoader("pandas", "io/formats/templates") + project_dir = pathlib.Path(__file__).parent.parent.parent.parent.parent.resolve() + template_dir = project_dir / "io" / "formats" / "templates" + loader = jinja2.FileSystemLoader(template_dir) env = jinja2.Environment(loader=loader, trim_blocks=True) return env