cool-RR / PySnooper

Never use print for debugging again
MIT License
16.31k stars 954 forks source link

new features request/discussion #244

Closed yantaozhao closed 1 year ago

yantaozhao commented 1 year ago

PySnooper is an awesome tool to tracing program runs.

It would be more powerful if add new features/options through snoop() parameters, descripted below:

output:

----Source path:... test/hello.py # <-customized indent char, and optional more indent level ----call 10 def main(): tons of program output here! --------call 15 def foo(): tons of program output here! maybe more nested calls. tons of program output here! --------return 16 return None ----return 20 print('bye') ----Return value:.. None


- [ ] only disable timestamp wthout interfering other thing, alongside `normalize`.
Keep absolute or subfolder path, but no timestamp to reduce at least 16 indent spaces that `normalize` added.

- [ ] show function/listcomprehension/dictcomprehension arguments. like as `call-return` pair, show `Passing arguments` and `Return value` beneath `call` and `return`.
Example:
```python
@pysnoopy.snoop(depth=sys.maxsize, indent_char='-', show_function_arguments=True)

# output:
----Source path:... test/hello.py
----call 10 def foo(a, b, c=4):
----Pass arguments: {'a'=2, 'b'=3, 'c'=4}  # <-show "Pass arguments" here!
codes executed
----return 20 return 1
----Return value:.. 1

output:

----Return value:.. <class 'torch.Tensor'> tensor([...]) # <-show return type


- [ ] restricted snoop to some path such as current project folder, and also specify more ignore paths.
Most times, I'm not interested in the built-in modules or third-party packages, but only current project's code. And likely to ignore some subfolder too, like `venv`/`test` folder etc.
```python
@pysnoopy.snoop(depth=sys.maxsize, restricted_to_path=os.getcwd(), ignore_paths=['venv', 'test', 'subfolder/xxx.py'])
# <- restricted to current folder, and ignore more folders and files
def main():
    pass

To prove the ideas, I've made some changes in the fork to implement above features, without adapting to early python version.

Any discussions or ideas are welcome.

cool-RR commented 1 year ago

Thanks for offering these feature requests. Most of these seem to me barely worth the maintenance burden. Out of all of these, the one that sounds the best is the feature request for including and excluding paths. If you'd like to implement this feature, let me warn you in advance: I'll make a list of requirements of exactly how it should behave, and I'd want you to write the whole thing, including extensive tests. It'll have to support Python versions 2.7+, and I'll also want you to run the tests on enough Python versions to be very confident that it works everywhere.

I'm letting you know in advance so if this is too much for you, you could let it go before you put any effort in. If it's not too much for you, create a separate feature request for this specific issue and I'll list my requirements.

yantaozhao commented 1 year ago

Thank you for your hard work to maintenance PySnooper. maybe someone will implement the features in future. You can close the issue if you want.