Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Constraints for generating first uv.lock when migrating #6425

Closed
mrcljx opened this issue Aug 22, 2024 · 4 comments
Closed
Labels
question Asking for clarification or support

Comments

@mrcljx
Copy link

mrcljx commented Aug 22, 2024

When migrating from Poetry (or other solutions) I want to ensure that the generated uv.lock does not accidentally upgrade any packages.

The docs say:

If resolution output file exists, i.e. a uv lockfile (uv.lock) or a requirements output file (requirements.txt), uv will prefer the dependency versions listed there.

So what I assumed would work is:

  1. Transform poetry dependencies (wrote a small script).
  2. Export a requirements.txt from poetry.lock via poetry export.
  3. Run uv lock

Sadly that didn't work (docs might be confusing here, I guess the latter just works with uv pip). I then assumed that maybe I can do:

uv lock --constraint requirements.txt

But that option does not exist.

What seems to have worked is to generate a fake uv.lock from my script, but I'm also not sure whether that really worked: I get a log statement that the lockfile is ignored because requires-dist doesn't match (I'm not generating that one).

It would be great if I could somehow provide constraints to uv lock. Or am I'm overlooking some existing feature?

@charliermarsh
Copy link
Member

I think you could take the output of that requirements.txt, and add it to the pyproject.toml under constraint-dependencies

[project]
name = "foo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = ["anyio"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
constraint-dependencies = [
    "anyio==3"
]

Then run uv lock. Then remove the constraint-dependencies and run uv lock again, and it should preserve the versions to the extent that it can.

@charliermarsh charliermarsh added the question Asking for clarification or support label Aug 22, 2024
@zanieb
Copy link
Member

zanieb commented Aug 22, 2024

Feel free to open again if that's not working for you.

@mrcljx
Copy link
Author

mrcljx commented Aug 22, 2024

Worked like a charm. 👍

@charliermarsh
Copy link
Member

That's awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

3 participants