Hi,
I'm porting Testoob to IronPython and have a module function that needs to
know the filename where the code calling it is defined.
In CPython I get the current frame with sys._getframe(), then climb
the stack with frame.f_back until I find a different file:
def _first_external_frame():
import sys
# find the first frame with a filename different than this one
frame = sys._getframe()
while frame.f_globals["__file__"] == __file__:
frame = frame.f_back
return frame
def _calling_module_directory():
from os.path import dirname, normpath
return normpath(dirname(_first_external_frame().f_globals["__file__"]))
I know I can't climb the stack in IronPython, but is there another way
to do it? Maybe some available .NET assembly metadata?
BTW - the use case is for building test suites: you can have a
subpackage of tests and define __init__.py like this:
def suite():
import testoob
return testoob.collecting.collect_from_files("test_*.py")
Thanks,
orip.
--
Check out my blog: http://orip.org
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com