From 48aac747cafd3aca44fc1fd4f0b6e5f072bb9879 Mon Sep 17 00:00:00 2001 From: hbristow Date: Tue, 6 Aug 2013 00:40:57 +1000 Subject: [PATCH] removed pkg_resources (setuptools) dependency from jinja. Matlab module now has no python dependencies beyond the core python libs --- modules/matlab/generator/gen_matlab.py | 5 +- modules/matlab/generator/jinja2/__init__.py | 4 +- modules/matlab/generator/jinja2/loaders.py | 65 --------------------- 3 files changed, 5 insertions(+), 69 deletions(-) diff --git a/modules/matlab/generator/gen_matlab.py b/modules/matlab/generator/gen_matlab.py index f788c4a1b9..44b46fd949 100644 --- a/modules/matlab/generator/gen_matlab.py +++ b/modules/matlab/generator/gen_matlab.py @@ -26,7 +26,8 @@ class MatlabWrapperGenerator(object): parse_tree.build(ns) # setup the template engine - jtemplate = Environment(loader=PackageLoader('templates', ''), trim_blocks=True, lstrip_blocks=True) + template_dir = os.path.join(os.path.dirname(__file__), 'templates') + jtemplate = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True) # add the custom filters jtemplate.filters['formatMatlabConstant'] = formatMatlabConstant @@ -99,7 +100,7 @@ if __name__ == "__main__": from hdr_parser import CppHeaderParser from parse_tree import ParseTree, todict, constants from filters import * - from jinja2 import Environment, PackageLoader + from jinja2 import Environment, FileSystemLoader # get the IO from the command line arguments input_files = sys.argv[2:-1] diff --git a/modules/matlab/generator/jinja2/__init__.py b/modules/matlab/generator/jinja2/__init__.py index 8434dea180..fe9e8224d3 100644 --- a/modules/matlab/generator/jinja2/__init__.py +++ b/modules/matlab/generator/jinja2/__init__.py @@ -33,7 +33,7 @@ __version__ = '2.8-dev' from jinja2.environment import Environment, Template # loaders -from jinja2.loaders import BaseLoader, FileSystemLoader, PackageLoader, \ +from jinja2.loaders import BaseLoader, FileSystemLoader, \ DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \ ModuleLoader @@ -58,7 +58,7 @@ from jinja2.utils import Markup, escape, clear_caches, \ __all__ = [ 'Environment', 'Template', 'BaseLoader', 'FileSystemLoader', - 'PackageLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader', + 'DictLoader', 'FunctionLoader', 'PrefixLoader', 'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache', 'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined', 'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound', diff --git a/modules/matlab/generator/jinja2/loaders.py b/modules/matlab/generator/jinja2/loaders.py index a9a2625274..c19fd30db0 100644 --- a/modules/matlab/generator/jinja2/loaders.py +++ b/modules/matlab/generator/jinja2/loaders.py @@ -192,71 +192,6 @@ class FileSystemLoader(BaseLoader): return sorted(found) -class PackageLoader(BaseLoader): - """Load templates from python eggs or packages. It is constructed with - the name of the python package and the path to the templates in that - package:: - - loader = PackageLoader('mypackage', 'views') - - If the package path is not given, ``'templates'`` is assumed. - - Per default the template encoding is ``'utf-8'`` which can be changed - by setting the `encoding` parameter to something else. Due to the nature - of eggs it's only possible to reload templates if the package was loaded - from the file system and not a zip file. - """ - - def __init__(self, package_name, package_path='templates', - encoding='utf-8'): - from pkg_resources import DefaultProvider, ResourceManager, \ - get_provider - provider = get_provider(package_name) - self.encoding = encoding - self.manager = ResourceManager() - self.filesystem_bound = isinstance(provider, DefaultProvider) - self.provider = provider - self.package_path = package_path - - def get_source(self, environment, template): - pieces = split_template_path(template) - p = '/'.join((self.package_path,) + tuple(pieces)) - if not self.provider.has_resource(p): - raise TemplateNotFound(template) - - filename = uptodate = None - if self.filesystem_bound: - filename = self.provider.get_resource_filename(self.manager, p) - mtime = path.getmtime(filename) - def uptodate(): - try: - return path.getmtime(filename) == mtime - except OSError: - return False - - source = self.provider.get_resource_string(self.manager, p) - return source.decode(self.encoding), filename, uptodate - - def list_templates(self): - path = self.package_path - if path[:2] == './': - path = path[2:] - elif path == '.': - path = '' - offset = len(path) - results = [] - def _walk(path): - for filename in self.provider.resource_listdir(path): - fullname = path + '/' + filename - if self.provider.resource_isdir(fullname): - _walk(fullname) - else: - results.append(fullname[offset:].lstrip('/')) - _walk(path) - results.sort() - return results - - class DictLoader(BaseLoader): """Loads a template from a python dict. It's passed a dict of unicode strings bound to template names. This loader is useful for unittesting: