This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: py to pyc location mapping with sys.pycache_prefix isn't 1-to-1 on Windows
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benrg, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2022-02-24 03:41 by benrg, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg413878 - (view) Author: (benrg) Date: 2022-02-24 03:41
`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.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90998
2022-02-24 03:41:44benrgcreate