Open skeledrew opened 3 years ago
If you're willing to make a PR to make read_source_file
use linecache.getlines
instead of the filesystem, then you could add a linecache entry like this:
The end result would be basically the same as creating a file, but without involving actual files.
Whether you do this or make a temporary file, there will also be the benefit of the source code showing up in a traceback, which as you can see it currently doesn't.
I've complained about this problem in general here but got no response.
I made a PR here. Seems a bit hacky though, as it'll require anyone else who runs into the issue to be aware of the implementation.
Great! Can you confirm that using that branch and the modified form of exec fixes the problem on your end? Are tracebacks also working now?
Working great, thanks! Though I didn't really notice an issue with the traceback TBH.
Look at what you originally posted:
> File "/home/skeledrew/Projects/pyls-livepy/.nox/make_pyls_livepy_test_env/lib/python3.7/site-packages/pyls_livepy/tracer.py", line 78, in run_trace_2
exec(source)
└ 'import pyls_livepy\n\n@pyls_livepy.eye\ndef func(x):\n """\n >>> func(5)\n 0\n """\n return x * x\n\nfunc(5)\n'
File "<string>", line 3, in <module>
File "/home/skeledrew/Projects/pyls-livepy/.nox/make_pyls_livepy_test_env/lib/python3.7/site-packages/birdseye/__init__.py", line 24, in __call__
return self.__val()(*args, **kwargs)
There's no source code under File "<string>", line 3, in <module>
Oh I see. I thought it was just a normal limitation. Yes I do have full tracebacks now, thanks.
> File "/home/skeledrew/Projects/pyls-livepy/.nox/make_pyls_livepy_test_env/lib/python3.7/site-packages/pyls_livepy/tracer.py", line 58, in run_trace
exec(code_obj)
└ <code object <module> at 0x7f4dd830b6f0, file "<some-string>", line 1>
File "<some-string>", line 32, in <module>
square("5")
└ <function square at 0x7f4dd81d4320>
File "<some-string>", line 20, in square
return x ** 2
└ '5'
I am attempting to use birdseye from within another tool, and a part of what it does is modify the source dynamically. This causes attempts to get a filename to fail. Is there a way to get around this without, say creating a temporary file?