-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Provide structured JSON output for pip index versions
#13194
base: main
Are you sure you want to change the base?
Provide structured JSON output for pip index versions
#13194
Conversation
pip index versions
|
||
write_output(json.dumps(structured_output)) | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be structured as follows:
if options.json:
...
else:
...
rather than
if options.json:
...
return
...
as the former is (IMO) easier to read.
I'm also slightly uncomfortable with the fact that we're duplicating the lookup of dist
here and in print_dist_installation_info
. Ideally, I'd like to see this refactored to remove the duplication. But it's not a showstopper, and if you prefer it could be deferred to a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done the first suggested change - I agree it reads nicer.
Regarding the second one - I also felt a bit uncomfortable with the duplicated lookup, but I wanted to keep the PR small
src/pip/_internal/commands/search.py
Outdated
def print_dist_installation_info(name: str, latest: str) -> None: | ||
env = get_default_environment() | ||
dist = env.get_distribution(name) | ||
def print_dist_installation_info_if_exists( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no real need to add _if_exists
to the name - print_dist_installation_info(latest, dist)
seems perfectly understandable to me. Apart from this minor point, this looks good, thanks.
The first part of #13188, providing a structured JSON-formatted output for
pip index versions
command.Usage:
which is properly formatted JSON - it prettifies to: