pypa/pip — pull request #380 by whitmo (2011-11-01 20:23:13+00:00)
Title: JSON for freeze output

I understand there is a difference of opinion over the value of having JSON output for pip freeze, but if people are interested, here is an implementation and a test. I also did a bit of refactoring to break the run method into more manageable parts including making the writing and formatting of output into methods.

Basically I was following Carl's suggestions, and these changes were on the way to making using freeze as an api less of a reach around. For fun I went ahead and added a json output method, but that could easily be done as a subclass when using pip as an api. To allow filtering of output, I altered how the original worked to capture all the output before writing, but it would be easy to change this to toggle between writing immediately to the console or use an output formatter.

I went ahead and hooked up the rest of the options implied in the comments or code itself ( part of b8347b32 ).

The json schema is naive and does not contain all the information that freeze can output if given a requirements file as a "clue". My guess from personal experience and looking at the code in the requirements loop is that that feature doesn't get used alot, but I understand if the loss of data is considered a flaw in this implementation. I'm not particular about the schema, and would be happy to refactor this one if someone has a good design for one that captures more data.

JSON Schema
----------------------

editable:
[list of vcs url]

requirements:
{pkgname:version}

find_links
[list of urls]

indexes:
[list of urls]

Miscellaneous
--------------------

d4463ff0 and 9cca5e76 deal with a bug that crashes freeze as git returns a status code 1 if a git repo does not have an origin. I also added the working directory to the exception output for call_subprocess ( 202e69d1 ) as it make debugging much easier in the case of pip freeze where pip is peeping in lots of different directories.