`importlib._bootstrap_external` contains this comment:
# We need an absolute path to the py file to avoid the possibility of
# collisions within sys.pycache_prefix [...]
# [...] the idea here is that if we get `Foo\Bar`, we first
# make it absolute (`C:\Somewhere\Foo\Bar`), then make it root-relative
# (`Somewhere\Foo\Bar`), so we end up placing the bytecode file in an
# unambiguous `C:\Bytecode\Somewhere\Foo\Bar\`.
The code follows the comment, but doesn't achieve the goal: `C:\Somewhere\Foo\Bar` and `D:\Somewhere\Foo\Bar` collide. There is also no explicit handling of UNC paths, with the result that `\\Somewhere\Foo\Bar` maps to the same location.
I think that on Windows the code should use a mapping like
C:\Somewhere\Foo\Bar ==> C:\Bytecode\C\Somewhere\Foo\Bar
D:\Somewhere\Foo\Bar ==> C:\Bytecode\D\Somewhere\Foo\Bar
\\Somewhere\Foo\Bar ==> C:\Bytecode\UNC\Somewhere\Foo\Bar
The lack of double-slash prefix handling also matters on Unixy platforms that give it a special meaning. Cygwin is probably affected by this. I don't know whether there are any others.
|