JSON output format for Pants options

Review Request #4113 — Created July 22, 2016 and submitted

echuba
pants
3161
pants-reviews
nhoward_tw, peiyu, stuhood, wisechengyi, zundel

Allows Pants options to be printed in formatted JSON. Each value stores a dict containing source, value, and optionally history keys.

Call: ./pants options --output-format=json
Output:

{
  ...
  "bench.jvm_options": {
    "source": "CONFIG", 
    "value": "['-Xmx1g', '-XX:MaxPermSize=256m']"
  }, 
  "bench.memory": {
    "source": "HARDCODED", 
    "value": "False"
  },
  ...
}

Call: ./pants options --output-format=json --show-history
Output:

{
  ...
  "bench.jvm_options": {
    "history": [
      "overrode (u\"REPLACE +[u'-Xmx1g', u'-XX:MaxPermSize=256m'] -[]\", u'CONFIG')", 
      "overrode (u\"REPLACE +[u'-Xmx256m'] -[]\", u'HARDCODED')"
    ], 
    "source": "CONFIG", 
    "value": "['-Xmx1g', '-XX:MaxPermSize=256m']"
  }, 
  "bench.memory": {
    "history": [], 
    "source": "HARDCODED", 
    "value": "False"
  }, 
  ...
}

Travis: https://travis-ci.org/ebubae/pants/builds/147534348

  • 0
  • 0
  • 4
  • 0
  • 4
Description From Last Updated
  1. please add test case

  2. --output-format would be more flexible and align with other tasks like

    --dependees-output-format=<str> (one of: [text, json] default: 'text')
        Output format of results.
    
  3. 
      
  1. The changes look good! I have just 1 question.

  2. src/python/pants/core_tasks/explain_options_task.py (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    Previously, we use value_color for value and rank_color for rank. In this review, in json format, you use rank_color for both value and rank, while in non-json format, you use rank_color for value, and no color specified for rank (except "details" part, which is in rank_color).

    Is there a particular reason for this change of behavior in output color?

    1. Why add colors at all for JSON? JSON is intended for machine reading. Just seems like something that could mess up if you don't specify --no-colors

  3. 
      
  1. +1 to the request for tests. I've got some JSON formatting comments below.

  2. JSON uses double quotes for string delimiting. Please change the quotes.

  3. We should make sure these values are properly escaped. Option values can contain quotes, brackets or braces.

    Running them through json.dumps or something would do the right thing.

  4. The history should be JSON-ified too.

  5. 
      
  1. 
      
  2. You should spot check a few values in the JSON.

  3. 
      
  1. Ship It!
  2. 
      
  1. Ship It!
  2. 
      
  1. Ship It!
  2. 
      
Review request changed

Status: Closed (submitted)

Change Summary:

Merged as c7f6093381d6f838ed6e600c35f69f8bee013c62

Loading...