feat(uv): Experimental UV support POC #1631
Conversation
a-ovchinnikov
left a comment
There was a problem hiding this comment.
This is a good start, please find some initial comments inline.
| name, version = _get_pyproject_metadata(package_dir) | ||
|
|
||
| _validate_lockfile(package_dir) | ||
| log.info("uv.lock validated for %s (name=%s version=%s)", package_dir, name, version) |
There was a problem hiding this comment.
A nitpick: I would suggest keeping such logs within functions that do validation. Also note, that here, on the happy path, you mention both package name and version despite the fact that this information is not really interesting to an operator: a validation succeeded after all, no need to spend any more time on this package. In _validate_lockfile(), on the other hand, you don't mention neither name-version, nor even path to the package, at least not explicitly. WDYT about moving the log messages and do a bit richer reporting on failures? (Also note, that solution recommends updating pyproject.toml, while technically correct in many cases the file is not controlled by a user, so I doubt the usefulness of this solution.)
| {**package, "source": _normalize_source(package["source"])} | ||
| if isinstance(package, Mapping) and isinstance(package.get("source"), Mapping) | ||
| else package | ||
| for package in data.get("package", []) |
There was a problem hiding this comment.
Please consider naming these statements, it is very non-obvious what is happening here. The rule of thumb for comprehensions is like this: if it has to occupy more than one line then it is either lacking proper helpers or should better be a regular loop.
Here something along the lines of
normalize_package = lambda p: {**p, "source": _normalize_source(package["source"])}
well_formed = lambda p: isinstance(p, Mapping) and isinstance(p.get("source"), Mapping)
packages = [normalize_package(p) if well_formed(p) else p for p in data.get("package", [])]Another optional suggestion: {**foo, bar: baz} is a neat trick, however WDYT about being more explicit, i.e. about using {**foo} | {bar: baz} instead?
|
|
||
| uv.lock records the source as a single-key mapping, one key per kind, e.g. | ||
| ``{"registry": "https://pypi.org/simple"}`` or ``{"git": "https://...#sha"}``. | ||
| Collapse it into the explicit ``{"kind": ..., "location": ...}`` form the |
There was a problem hiding this comment.
Are you sure this procedure should be called "collapse"? I would expect a collapsed representation to be smaller rather than bigger then the original one.
| return {"kind": kind, "location": raw[kind]} | ||
|
|
||
|
|
||
| def _normalize_lock(data: Any) -> Any: |
There was a problem hiding this comment.
Have you considered making this a before validator instead?
Wire up the experimental x-uv package manager so uv-managed projects can be requested via the CLI. This adds the UvPackageInput model and the x-uv type, registers the handler in the resolver, and provides a fetch_uv_source to be filled in incrementally. It is marked experimental (x-uv). Issue: hermetoproject#1142 Design: hermetoproject#1564 Signed-off-by: Harshit Bansal <harshitbansal184507@gmail.com>
Signed-off-by: Harshit Bansal <harshitbansal184507@gmail.com>
a3f0396 to
91aaf3e
Compare
No description provided.