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
Change option --color
choices to auto/always/never
#1701
Changes from 8 commits
7dfd9ca
381eecb
3ed593b
d9f6a39
f24104e
f5897cd
d8c1ade
34749a3
0caeab5
5492aab
750d15a
3eae210
544563f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,17 @@ | |
from vsc.utils import fancylogger | ||
from vsc.utils.generaloption import GeneralOption | ||
|
||
try: | ||
from humanfriendly.terminal import terminal_supports_colors | ||
except ImportError: | ||
# provide an approximation that should work in most cases | ||
def terminal_supports_colors(stream): | ||
try: | ||
return os.isatty(stream.fileno()) | ||
except Exception: | ||
# in case of errors do not bother and just return the safe default | ||
return False | ||
|
||
|
||
CONFIG_ENV_VAR_PREFIX = 'EASYBUILD' | ||
|
||
|
@@ -142,6 +153,24 @@ def pretty_print_opts(opts_dict): | |
print '\n'.join(lines) | ||
|
||
|
||
def use_color(colorize, stream=sys.stdout): | ||
""" | ||
Return ``True`` or ``False`` depending on whether ANSI color | ||
escapes are to be used when printing to `stream`. | ||
|
||
The `colorize` argument can take the three string values | ||
``'auto'``/``'always'``/``'never'``, see the ``--color`` option | ||
for their meaning. | ||
""" | ||
# turn color=auto/yes/no into a boolean value | ||
if options.color == 'auto': | ||
return terminal_supports_colors(stream) | ||
elif options.color == 'always': | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
class EasyBuildOptions(GeneralOption): | ||
"""Easybuild generaloption class""" | ||
VERSION = this_is_easybuild() | ||
|
@@ -258,7 +287,7 @@ def override_options(self): | |
None, 'store_true', False), | ||
'cleanup-builddir': ("Cleanup build dir after successful installation.", None, 'store_true', True), | ||
'cleanup-tmpdir': ("Cleanup tmp dir after successful run.", None, 'store_true', True), | ||
'color': ("Allow color output", None, 'store_true', True), | ||
'color': ("Colorize output", 'choice', 'store', 'auto', ['auto', 'always', 'never'], {'metavar':'WHEN'}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since enabling this requires having also, changing this may break people's configuration files, since they may specify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Kenneth Hoste, Fri, Mar 25, 2016 at 03:44:00PM -0700:)
No it doesn't -- if you don't have the required packages, it will
Good point, but how to I do that with vsc's option parsing framework? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually, I would translate the other way round:
|
||
'default-opt-level': ("Specify default optimisation level", 'choice', 'store', DEFAULT_OPT_LEVEL, | ||
Compiler.COMPILER_OPT_FLAGS), | ||
'deprecated': ("Run pretending to be (future) version, to test removal of deprecated code.", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,11 @@ def find_rel_test(): | |
], | ||
extras_require = { | ||
'yeb': ["PyYAML >= 3.11"], | ||
'coloredlogs': [ | ||
'vsc-base[coloredlogs] >= 2.5.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @riccardomurri please bump to 2.5.3 as minimal required version |
||
'coloredlogs', | ||
'humanfriendly', # determine whether terminal supports ANSI color | ||
], | ||
}, | ||
namespace_packages=['easybuild'], | ||
) |
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.
@riccardomurri this should use
colorize
rather thanoptions.color
?