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

If pygments is installed, produce colorized json output by default. #10

Closed
wants to merge 1 commit into from

Conversation

aisipos
Copy link

@aisipos aisipos commented Dec 24, 2012

Fall back to standard uncolorized output if pygments is not installed.

@aisipos
Copy link
Author

aisipos commented Dec 24, 2012

Slight update to ensure pygments has json support before using it. Older versions of pygments didn't have json support until https://github.com/orb/pygments-json was merged.

#Also ensure the JSON lexer is installed.
#Old versions of pygments don't have this installed,
#it's available separately as pygments-json
lexer = pygments.lexers.get_lexer_by_name('json')
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the JSON lexer is not installed? Does get_lexer_by_name throw an ImportError?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, indeed you are right. get_lexer_by_name throws a pygments.util.ClassNotFound when the given lexer is not found (see http://pygments.org/docs/api/).

I updated the PR to catch any exception when trying to use pygments, falling back to the straight JSONFormatter if anything exception arise.

@aisipos
Copy link
Author

aisipos commented Jan 8, 2013

Updated PR to catch all errors when trying to use the pygments JSON lexer, as throws its own exceptions rather than ImportError if it can't find a specific lexer.

@aisipos
Copy link
Author

aisipos commented Feb 10, 2013

Updated PR to fix compatibility with Python 3 - Travis build now passes. Also rebased on top of latest commit to develop branch.

@danpritts
Copy link

It would be nice to have Pygments be automatically installed when i pip install aws-cli

@aisipos
Copy link
Author

aisipos commented Mar 26, 2013

It would be easy to make pygments a dependency for aws-cli. But it's also a judgement call by the maintainers, it makes the install a bit heavier and isn't a requirement. @garnaat : Do you think this PR is useful, and what are your thoughts on a pygments dependency?

@danpritts
Copy link

Tough call, I agree. But I never would have heard of pygments had i not come here to file a different bug. Not sure what the right way to deal with it is; can pip ask if you want to install optional dependencies? That would probably be ideal.

@aisipos
Copy link
Author

aisipos commented Mar 26, 2013

No, pip doesn't provide user prompted optional dependencies. Prompting the user would only confuse them anyway - the library should make a reasonable choice for devs - whether to provide it or not. The docs can state they can get colored output merely by doing a pip install pygments

@ches
Copy link

ches commented May 8, 2013

I'd like this feature but my 2 cents would be to leave it optional. I typically have pygments installed on development workstations (for Sphinx documentation among other things), but could do without the extra download/package on servers.

Speaking of servers, for scripting I humbly request that this patch be enhanced to not colorize if I'm piping, redirecting output to a file, etc. (check sys.stdout.isatty()). Nobody likes to fight ANSI escape codes where they shouldn't be 😃

Fall back to standard uncolorized output if pygments is not installed.
Only output colorized json if output is a tty
@aisipos
Copy link
Author

aisipos commented May 21, 2013

I rebased the PR to the head of the develop branch, and changed it so that colorized output is only produced when writing to a stream that .isatty(). Thanks for the suggestion, that should have been the correct behavior the whole time.

Pygments support is indeed optional. If you don't have pygments installed with this PR, it will fall back to straight uncolorized output.

@ches
Copy link

ches commented May 22, 2013

👍

@swrobel
Copy link

swrobel commented Nov 18, 2013

👍

@JordonPhillips JordonPhillips added pr:needs-review This PR needs a review from a Member. and removed pr:needs-review This PR needs a review from a Member. labels May 17, 2016
@JordonPhillips
Copy link
Member

Closing this out since this isn't the way we want to go with this feature. Feature request located at #2123.

kdaily referenced this pull request in kdaily/aws-cli Apr 15, 2021
Implement copy method for transfer manager
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.

None yet

6 participants