python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.89k stars 2.28k forks source link

poetry install generated .pth files don't use drive letter for mapped network drives #8935

Open slingshotvfx opened 10 months ago

slingshotvfx commented 10 months ago

Issue

possibly related to https://github.com/python-poetry/poetry/issues/4327 https://github.com/python-poetry/poetry/issues/959

I have a poetry project on a mapped network drive (z:) in Windows. When I run poetry install, the .venv\Lib\site-packages\app.pth file that is created uses the UNC path instead of the drive path:

app.pth
//server/share/app

But it should be:

Z:\app

This specifically caused problems for me because both the UNC path and the Z:\ path ended up in sys.path in my virtualenv:

Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
>>> import sys
>>> sys.path
['Z:\\app\\.venv', 'Z:\\app\\.venv\\Lib\\site-packages', '\\\\server\\share\\app']

This slowed Pylance to a crawl in VS Code. Might be a bug in Pylance but it basically made it re-index my project continually, as it presumably tried to reconcile duplicate search paths.

Manually changing the app.pth path to use Z:\ and restarting VS Code fixed all issues.

Curiously, direct_url.json appears to use the correct path:

.venv/Lib/site-packages/app-0.0.1-dist-into/direct_url.json
{"dir_info": {"editable": true}, "url": "file:///Z:/app"}
dimbleby commented 10 months ago

are you telling us that z:\app and \\server\app are equivalent?

if so this definitely seems like a pylance problem.

code is here if you want to propose a change.

But I dont see how you can expect to fix this in poetry without "breaking" it for the next person who has things the other way round: if they already have \\server\app in their path then what you want to do will just put them in the same spot that you are now in.

Advise that if pylance has a problem that makes it go super slowly then this is better reported to pylance.

slingshotvfx commented 10 months ago

Yes, in this example \\server is mapped to z:\ (actually should be \\server\share mapped to z:\, fixed in my original post)

Pylance issues aside, I think Poetry should at least generate paths consistently for mapped network drives.

This line: https://github.com/python-poetry/poetry/blob/776fcb8ae3ea76a9e7681054034613ca440c7e9a/src/poetry/masonry/builders/editable.py#L111

uses Path.resolve() which resolves to a UNC path in windows (//server/share), while:

https://github.com/python-poetry/poetry/blob/776fcb8ae3ea76a9e7681054034613ca440c7e9a/src/poetry/masonry/builders/editable.py#L237

uses Path.absolute() which maintains the mapped drive letter (z:\).

from pathlib import Path

print("resolve:", Path(__file__).resolve().as_posix())
print("absolute:", Path(__file__).absolute().as_uri())
resolve: //server/storage/dev/paths.py
absolute: file:///Z:/dev/paths.py

I think ideally poetry would use .absolute() in both places, although I'm not familiar with the code to know if that would effect anything else.

dimbleby commented 10 months ago

feel free to submit a merge request, imo this is unimportant but if you can make the case that it matters then go for it!