uv icon indicating copy to clipboard operation
uv copied to clipboard

Very large lockfile and clean up

Open jbcdnr opened this issue 2 months ago • 9 comments

We noticed that our uv.lock file grows in size, up to 2.5MB and 35k lines with a lot of resolution-markers and the time to uv lock explodes to more than 30 min and sometimes OOM. We have a pretty bad hygien for our pyproject.toml with a lot of * versions and some conflicts so the resolver might have a hard time.

We came up with a simple script to extract all the versions from the lockfile and copy paste them into pyproject.toml, then rerun lock and revert pyproject right after. This speeds up the follow up lock calls and make the lock file only 0.4MB big. Is it expected behavior? Is our cleanup script actually something that exists as part of the uv command?

import pathlib
import re

content = pathlib.Path("uv.lock").read_text()

print("dependencies = [")
for package_version_match in re.finditer(
    r'name = "([^"]+)"\nversion = "([\d\.]+)"', content
):
    package_name, package_version = package_version_match.groups()
    print(f'    "{package_name}=={package_version}",')
print("]")

Thank you for your help.

jbcdnr avatar Dec 09 '24 09:12 jbcdnr