-
Notifications
You must be signed in to change notification settings - Fork 32
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
Index node finder #64
base: master
Are you sure you want to change the base?
Conversation
f148326
to
554504f
Compare
554504f
to
57d8fb0
Compare
28a88ea
to
637521e
Compare
8ad604b
to
0a22823
Compare
0a22823
to
05c7218
Compare
hi @alexmojaki. I have some good news for you. The new NodeFinder is near completion and works so far, but I need some more time to finish and to optimize it. Here you can get some impression what it can do: https://github.com/15r10nk/executing/blob/index_node_finder/Features.md This list gets generated by pytest and probably still misses some features. |
af7ef00
to
65619b9
Compare
335d5c3
to
e5d175c
Compare
4a69438
to
20cef7d
Compare
20cef7d
to
d16de24
Compare
We're going to use It sounded like this was going well, can it be revived? |
cool that inline-snapshot is used in logfire 😄
kind of. This branch works not out of the box with pytest. I had to reapply the pytest changes on top of the original ast to make the mapping work. We would have to do the same with logfire / any other library which modifies the ast (like lazy-imports-lite for example).
Yes, the concept worked, but I would merge it with the current main and add some comments to make it easier to understand before you review it. I have also a general question to ast-rewriting with a custom MetaPathFinder. The auto_trace feature of logfire can currently not be used in combination with assertion rewriting of pytest for example. And I'm also not sure which rewriting would be used. |
Wouldn't that work equally well with the other node finders? It sounds like this branch doesn't actually help with pytest. Would this branch work better when the statement being executed hasn't been modified, i.e. all the modifications are 'around' the executed statement?
I have also thought such a thing would be nice. I imagine it doesn't exist because AST rewriting isn't common enough that people are bothered by them not cooperating. Another library that does this is birdseye. I could make executing work with auto-tracing if I did the AST transformation on the tree of an |
This branch has almost the same functionality like the PositionNodeFinder. We would have to add something similar for logfire.
I hope that I'm correct here, but this should not be a problem. logfire could memorize every ast it has created for a source file and we could check each of them for a matching bytecode. |
A modification at root level messes with the bytecode structure and the algo can not map the bytecodes (and child bytecodes) any more. |
Ah, after rereading #31 (comment) I see that this method requires the bytecode to match the source code exactly, my mistake for thinking otherwise. I could store a Source for each modified code object produced by |
It might be enough to store the args. You should be able to generate the Source with this args and the original ast. I was thinking about something like this: @executing.register_ast_provider
def get_logfire_ast(path,original_ast):
for args in all_args_for_file(path):
yield transform(original_ast,args) Could this also be used to make the SentinelNodeFinder work? |
Can you tell me why you need the args to generate the code? I read some source of logfire but I did not understood why instrument should generate different code for different args. |
It might be possible to always generate the same code every time, but probably with some small performance cost. I can consider various approaches to solving this problem if I get to it. For now I'm just going to only fully support this feature in 3.11+. |
It is just an idea and I probably don't know enough about logfire, but you could generate something like this: @logfire.instrument
def some_function(arg_a,arg_b,__logfire_args__):
if __logfire_args__.extract_args:
__logfire_args__.method({"arg_a":arg_a,"arg_b":arg_b})
... The instrument decorator should pass the This would also save some time if you have multiple instrumented functions, because you would transform the source only once. But you have probably similar ideas. It is ok for me if this branch does not get merged. |
This is still work in progress.
The goal is an NodeFinder with similar capabilities like PositionNodeFinder, but for cpython <= 3.10.
see #42
todo:
3.7 (if possible)to difficult for now3.6 (if possible)to difficult for now