Skip to content
Myr

Merge pull request #1505 from pallets/package-loader-path

Before adoption: this commit came in with the history the project adopted, so no landing records it.

omit curdir from PackageLoader root path

authored by David Lord · committed by GitHub · parents 355ef53, 8931077 · Browse files · 3 files+17 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+17 added−1 removed

  • tests:+11 added−0 removed
  • other:+6 added−1 removed

3 files+17 added−1 removed

modified:src/jinja2/loaders.py+3 added-1 removed
268 unmodified lines
269 package_name: str,270 package_path: "str" = "templates",271 encoding: str = "utf-8",272 ) -> None:273 package_path = os.path.normpath(package_path).rstrip(os.path.sep)274275 # normpath preserves ".", which isn't valid in zip paths.276 if package_path == os.path.curdir:277 package_path = ""278 elif package_path[:2] == os.path.curdir + os.path.sep:279 package_path = package_path[2:]280278 package_path = os.path.normpath(package_path).rstrip(os.path.sep)281 self.package_path = package_path282 self.package_name = package_name283 self.encoding = encoding284
360 unmodified lines
modified:tests/test_loader.py+11 added
337 unmodified lines
338def test_package_zip_list(package_zip_loader):339 assert package_zip_loader.list_templates() == ["foo/test.html", "test.html"]340341342@pytest.mark.parametrize("package_path", ["", ".", "./"])343def test_package_zip_omit_curdir(package_zip_loader, package_path):344 """PackageLoader should not add or include "." or "./" in the root345 path, it is invalid in zip paths.346 """347 loader = PackageLoader("t_pack", package_path)348 assert loader.package_path == ""349 source, _, _ = loader.get_source(None, "templates/foo/test.html")350 assert source.rstrip() == "FOO"351352353def test_pep_451_import_hook():354 class ImportHook(importlib.abc.MetaPathFinder, importlib.abc.Loader):355 def find_spec(self, name, path=None, target=None):356 if name != "res":
25 unmodified lines
modified:CHANGES.rst+3 added
9 unmodified lines
10- Revert an unintended change that caused ``Undefined`` to act like11 ``StrictUndefined`` for the ``in`` operator. :issue:`1448`12- Imported macros have access to the current template globals in async13 environments. :issue:`1494`14- ``PackageLoader`` will not include a current directory (.) path15 segment. This allows loading templates from the root of a zip16 import. :issue:`1467`171819Version 3.0.120-------------
876 unmodified lines