diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
| commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
| tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/python/Jinja2/py3/patches | |
| parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/Jinja2/py3/patches')
3 files changed, 158 insertions, 158 deletions
diff --git a/contrib/python/Jinja2/py3/patches/01-arcadia.patch b/contrib/python/Jinja2/py3/patches/01-arcadia.patch index 4a7109dbae5..b78b648b373 100644 --- a/contrib/python/Jinja2/py3/patches/01-arcadia.patch +++ b/contrib/python/Jinja2/py3/patches/01-arcadia.patch @@ -1,30 +1,30 @@ ---- contrib/python/Jinja2/py3/jinja2/__init__.py (index) -+++ contrib/python/Jinja2/py3/jinja2/__init__.py (working tree) -@@ -25,6 +25,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) +--- contrib/python/Jinja2/py3/jinja2/__init__.py (index) ++++ contrib/python/Jinja2/py3/jinja2/__init__.py (working tree) +@@ -25,6 +25,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) @@ -650,3 +650,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) + 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 index 7bd87576c20..d23c1d80963 100644 --- a/contrib/python/Jinja2/py3/patches/02-fix-tests.patch +++ b/contrib/python/Jinja2/py3/patches/02-fix-tests.patch @@ -1,69 +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) - +--- 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) + @@ -316,7 +319,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( @@ -337,7 +340,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" - + @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 index b2a7691914e..898e0c11893 100644 --- a/contrib/python/Jinja2/py3/patches/03-fix-PackageLoader.patch +++ b/contrib/python/Jinja2/py3/patches/03-fix-PackageLoader.patch @@ -1,75 +1,75 @@ ---- contrib/python/Jinja2/py3/jinja2/loaders.py (index) -+++ contrib/python/Jinja2/py3/jinja2/loaders.py (working tree) -@@ -4,6 +4,7 @@ sources. - import importlib.util - import os - import sys -+import pkgutil - import typing as t - import weakref - import zipimport -@@ -20,6 +21,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 -@@ -284,19 +287,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) -+ elif hasattr(loader, "arcadia_source_finder"): -+ template_root = os.path.dirname(package.__file__) +--- contrib/python/Jinja2/py3/jinja2/loaders.py (index) ++++ contrib/python/Jinja2/py3/jinja2/loaders.py (working tree) +@@ -4,6 +4,7 @@ sources. + import importlib.util + import os + import sys ++import pkgutil + import typing as t + import weakref + import zipimport +@@ -20,6 +21,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 +@@ -284,19 +287,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) ++ elif hasattr(loader, "arcadia_source_finder"): ++ template_root = os.path.dirname(package.__file__) else: roots: t.List[str] = [] @@ -329,7 +335,16 @@ class PackageLoader(BaseLoader): - p = os.path.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) + p = os.path.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) @@ -359,7 +374,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) - + 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) + |
