Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal - standardizing directories and template paths #259

Open
sqlalchemy-bot opened this issue Nov 23, 2016 · 4 comments
Open

proposal - standardizing directories and template paths #259

sqlalchemy-bot opened this issue Nov 23, 2016 · 4 comments
Labels
Milestone

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by jvanasco (@jvanasco)

I've been working on some tools to precompile templates before a webserver forks, and have run into a few issues when trying to build this out more reliably.

  1. 'directories' can be duplicates. I'm not sure this will affect anything down the line, but it might make sense. this is relatively simple to fix.

    lookup = TemplateLookup(directories=['templates', 'templates/', 'templates'])
    print lookup.directories
    ['templates', 'templates', 'templates']

  2. filenames aren't standardized, so the same template can become 2 objects/compiled 2 ways (relative vs absolute). this will require more thought.

    lookup = TemplateLookup(directories=['templates'])
    t1 = lookup.get_template('goodnight_moon.mako')
    t2 = lookup.get_template('/goodnight_moon.mako')
    print lookup._collection
    {'goodnight_moon.mako': <mako.template.Template object at 0x1015df510>, '/goodnight_moon.mako': <mako.template.Template object at 0x1015df850>}

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

i think you mean "canonicalized". you run the paths through os.path.abspath(os.path.realpath()) in order to get the key in the lookup. This is too expensive to do for every include call, so you'd still cache on all three paths, the canonical path is only used when first creating the entry:

{"/canonical/path/to/template.mako": <Template at 0x123>, "template.mako": <Template at 0x123>, "/path/to/template.mako": <Template at 0x123>}

the behavior turns on using a flag "canonical=True" to TemplateLookup.

@sqlalchemy-bot
Copy link
Author

jvanasco (@jvanasco) wrote:

Yeah - canonical names for templates.

the behavior turns on using a flag "canonical=True" to TemplateLookup

Is that your suggestion for implementing? That doesn't exist right now.

I was thinking about augmenting the .directories with something like:

self.directories_real = [d: os.path.abspath(os.path.realpath(d)) for d in self.directories]

then using that cached value when generating a key.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

yes, the flag would be added. The cache lookup for an <%include> should still be just one hash lookup though. Just put mulitple entries into the cache, one on the canonical path, one on the requested path.

@sqlalchemy-bot
Copy link
Author

jvanasco (@jvanasco) wrote:

gotcha. thanks.

@bourke bourke added this to Backlog in Mako prioritization Nov 17, 2021
@bourke bourke added this to the 1.3 milestone Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants