astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.16k stars 598 forks source link

Relative paths in script sources don't work #7292

Closed SnirShechter closed 5 days ago

SnirShechter commented 6 days ago

The error

PS C:\whatever> uv run .\scripts\myscript.py
Reading inline script metadata from: .\scripts\myscript.py
error: path could not be converted to a URL: libs\mypackage

image

In short

Script sources ([tool.uv.sources]) use full paths, do not allow for relative paths e.g. ../libs/mypackage and are thus not platform-agnostic and can't be used by multiple developers.

In depth

Consider this script:

from mypackage import hello

hello("John")

Running uv add --script myscript.py ./libs/mypackage --editable results in this:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "mypackage",
# ]
#
# [tool.uv.sources]
# mypackage = { path = 'C:\whatever\libs\mypackage', editable = true }
# ///
from mypackage import hello

hello("John")

But obviously C:\... is not platform agnostic, so to make it work for all developers I need to change it to ..\libs\mypackage, but that doesn't work (see the error above)

charliermarsh commented 6 days ago

Thanks, these look like bugs.