Relative indexes in PEP 723 scripts are resolved against the current working directory
bug
## Summary
Relative local indexes declared in a PEP 723 script are resolved against the directory where `uv run` is invoked, rather than the directory containing the script.
So the same script can work when ran from its own directory but fail when ran by path from somewhere else
## Reproduction
```console
$ tmpdir="$(mktemp -d)"
$ mkdir -p "$tmpdir/scripts/links" "$tmpdir/elsewhere"
$ python3 - "$tmpdir/scripts/links/ok-1.0.0-py3-none-any.whl" <<'PY'
import sys
from zipfile import ZipFile
with ZipFile(sys.argv[1], "w") as wheel:
wheel.writestr("ok.py", "")
wheel.writestr(
"ok-1.0.0.dist-info/METADATA",
"Metadata-Version: 2.3\nName: ok\nVersion: 1.0.0\n",
)
wheel.writestr(
"ok-1.0.0.dist-info/WHEEL",
"Wheel-Version: 1.0\nRoot-Is-Purelib: true\nTag: py3-none-any\n",
)
wheel.writestr("ok-1.0.0.dist-info/RECORD", "")
PY
$ cat >"$tmpdir/scripts/main.py" <<'PY'
# /// script
# requires-python = ">=3.11"
# dependencies = ["ok"]
#
# [[tool.uv.index]]
# name = "local"
# url = "./links"
# format = "flat"
#
# [tool.uv.sources]
# ok = { index = "local" }
# ///
import ok
print("ok imported")
PY
$ cd "$tmpdir/scripts"
$ uv run --offline main.py
ok imported
$ cd "$tmpdir/elsewhere"
$ uv run --offline "$tmpdir/scripts/main.py"
error: Failed to read `--find-links` directory: .../elsewhere/links
Caused by: No such file or directory (os error 2)
```
## Expected behavior
`./links` is resolved relative to the directory containing `main.py`, so both invocations print:
```shell
ok imported
```
## Actual behavior
The second invocation resolves `./links` relative to the current working directory as `elsewhere/links` and fails
### Platform
Darwin 25.5.0 arm64
### Version
uv 0.12.3 (507230998 2026-08-07 aarch64-apple-darwin)
### Python version
3.14.0
1 条评论