-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add option to format output of the cli as json #81
Conversation
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.
Thanks for the patch! I suggest we return a proper python dictionary object from to_dict
method and call json.dumps
before passing it logger.info
.
@@ -68,6 +68,9 @@ def localize_date(self, date): | |||
date = utc.localize(date) | |||
return date.astimezone(PST_TIMEZONE) | |||
|
|||
def to_dict(self): |
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.
this method name is a little bit misleading since it's returning a str representation of json not a python dictionary object.
floyd/cli/experiment.py
Outdated
@@ -171,6 +187,12 @@ def output(id, url, download): | |||
if "output" in task_instance.output_ids: | |||
output_dir_url = "{}/api/v1/resources/{}?content=true".format(floyd.floyd_host, | |||
task_instance.output_ids["output"]) | |||
if format == 'json': | |||
experiment_dict = json.loads(experiment.to_dict()) |
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.
it's doing double encoding/decoding here. a better way to do it is to get the dictionary, add the output_dir_url key, then serialize to json string at the end.
floyd/cli/experiment.py
Outdated
print_experiments([experiment]) | ||
else: | ||
experiments = ExperimentClient().get_all() | ||
if format == 'json': | ||
floyd_logger.info([e.to_dict() for e in experiments]) |
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.
string representation of python object is not the same the json string serialization spec. we should be calling json.dumps()
on the python list object instead.
Looks good to me 👍 |
Done 👍 |
What we have done instead is directly using floyd API in our app. Can we just add
|
Sorry for the delay. I missed the github notification. Yes, using client seems like a better approach. Feel free to remove the format code in this case. |
As per #76