spyder-ide / spyder-kernels

Jupyter Kernels for the Spyder console
MIT License
39 stars 40 forks source link

Debugger misses breakpoint when a file can have several canonic paths #491

Closed impact27 closed 6 months ago

impact27 commented 6 months ago

A file can have several associated paths. For example, on windows, network shares can present "virtual drive letters" so there are several way of accessing them. To address this issue, os.path.samefile uses os.stat(), see:

https://docs.python.org/3/library/os.path.html#os.path.samefile

The problem is that the debugger doesn't rely on os.stat and instead only calls os.path.abspath and os.path.normpath. This means that if a breakpoint is set in Spyder on a file loaded with some path, and then in the console the file is loaded with some other path, the breakpoints will not apply.

impact27 commented 6 months ago

To reproduce on unix:

create a file containing

def fun(a):
    a = a + 1
    print(a)

and save it as a.py. Place a breakpoint on the second line

In a terminal: mkdir folder ln a.py folder/a.py

change the working directory to folder

then execute

from a import fun %debug fun(0)

The debugger will not see any breakpoint in folder/a.py but will see breakpoints in a.py, even though it is the same file (in this example through a hard link)