diff options
author | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 12:29:46 +0300 |
---|---|---|
committer | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 13:14:22 +0300 |
commit | 9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch) | |
tree | a8fb3181d5947c0d78cf402aa56e686130179049 /contrib/python/Jinja2/py3 | |
parent | a44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff) | |
download | ydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz |
publishFullContrib: true for ydb
<HIDDEN_URL>
commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/python/Jinja2/py3')
4 files changed, 233 insertions, 0 deletions
diff --git a/contrib/python/Jinja2/py3/.yandex_meta/yamaker.yaml b/contrib/python/Jinja2/py3/.yandex_meta/yamaker.yaml new file mode 100644 index 0000000000..9c91995480 --- /dev/null +++ b/contrib/python/Jinja2/py3/.yandex_meta/yamaker.yaml @@ -0,0 +1,4 @@ +exclude: + - examples/basic/test.py +mark_as_sources: + - jinja2/tests.py diff --git a/contrib/python/Jinja2/py3/patches/01-arcadia.patch b/contrib/python/Jinja2/py3/patches/01-arcadia.patch new file mode 100644 index 0000000000..03688772ca --- /dev/null +++ b/contrib/python/Jinja2/py3/patches/01-arcadia.patch @@ -0,0 +1,30 @@ +--- contrib/python/Jinja2/py3/jinja2/__init__.py (index) ++++ contrib/python/Jinja2/py3/jinja2/__init__.py (working tree) +@@ -22,6 +22,7 @@ from .loaders import FunctionLoader + from .loaders import ModuleLoader as ModuleLoader + from .loaders import PackageLoader as PackageLoader + from .loaders import PrefixLoader as PrefixLoader ++from .loaders import ResourceLoader as ResourceLoader + from .runtime import ChainableUndefined as ChainableUndefined + from .runtime import DebugUndefined as DebugUndefined + from .runtime import make_logging_undefined as make_logging_undefined +--- contrib/python/Jinja2/py3/jinja2/loaders.py (index) ++++ contrib/python/Jinja2/py3/jinja2/loaders.py (working tree) +@@ -659,3 +659,17 @@ class ModuleLoader(BaseLoader): + return environment.template_class.from_module_dict( + environment, mod.__dict__, globals + ) ++ ++ ++class ResourceLoader(BaseLoader): ++ def __init__(self, prefix, module_loader): ++ self.prefix = prefix ++ self.module_loader = module_loader ++ ++ def get_source(self, environment, template): ++ if self.module_loader is None: ++ raise TemplateNotFound(template) ++ try: ++ return self.module_loader.get_data(os.path.join(self.prefix, template)).decode('utf-8'), None, None ++ except IOError: ++ raise TemplateNotFound(template) diff --git a/contrib/python/Jinja2/py3/patches/02-fix-tests.patch b/contrib/python/Jinja2/py3/patches/02-fix-tests.patch new file mode 100644 index 0000000000..c62a863468 --- /dev/null +++ b/contrib/python/Jinja2/py3/patches/02-fix-tests.patch @@ -0,0 +1,69 @@ +--- contrib/python/Jinja2/py3/tests/conftest.py (index) ++++ contrib/python/Jinja2/py3/tests/conftest.py (working tree) +@@ -27,7 +27,8 @@ def package_loader(): + @pytest.fixture + def filesystem_loader(): + """returns FileSystemLoader initialized to res/templates directory""" +- here = Path(__file__).parent.resolve() ++ import yatest.common ++ here = Path(yatest.common.test_source_path()) + return loaders.FileSystemLoader(here / "res" / "templates") + + +--- contrib/python/Jinja2/py3/tests/test_loader.py (index) ++++ contrib/python/Jinja2/py3/tests/test_loader.py (working tree) +@@ -18,6 +18,8 @@ from jinja2._compat import PYPY + from jinja2.exceptions import TemplateNotFound + from jinja2.loaders import split_template_path + ++import yatest.common as yc ++ + + class TestLoaders: + def test_dict_loader(self, dict_loader): +@@ -118,7 +120,7 @@ class TestLoaders(object): + + + class TestFileSystemLoader: +- searchpath = (Path(__file__) / ".." / "res" / "templates").resolve() ++ searchpath = (Path(yc.test_source_path()) / "res" / "templates").resolve() + + @staticmethod + def _test_common(env): +@@ -146,6 +148,7 @@ class TestFileSystemLoader(object): + env = Environment(loader=filesystem_loader) + self._test_common(env) + ++ @pytest.mark.skip("Arcadia read only") + def test_caches_template_based_on_mtime(self): + filesystem_loader = loaders.FileSystemLoader(self.searchpath) + +@@ -325,7 +328,7 @@ def test_package_dir_list(package_dir_loader): + @pytest.fixture() + def package_file_loader(monkeypatch): + monkeypatch.syspath_prepend(Path(__file__).parent / "res") +- return PackageLoader("__init__") ++ return PackageLoader("res") + + + @pytest.mark.parametrize( +@@ -346,7 +349,7 @@ def test_package_dir_list(package_dir_loader): + + @pytest.fixture() + def package_zip_loader(monkeypatch): +- package_zip = (Path(__file__) / ".." / "res" / "package.zip").resolve() ++ package_zip = (Path(yc.test_source_path()) / "res" / "package.zip").resolve() + monkeypatch.syspath_prepend(package_zip) + return PackageLoader("t_pack") + +--- contrib/python/Jinja2/py3/tests/test_utils.py (index) ++++ contrib/python/Jinja2/py3/tests/test_utils.py (working tree) +@@ -110,7 +110,7 @@ class TestHelpers(object): + + assert object_type_repr(42) == "int object" + assert object_type_repr([]) == "list object" +- assert object_type_repr(X()) == "test_utils.X object" ++ assert object_type_repr(X()) == "__tests__.test_utils.X object" + assert object_type_repr(None) == "None" + assert object_type_repr(Ellipsis) == "Ellipsis" + diff --git a/contrib/python/Jinja2/py3/patches/03-fix-PackageLoader.patch b/contrib/python/Jinja2/py3/patches/03-fix-PackageLoader.patch new file mode 100644 index 0000000000..d4c98d43f5 --- /dev/null +++ b/contrib/python/Jinja2/py3/patches/03-fix-PackageLoader.patch @@ -0,0 +1,130 @@ +--- contrib/python/Jinja2/py3/jinja2/loaders.py (index) ++++ contrib/python/Jinja2/py3/jinja2/loaders.py (working tree) +@@ -5,6 +5,7 @@ sources. + import os + import posixpath + import sys ++import pkgutil + import typing as t + import weakref + import zipimport +@@ -21,6 +22,8 @@ if t.TYPE_CHECKING: + from .environment import Environment + from .environment import Template + ++import __res as arcadia_res ++ + + def split_template_path(template: str) -> t.List[str]: + """Split a path into segments and perform a sanity check. If it detects +@@ -288,19 +291,22 @@ class PackageLoader(BaseLoader): + + # Make sure the package exists. This also makes namespace + # packages work, otherwise get_loader returns None. +- import_module(package_name) ++ package = import_module(package_name) + spec = importlib.util.find_spec(package_name) + assert spec is not None, "An import spec was not found for the package." + loader = spec.loader + assert loader is not None, "A loader was not found for the package." + self._loader = loader + self._archive = None ++ self._package = package + template_root = None + + if isinstance(loader, zipimport.zipimporter): + self._archive = loader.archive + pkgdir = next(iter(spec.submodule_search_locations)) # type: ignore + template_root = os.path.join(pkgdir, package_path).rstrip(os.path.sep) ++ elif hasattr(loader, "arcadia_source_finder"): ++ template_root = os.path.dirname(package.__file__).rstrip(os.path.sep) + else: + roots: t.List[str] = [] + +@@ -338,7 +341,16 @@ class PackageLoader(BaseLoader): + p = posixpath.join(self._template_root, *split_template_path(template)) + up_to_date: t.Optional[t.Callable[[], bool]] + +- if self._archive is None: ++ if self._archive is None and hasattr(self, "_package"): ++ try: ++ source = pkgutil.get_data(self.package_name, os.path.join(self.package_path, *split_template_path(template))) ++ except OSError: ++ raise TemplateNotFound(template) ++ ++ def up_to_date() -> bool: ++ return True ++ ++ elif self._archive is None: + # Package is a directory. + if not os.path.isfile(p): + raise TemplateNotFound(template) +@@ -368,7 +380,12 @@ class PackageLoader(BaseLoader): + def list_templates(self) -> t.List[str]: + results: t.List[str] = [] + +- if self._archive is None: ++ if self._archive is None and hasattr(self, "_package"): ++ prefix = os.path.join(self._template_root, self.package_path).encode() + b"/" ++ for name in arcadia_res.resfs_files(prefix): ++ results.append(name.removeprefix(prefix).decode()) ++ ++ elif self._archive is None: + # Package is a directory. + offset = len(self._template_root) + +--- contrib/python/Jinja2/py3/jinja2/loaders.py (index) ++++ contrib/python/Jinja2/py3/jinja2/loaders.py (working tree) +@@ -279,6 +279,7 @@ class PackageLoader(BaseLoader): + package_name: str, + package_path: "str" = "templates", + encoding: str = "utf-8", ++ skip_unknown_package: bool = False, + ) -> None: + package_path = os.path.normpath(package_path).rstrip(os.path.sep) + +@@ -291,6 +292,7 @@ class PackageLoader(BaseLoader): + self.package_path = package_path + self.package_name = package_name + self.encoding = encoding ++ self.skip_unknown_package = skip_unknown_package + + # Make sure the package exists. This also makes namespace + # packages work, otherwise get_loader returns None. +@@ -339,6 +341,9 @@ class PackageLoader(BaseLoader): + def get_source( + self, environment: "Environment", template: str + ) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]: ++ if self._template_root is None and self.skip_unknown_package: ++ raise TemplateNotFound(template) ++ + # Use posixpath even on Windows to avoid "drive:" or UNC + # segments breaking out of the search directory. Use normpath to + # convert Windows altsep to sep. +@@ -386,6 +391,9 @@ class PackageLoader(BaseLoader): + def list_templates(self) -> t.List[str]: + results: t.List[str] = [] + ++ if self._template_root is None and self.skip_unknown_package: ++ return results ++ + if self._archive is None and hasattr(self, "_package"): + prefix = os.path.join(self._template_root, self.package_path).encode() + b"/" + for name in arcadia_res.resfs_files(prefix): +--- contrib/python/Jinja2/py3/jinja2/loaders.py (index) ++++ contrib/python/Jinja2/py3/jinja2/loaders.py (working tree) +@@ -296,7 +296,13 @@ class PackageLoader(BaseLoader): + + # Make sure the package exists. This also makes namespace + # packages work, otherwise get_loader returns None. +- package = import_module(package_name) ++ try: ++ package = import_module(package_name) ++ except ModuleNotFoundError: ++ if skip_unknown_package: ++ self._template_root = None ++ return ++ raise + spec = importlib.util.find_spec(package_name) + assert spec is not None, "An import spec was not found for the package." + loader = spec.loader |