sqlalchemy / sqlalchemy/mako

include complete filename of invoking frame

Open
#280 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug low priority
Dominant language
Python
Stars
459
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Mario Frasca (@mfrasca)

I'm distributing templates with resources. they go next to each other. my python program reads the template using a lookup, and it's the template that should be able to open the resource and include it in the rendering process.

in practice? it's postscript, and the resource is an image which I want to include in the result.

the problem is that once the template file has been copied where mako can find it thanks to the lookup, I don't know how to get to the location and open the resource, located relative to it.

it would not be such a big deal, if mako did not strip the complete path of source files in the frames information.

this is the invoked frame, where I need to know the location of the template file:
(frame=<frame object at 0x7f4f607fd6b8>, filename='/home/mario/.virtualenvs/ghide-3.1-dev/lib/python3.5/site-packages/ghini.desktop-3.1.8-py3.5.egg/bauble/plugins/report/utils.py', lineno=375, function='add_text', code_context=[' print(inspect.getouterframes(inspect.currentframe()))\n'], index=0)

please notice the complete path of filename

this is the invoking frame, where most information is missing:

(frame=<frame object at 0x7f4f60218908>, filename='accession_label_single_qr_ps_mako', lineno=103, function='render_body', code_context=None, index=None)

the above is what I can read using inspect.getouterframes(inspect.currentframe()), but precisely the same you can also get with sys._getframe().f_back.co_filename

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Mako creates the invoking template frame and compare the reported inspect.getouterframes() output with sys._getframe().f_back.co_filename. The issue mentions the template name accession_label_single_qr_ps_mako and render_body; done means exposing the complete template filename in the frame information when a lookup-loaded template is invoked.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.