diff --git a/luigi/server.py b/luigi/server.py index 749f94e562..1a6fc26123 100644 --- a/luigi/server.py +++ b/luigi/server.py @@ -37,7 +37,6 @@ import atexit import datetime -import importlib import json import logging import os @@ -157,7 +156,7 @@ def initialize(self, scheduler): self._scheduler = scheduler def get_template_path(self): - return importlib.resources.files("templates").name + return os.path.join(os.path.dirname(__file__), "templates") class AllRunHandler(BaseTaskHistoryHandler): diff --git a/test/server_test.py b/test/server_test.py index 6946bcff80..dd34a143c7 100644 --- a/test/server_test.py +++ b/test/server_test.py @@ -483,6 +483,19 @@ def test_get_no_metrics(self): patched_write.assert_not_called() +def test_get_template_path_returns_existing_directory(): + """Regression test for https://github.com/spotify/luigi/issues/3415. + + The returned path must point to the luigi/templates directory that + tornado uses to render task-history pages. + """ + handler = luigi.server.BaseTaskHistoryHandler(tornado.web.Application(), mock.MagicMock(), scheduler=mock.MagicMock()) + path = handler.get_template_path() + assert os.path.isdir(path), f"get_template_path() returned non-existent directory: {path!r}" + assert os.path.basename(path) == "templates" + assert os.path.isfile(os.path.join(path, "recent.html")) + + class FromUtcTest(unittest.TestCase): def test_with_microseconds(self): """Test parsing UTC time string with microseconds"""