ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
796 stars 46 forks source link

`hunter.Event.filename` may be relative #56

Closed chrahunt closed 5 years ago

chrahunt commented 5 years ago

The docs of hunter.Event.filename state that it returns an absolute path

https://github.com/ionelmc/python-hunter/blob/b3a1310b0593d2c6b6ef430883843896e17d6a81/src/hunter/event.py#L178

That is not true in all cases.

Environment

$ python -V
Python 3.7.1
$ pip freeze | grep hunter
hunter==2.2.1
$ echo "print(__file__)" > test.py
$ python test.py
test.py

Test

$ PYTHONHUNTER="filename='$PWD/test.py'"  python test.py
test.py
$ PYTHONHUNTER="filename='test.py'"  python test.py
                                 test.py:1     call      => <module>()
                                 test.py:1     line         print(__file__)
test.py
                                 test.py:1     return    <= <module>: None

The expected behavior would be for $PWD/test.py to match and output to be generated - but instead it only works when providing a relative path.

ionelmc commented 5 years ago

Well there are a bunch of ways to deal with this problem:

ionelmc commented 5 years ago

Ah, now I noticed you complained about the docstring. Hmmm ... so making it absolute would be problematic when tracing code that changes cwd at least. Lemme try some experiments...

ionelmc commented 5 years ago

So uh, compromise to fixing docstring and adding basename?

chrahunt commented 5 years ago

Fine by me.

ionelmc commented 5 years ago

Fixed in 310d1542671946a78c2a543fa2acbe87bfe68bbb.