Skip to content

feat(uv): Experimental UV support POC #1631

Draft
harshitbansal184507 wants to merge 2 commits into
hermetoproject:mainfrom
harshitbansal184507:feat/uv
Draft

feat(uv): Experimental UV support POC #1631
harshitbansal184507 wants to merge 2 commits into
hermetoproject:mainfrom
harshitbansal184507:feat/uv

Conversation

@harshitbansal184507

Copy link
Copy Markdown
Contributor

No description provided.

@a-ovchinnikov a-ovchinnikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, please find some initial comments inline.

Comment thread hermeto/core/package_managers/uv/main.py
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

Comment thread hermeto/core/package_managers/uv/models.py
{**package, "source": _normalize_source(package["source"])}
if isinstance(package, Mapping) and isinstance(package.get("source"), Mapping)
else package
for package in data.get("package", [])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants