astral-sh / uv

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

Allow `uv sync --no-install-project` without relying on `pyproject.toml` #6573

Open albertferras-vrf opened 3 weeks ago

albertferras-vrf commented 3 weeks ago

I'm trying the new feature in today's 0.3.3 release: uv sync --no-install-project but I could not make it work since it keeps failing because pyproject.toml file is not found

The full Dockerfile example provided in the documentation here https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers does not work and raises this error too

charliermarsh commented 3 weeks ago

Apologies, does it work if you copy over the pyproject.toml? It might be relying on discovering it but not actually reading from it. Will fix.

albertferras-vrf commented 3 weeks ago

Yes, it works after copying pyproject.toml. However, it seems like it tries to read it because after creating an empty one (touch pyproject.toml) then uv sync fails with 0.092 error: Noprojecttable found in:/opt/app/pyproject.toml``

charliermarsh commented 3 weeks ago

Yes it reads it to discover the project name, so it can pick out the right dependency tree in the lockfile.

charliermarsh commented 3 weeks ago

But it does not require the project contents which is the critical piece that would ruin caching.

charliermarsh commented 3 weeks ago

(The docs are incorrect though.)

albertferras-vrf commented 3 weeks ago

What happens if the project has multiple packages (using workspaces), do I need to copy all other pyproject.toml files too?

charliermarsh commented 3 weeks ago

Let me test it before I try to answer confidently.

charliermarsh commented 3 weeks ago

Yes, but I think we can fix that part.

charliermarsh commented 3 weeks ago

I updated the documentation (and added test coverage) for now. We'll follow-up with some other changes.

albertferras-vrf commented 3 weeks ago

thank you @charliermarsh !

One suggestion: Maybe we can consider storing the root (?) project name in uv.lock so that pyproject.toml is not needed. it would make it slightly easier to have a working Dockerfile

charliermarsh commented 3 weeks ago

I think we probably can. Just trying to decide if we should. It creates some weirdness if we don't use the pyproject.toml to discover the root directory, etc.

jaklan commented 3 weeks ago

@charliermarsh I don't know low-level differences between uv and pdm, just to mention the latter is able to update venv without pyproject.toml with the below command:

pdm sync --no-self

Btw, what is a difference between these two flags?

      --locked                                   Assert that the `uv.lock` will remain unchanged
      --frozen                                   Sync without updating the `uv.lock` file
zanieb commented 2 weeks ago

@jaklan you can see the extended documentation at https://docs.astral.sh/uv/reference/cli/#uv-sync or uv help sync.

jaklan commented 2 weeks ago

@zanieb thanks, I haven't noticed docs contain extended version of options' help messages (I used uv sync --help)

zanieb commented 2 weeks ago

The end of uv sync --help suggests the longer option and we cover this at https://docs.astral.sh/uv/getting-started/help/ — let me know if there's anything more we can do to emphasize that it's available though!

jaklan commented 2 weeks ago

@zanieb ach lol, haven't noticed the footer at all 😄 Maybe you can make it bold:

Use uv help sync for more details.

or put at the top:

❯ uv sync --help Update the project's environment

Note: Use uv help sync for more detailed help.

Usage: uv sync [OPTIONS] ...

but generally - it was simply my bad, I was just quickly testing uv and haven't got familiar with the CLI and docs yet

charliermarsh commented 2 weeks ago

The biggest hangup to doing this is that you lose any configuration specified in the pyproject.toml, which feels like a footgun.