uv icon indicating copy to clipboard operation
uv copied to clipboard

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

Open jamesbraza opened this issue 1 year ago • 14 comments

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)

jamesbraza avatar Apr 25 '24 20:04 jamesbraza

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

charliermarsh avatar Apr 25 '24 23:04 charliermarsh

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

charliermarsh avatar Apr 25 '24 23:04 charliermarsh

Lol give in to your temptations 😈 🔥 🚀 🦾 😆

jamesbraza avatar Apr 25 '24 23:04 jamesbraza

Is that "breaking" ?

zanieb avatar Apr 25 '24 23:04 zanieb

I'd consider it breaking.

charliermarsh avatar Apr 25 '24 23:04 charliermarsh

Would we support $PWD too or whatever?

zanieb avatar Apr 25 '24 23:04 zanieb

I believe we already do.

charliermarsh avatar Apr 25 '24 23:04 charliermarsh

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

charliermarsh avatar Apr 25 '24 23:04 charliermarsh

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?

charliermarsh avatar Apr 25 '24 23:04 charliermarsh

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...

zanieb avatar Apr 26 '24 01:04 zanieb

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.

charliermarsh avatar Apr 26 '24 02:04 charliermarsh

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

zanieb avatar Apr 26 '24 02:04 zanieb

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

jamesbraza avatar Apr 26 '24 17:04 jamesbraza

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

charliermarsh avatar Apr 27 '24 12:04 charliermarsh

We'll ship this in v0.3.0.

charliermarsh avatar Jun 01 '24 16:06 charliermarsh