removed pkg_resources (setuptools) dependency from jinja. Matlab module now has no python dependencies beyond the core python libs

pull/1384/head
hbristow 11 years ago
parent d00f4e267b
commit 48aac747ca
  1. 5
      modules/matlab/generator/gen_matlab.py
  2. 4
      modules/matlab/generator/jinja2/__init__.py
  3. 65
      modules/matlab/generator/jinja2/loaders.py

@ -26,7 +26,8 @@ class MatlabWrapperGenerator(object):
parse_tree.build(ns) parse_tree.build(ns)
# setup the template engine # 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 # add the custom filters
jtemplate.filters['formatMatlabConstant'] = formatMatlabConstant jtemplate.filters['formatMatlabConstant'] = formatMatlabConstant
@ -99,7 +100,7 @@ if __name__ == "__main__":
from hdr_parser import CppHeaderParser from hdr_parser import CppHeaderParser
from parse_tree import ParseTree, todict, constants from parse_tree import ParseTree, todict, constants
from filters import * from filters import *
from jinja2 import Environment, PackageLoader from jinja2 import Environment, FileSystemLoader
# get the IO from the command line arguments # get the IO from the command line arguments
input_files = sys.argv[2:-1] input_files = sys.argv[2:-1]

@ -33,7 +33,7 @@ __version__ = '2.8-dev'
from jinja2.environment import Environment, Template from jinja2.environment import Environment, Template
# loaders # loaders
from jinja2.loaders import BaseLoader, FileSystemLoader, PackageLoader, \ from jinja2.loaders import BaseLoader, FileSystemLoader, \
DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \ DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \
ModuleLoader ModuleLoader
@ -58,7 +58,7 @@ from jinja2.utils import Markup, escape, clear_caches, \
__all__ = [ __all__ = [
'Environment', 'Template', 'BaseLoader', 'FileSystemLoader', 'Environment', 'Template', 'BaseLoader', 'FileSystemLoader',
'PackageLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader',
'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache', 'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache',
'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined', 'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined',
'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound', 'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound',

@ -192,71 +192,6 @@ class FileSystemLoader(BaseLoader):
return sorted(found) 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): class DictLoader(BaseLoader):
"""Loads a template from a python dict. It's passed a dict of unicode """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: strings bound to template names. This loader is useful for unittesting:

Loading…
Cancel
Save