astral-sh / uv

An extremely fast Python package installer and resolver, written in Rust.
https://astral.sh/
Apache License 2.0
11.73k stars 321 forks source link

Bug (?): `PACKAGE_ROOT` not working one level up #3271

Open jamesbraza opened 2 weeks ago

jamesbraza commented 2 weeks ago

I have a setuptools.build_meta backend monorepo with a pyproject.toml package named packagename in a subfolder. I specify its dependency in a requirements.txt at the repo root: package-name @ file://${PROJECT_ROOT}/packagename

In /Users/user/code/repo-root, running uv pip install --no-cache . works fine.

Moving up one directory to /Users/user/code and running uv pip install --no-cache ./repo fails:

error: Distribution not found at: file:///Users/user/code/packagename

Can we somehow know PROJECT_ROOT should be ./repo, instead of ./ in this case?


I am using uv 0.1.38 (0b23caa18 2024-04-24)

charliermarsh commented 2 weeks ago

Hmm, right now PROJECT_ROOT is just the current working directory.

charliermarsh commented 2 weeks ago

Slightly tempted to set it to the directory of the containing file.

jamesbraza commented 2 weeks ago

Lol give in to your temptations 😈 🔥 🚀 🦾 😆

zanieb commented 2 weeks ago

Is that "breaking" ?

charliermarsh commented 2 weeks ago

I'd consider it breaking.

zanieb commented 2 weeks ago

Would we support $PWD too or whatever?

charliermarsh commented 2 weeks ago

I believe we already do.

charliermarsh commented 2 weeks ago

We support any env var, and then PROJECT_ROOT is special on top of those.

charliermarsh commented 2 weeks ago

Using the directory that contains the file definitely seems right for pyproject.toml. I could see it being less convenient for requirements.txt in some rare cases?

zanieb commented 2 weeks ago

Yeah the latter seems more problematic, e.g. requirements/dev.txt — but it seems quite correct for pyproject.toml.

I wonder if we should scan for git boundaries for requirements.txt...

charliermarsh commented 2 weeks ago

Yeah the latter seems more problematic, e.g. requirements/dev.txt — but it seems quite correct for pyproject.toml.

Yeah. Is it even that bad though? It just means you need to make the path relative to the file rather than the root directory. But it would still work consistently regardless of where you invoked uv from, unlike the current implementation.

zanieb commented 2 weeks ago

I'm curious if anyone else will weigh in, but yeah having it work consistently seems like an improvement.

jamesbraza commented 2 weeks ago

Maybe PACKAGE_ROOT can have a fallback (or a configuration option --package-root-is-not-cwd) to maintain compatibility:

  1. Looks in target directory (in this case, ./repo)
  2. Falls back on current working directory

That being said, imo the most straightforward/intuitive route is to support two environment variables:

# Uses input uv command to resolve to ./repo/foo
file://${PROJECT_ROOT}/foo

# Always resolves to ./foo
file://${CURRENT_DIRECTORY}/foo
charliermarsh commented 2 weeks ago

For ${CURRENT_DIRECTORY} you can likely already do ${PWD}.