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(python list): added --format param to uv python list #10448

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jzlotek
Copy link

@jzlotek jzlotek commented Jan 9, 2025

Summary

I use uv for automation on remote hosts and it would be useful to have it be able to tell me the supported versions of python (for the remote machine) in a machine readable manner so I do not need to parse uv python list.

This change adds --format (json|text) to uv python list to make it's output machine readable

Loosely related:

Test Plan

Manually tested via

# quick inspection without pretty print
cargo run -- python list --format json

Short example of output (trimmed down)

Cmd: cargo run -- python list --format json | jq '.[:2]'

[
  {
    "key": "cpython-3.13.1+freethreaded-linux-x86_64-gnu",
    "version": "3.13.1",
    "path": null,
    "symlink": null,
    "url": "https://github.com/astral-sh/python-build-standalone/releases/download/20241219/cpython-3.13.1%2B20241219-x86_64-unknown-linux-gnu-freethreaded%2Bpgo%2Blto-full.tar.zst",
    "os": "linux",
    "variant": "freethreaded",
    "implementation": "cpython",
    "arch": "x86_64",
    "libc": "gnu"
  },
  {
    "key": "cpython-3.13.1-linux-x86_64-gnu",
    "version": "3.13.1",
    "path": "/usr/bin/python3.13",
    "symlink": null,
    "url": null,
    "os": "linux",
    "variant": "default",
    "implementation": "cpython",
    "arch": "x86_64",
    "libc": "gnu"
  }
]

@zanieb zanieb requested review from Gankra and zanieb January 9, 2025 22:22
Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

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

Everything looks good except one detail. Although not 100% confident on if there's any fields that would be "bad" to expose since machine-readable outputs are ideally making a stronger guarantee of stable output.

Comment on lines +192 to +194
Either::Left(path) => {
let is_symlink = fs_err::symlink_metadata(path).unwrap().is_symlink();
if is_symlink {
Copy link
Contributor

Choose a reason for hiding this comment

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

afaict these 3 paths only differ by one field each. I'd like to see this refactored to just compute the 2 special fields and then make one PrintData at the end.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah you're right! I'll make that adjustment. Thanks for the pointer.

@jzlotek
Copy link
Author

jzlotek commented Jan 10, 2025

Everything looks good except one detail. Although not 100% confident on if there's any fields that would be "bad" to expose since machine-readable outputs are ideally making a stronger guarantee of stable output.

I'll think about it. The only thing I can think of adding that is probably worthwhile is to add the version parts. Thoughts? I am not super familiar with the api as this is my first time doing rust/uv work so any suggestions would be appriciated

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

Successfully merging this pull request may close these issues.

2 participants