astral-sh / uv

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

Add feature flag to disable new lock file features (PEP 751) #6463

Closed ketozhang closed 2 weeks ago

ketozhang commented 2 weeks ago

I'm not ready to use the new lock files in my dev environment. I need to heavily rely on pip-compile style lock files (uv sync requirements.in).

Is there any way to not be affected by the uv.lock (not sure what the existence of that file implies for other uv commands).

charliermarsh commented 2 weeks ago

If you use the pip API, there's no impact. But you can't use uv sync or uv lock without uv.lock. (Note that uv.lock is not the same as PEP 751, which is not yet finished or accepted.)

zanieb commented 2 weeks ago

Yeah, I'd recommend just using uv pip sync instead of the top-level interface.

ketozhang commented 2 weeks ago

@charliermarsh Your response speed amazing ❤️! @zanieb (and you! I didn't get a chance to type this)

Doesn't the lock file affect uv run (docs)? I think uv run python is something I started to use in place of .venv/bin/python (or activate -> python).


Gotcha, will try to move remember to always use uv pip.

zanieb commented 2 weeks ago

uv run will always create and use a lockfile in a project, yeah. I presume you have a pyproject.toml?

zanieb commented 2 weeks ago

Actually you can use uv run --no-project and we will ignore any pyproject.toml files

ketozhang commented 2 weeks ago

I presume you have a pyproject.toml?

Yes.

For now, I'm thinking about the project workflow:

$ cd /path/to/project

$ uv venv                               # Optional and redundant to next command (old habit)
$ uv pip sync dev-requirements.txt      # OR uv pip install -r ...

# Run project environment's python == .venv/bin/python
$ uv run python
zanieb commented 2 weeks ago

Yep! Makes sense. If you do uv run --no-project python we will read the .venv we just will ignore the pyproject.toml (and uv.lock)

zanieb commented 2 weeks ago
❯ uv init
Initialized project `example`
❯ uv venv
Using Python 3.11.7
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
❯ uv pip install httpx
Resolved 7 packages in 201ms
Installed 7 packages in 19ms
 + anyio==4.4.0
 + certifi==2024.7.4
 + h11==0.14.0
 + httpcore==1.0.5
 + httpx==0.27.0
 + idna==3.7
 + sniffio==1.3.1
❯ uv run --no-project python -c "import httpx"
❯ tree .
.
├── README.md
├── pyproject.toml
└── src
    └── example
        └── __init__.py

(Note we don't create a uv.lock)

zanieb commented 2 weeks ago

You can also just do

[tool.uv]
managed = false

if you never want to use uv sync and uv lock

ketozhang commented 2 weeks ago

managed = false

Oh, same as rye. That solves it as a quasi-feature flag. Thank you!

zanieb commented 2 weeks ago

Adding documentation for this in https://github.com/astral-sh/uv/pull/6465