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

NF: Add check for whether color is enabled #3407

Merged
merged 6 commits into from May 15, 2019
Merged

Conversation

@effigies
Copy link
Contributor

@effigies effigies commented May 14, 2019

Checks for interactive terminal, datalad.ui.color configuration and NO_COLOR environment variable, in that order of precedence.

Closes #3404.

@codecov
Copy link

@codecov codecov bot commented May 15, 2019

Codecov Report

Merging #3407 into 0.11.x will increase coverage by 0.03%.
The diff coverage is 98.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           0.11.x    #3407      +/-   ##
==========================================
+ Coverage   90.98%   91.02%   +0.03%     
==========================================
  Files         254      255       +1     
  Lines       33381    33441      +60     
==========================================
+ Hits        30373    30439      +66     
+ Misses       3008     3002       -6
Impacted Files Coverage Δ
datalad/interface/common_cfg.py 100% <ø> (ø) ⬆️
datalad/support/ansi_colors.py 100% <100%> (+4.54%) ⬆️
datalad/support/tests/test_ansi_colors.py 100% <100%> (ø)
datalad/interface/ls.py 68.83% <83.33%> (+0.68%) ⬆️
datalad/metadata/extractors/__init__.py 100% <0%> (ø) ⬆️
datalad/metadata/extractors/tests/__init__.py 100% <0%> (ø) ⬆️
datalad/metadata/__init__.py 100% <0%> (ø) ⬆️
datalad/support/tests/__init__.py 100% <0%> (ø) ⬆️
datalad/support/network.py 85.97% <0%> (+0.22%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63b4b8f...ae60a37. Read the comment docs.

@effigies
Copy link
Contributor Author

@effigies effigies commented May 15, 2019

Let me know if this seems like the right approach. I can add tests if you agree.

Copy link
Member

@yarikoptic yarikoptic left a comment

THANKS! Just a minor request -- add this setting to datalad/interface/common_cfg.py so we centralize its "specification" and possibly interface for specification

if not ui.is_interactive:
return False

UIC = cfg.get_value('datalad', 'ui.color', 'auto')
Copy link
Member

@yarikoptic yarikoptic May 15, 2019

Thanks!
Ideally I think we should add an item (at the end, along with datalad.ui.progressbar) to datalad/interface/common_cfg.py and use cfg.obtain('datalad.ui.color') here which would then pick up default from the common cfg definition.

@effigies
Copy link
Contributor Author

@effigies effigies commented May 15, 2019

Cool. Moving to a config option that is required to have a value made the checks much shorter. Testing is going to involve some manipulation of the config, and my reading is that setting values stores them on disk. Do you have helper functions for creating an environment with a disposable config?

effigies added 3 commits May 15, 2019
Checks for interactive terminal, datalad.ui.color configuration and
NO_COLOR environment variable, in that order of precedence.
datalad/interface/ls.py Outdated Show resolved Hide resolved
@kyleam
Copy link
Contributor

@kyleam kyleam commented May 15, 2019

Testing is going to involve some manipulation of the config, and my reading is that setting values stores them on disk. Do you have helper functions for creating an environment with a disposable config?

There's a patch_config helper you can use to override config values for tests (that doesn't involve touching the disk). For testing NO_COLOR, you could patch os.environ. There are examples of both in the codebase.

ansi_colors.color_word() does the same thing, but it decides to color
words based on the newly added ansi_colors.color_enabled(), which
consults both NO_COLOR and datalad.ui.color.
@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented May 15, 2019

Let me know if this seems like the right approach

looks good to me

@effigies
Copy link
Contributor Author

@effigies effigies commented May 15, 2019

I added unit tests for the other utilities while I was at it, though now I see from the coverage they were already being thoroughly exercised. Ah well. I can remove them if they seem excessive.

kyleam
kyleam approved these changes May 15, 2019
Copy link
Contributor

@kyleam kyleam left a comment

Looks great. Thanks.

Copy link
Contributor

@kyleam kyleam left a comment

Ah, taking another look, I think datalad.ui.color=on should force color even when is_interactive() -> False, in the same way that git diff --color (or git -c color.ui=always diff) would.

@kyleam kyleam merged commit ae60a37 into datalad:0.11.x May 15, 2019
5 checks passed
kyleam added a commit that referenced this issue May 15, 2019
@effigies effigies deleted the enh/no_color branch May 15, 2019
yarikoptic added a commit to yarikoptic/datalad that referenced this issue May 21, 2019
* origin/0.11.x: (3256 commits)
  MNT: Avoid invalid escape sequences in strings
  BF: export_to_figshare: Don't test identity of string literal
  BF(TST): do not assume user naiveness - treat any url-like looking path as a path
  BF: Check for /, \ or # in the username@hostname part while detecting SSHRI
  CHANGELOG.md: Add entry for dataladgh-3374
  BF: revert back (remove) check for path being PathRI
  BF: list annex-transfer also in cmdline opt choice for "what"
  RF: convert imports into "tupled lists" of what to import
  BF: stop relying on setup.py runtime environment using platform.dist
  CHANGELOG.md: Update for dataladgh-3407
  RF: Set precedence to datalad.ui.color, NO_COLOR, datalad.ui.ui.is_interactive
  TEST: Test ANSI colors tools directly
  ENH: ls: Replace custom logic with color_word()
  RF: Move datalad.ui.color to common_cfg
  DOC: Add Zenodo
  NF: Add check for whether color is enabled
  RF: disable wrapt workaround
  CHANGELOG.md: Update for dataladgh-3396
  DOC: log_progress: Reword cross-reference from 96b45b4
  ENH: adjust code comments
  ...
yarikoptic added a commit to yarikoptic/datalad that referenced this issue May 21, 2019
* origin/0.11.x: (3256 commits)
  MNT: Avoid invalid escape sequences in strings
  BF: export_to_figshare: Don't test identity of string literal
  BF(TST): do not assume user naiveness - treat any url-like looking path as a path
  BF: Check for /, \ or # in the username@hostname part while detecting SSHRI
  CHANGELOG.md: Add entry for dataladgh-3374
  BF: revert back (remove) check for path being PathRI
  BF: list annex-transfer also in cmdline opt choice for "what"
  RF: convert imports into "tupled lists" of what to import
  BF: stop relying on setup.py runtime environment using platform.dist
  CHANGELOG.md: Update for dataladgh-3407
  RF: Set precedence to datalad.ui.color, NO_COLOR, datalad.ui.ui.is_interactive
  TEST: Test ANSI colors tools directly
  ENH: ls: Replace custom logic with color_word()
  RF: Move datalad.ui.color to common_cfg
  DOC: Add Zenodo
  NF: Add check for whether color is enabled
  RF: disable wrapt workaround
  CHANGELOG.md: Update for dataladgh-3396
  DOC: log_progress: Reword cross-reference from 96b45b4
  ENH: adjust code comments
  ...
yarikoptic added a commit that referenced this issue May 28, 2019
0.11.5 (May 23, 2019) -- stability is not overrated

Should be faster and less buggy, with a few enhancements.

 Fixes

- [create-sibling][]  ([#3318][])
  - Siblings are no longer configured with a post-update hook unless a
    web interface is requested with `--ui`.
  - `git submodule update --init` is no longer called from the
    post-update hook.
  - If `--inherit` is given for a dataset without a superdataset, a
    warning is now given instead of raising an error.
- The internal command runner failed on Python 2 when its `env`
  argument had unicode values.  ([#3332][])
- The safeguard that prevents creating a dataset in a subdirectory
  that already contains tracked files for another repository failed on
  Git versions before 2.14.  For older Git versions, we now warn the
  caller that the safeguard is not active.  ([#3347][])
- A regression introduced in v0.11.1 prevented [save][] from committing
  changes under a subdirectory when the subdirectory was specified as
  a path argument.  ([#3106][])
- A workaround introduced in v0.11.1 made it possible for [save][] to
  do a partial commit with an annex file that has gone below the
  `annex.largefiles` threshold.  The logic of this workaround was
  faulty, leading to files being displayed as typechanged in the index
  following the commit.  ([#3365][])
- The resolve_path() helper confused paths that had a semicolon for
  SSH RIs.  ([#3425][])
- The detection of SSH RIs has been improved.  ([#3425][])

 Enhancements and new features

- The internal command runner was too aggressive in its decision to
  sleep.  ([#3322][])
- The "INFO" label in log messages now retains the default text color
  for the terminal rather than using white, which only worked well for
  terminals with dark backgrounds.  ([#3334][])
- A short flag `-R` is now available for the `--recursion-limit` flag,
  a flag shared by several subcommands.  ([#3340][])
- The authentication logic for [create-sibling-github][] has been
  revamped and now supports 2FA.  ([#3180][])
- New configuration option `datalad.ui.progressbar` can be used to
  configure the default backend for progress reporting ("none", for
  example, results in no progress bars being shown).  ([#3396][])
- A new progress backend, available by setting datalad.ui.progressbar
  to "log", replaces progress bars with a log message upon completion
  of an action.  ([#3396][])
- DataLad learned to consult the [NO_COLOR][] environment variable and
  the new `datalad.ui.color` configuration option when deciding to
  color output.  The default value, "auto", retains the current
  behavior of coloring output if attached to a TTY ([#3407][]).
- [clean][] now removes annex transfer directories, which is useful
  for cleaning up failed downloads. ([#3374][])
- [clone][] no longer refuses to clone into a local path that looks
  like a URL, making its behavior consistent with `git clone`.
  ([#3425][])
- [wtf][]
  - Learned to fall back to the `dist` package if `platform.dist`,
    which has been removed in the yet-to-be-release Python 3.8, does
    not exist.  ([#3439][])
  - Gained a `--section` option for limiting the output to specific
    sections and a `--decor` option, which currently knows how to
    format the output as GitHub's `<details>` section.  ([#3440][])

* tag '0.11.5': (96 commits)
  [DATALAD RUNCMD] make update-changelog
  Version boost and finalize CHANGELOG.md record
  ENH: new Makefile rule linkissues-changelog to link issues, which now will also be prerequisite for update-changelog
  CHANGELOG.md: Add entries for recently merged PRs
  ENH: require "distro" for python >= 3.8
  ENH: compat with python 3.8 which removed .dist -- try distro
  CLN: wtf: Remove unused (and duplicated) import
  DOC: wtf: Avoid double period in -S's description
  ENH: -D|--decor html_details -- to make it ready for pasting to github issue without clutter
  BF: assure bytes while giving to pyperclip upon its demand (on Py2)
  RF: move always present path + type "section" into "location" section, retain order of sections from cmdline
  RF: switch from nargs="*" to action=append for wtf -S
  ENH: wtf -S to specify which sections to query/display (by default -- all)
  MNT: Avoid invalid escape sequences in strings
  BF: export_to_figshare: Don't test identity of string literal
  BF(TST): do not assume user naiveness - treat any url-like looking path as a path
  BF: Check for /, \ or # in the username@hostname part while detecting SSHRI
  CHANGELOG.md: Add entry for gh-3374
  BF: revert back (remove) check for path being PathRI
  BF: list annex-transfer also in cmdline opt choice for "what"
  ...
yarikoptic added a commit that referenced this issue May 28, 2019
0.11.5 (May 23, 2019) -- stability is not overrated

Should be faster and less buggy, with a few enhancements.

 Fixes

- [create-sibling][]  ([#3318][])
  - Siblings are no longer configured with a post-update hook unless a
    web interface is requested with `--ui`.
  - `git submodule update --init` is no longer called from the
    post-update hook.
  - If `--inherit` is given for a dataset without a superdataset, a
    warning is now given instead of raising an error.
- The internal command runner failed on Python 2 when its `env`
  argument had unicode values.  ([#3332][])
- The safeguard that prevents creating a dataset in a subdirectory
  that already contains tracked files for another repository failed on
  Git versions before 2.14.  For older Git versions, we now warn the
  caller that the safeguard is not active.  ([#3347][])
- A regression introduced in v0.11.1 prevented [save][] from committing
  changes under a subdirectory when the subdirectory was specified as
  a path argument.  ([#3106][])
- A workaround introduced in v0.11.1 made it possible for [save][] to
  do a partial commit with an annex file that has gone below the
  `annex.largefiles` threshold.  The logic of this workaround was
  faulty, leading to files being displayed as typechanged in the index
  following the commit.  ([#3365][])
- The resolve_path() helper confused paths that had a semicolon for
  SSH RIs.  ([#3425][])
- The detection of SSH RIs has been improved.  ([#3425][])

 Enhancements and new features

- The internal command runner was too aggressive in its decision to
  sleep.  ([#3322][])
- The "INFO" label in log messages now retains the default text color
  for the terminal rather than using white, which only worked well for
  terminals with dark backgrounds.  ([#3334][])
- A short flag `-R` is now available for the `--recursion-limit` flag,
  a flag shared by several subcommands.  ([#3340][])
- The authentication logic for [create-sibling-github][] has been
  revamped and now supports 2FA.  ([#3180][])
- New configuration option `datalad.ui.progressbar` can be used to
  configure the default backend for progress reporting ("none", for
  example, results in no progress bars being shown).  ([#3396][])
- A new progress backend, available by setting datalad.ui.progressbar
  to "log", replaces progress bars with a log message upon completion
  of an action.  ([#3396][])
- DataLad learned to consult the [NO_COLOR][] environment variable and
  the new `datalad.ui.color` configuration option when deciding to
  color output.  The default value, "auto", retains the current
  behavior of coloring output if attached to a TTY ([#3407][]).
- [clean][] now removes annex transfer directories, which is useful
  for cleaning up failed downloads. ([#3374][])
- [clone][] no longer refuses to clone into a local path that looks
  like a URL, making its behavior consistent with `git clone`.
  ([#3425][])
- [wtf][]
  - Learned to fall back to the `dist` package if `platform.dist`,
    which has been removed in the yet-to-be-release Python 3.8, does
    not exist.  ([#3439][])
  - Gained a `--section` option for limiting the output to specific
    sections and a `--decor` option, which currently knows how to
    format the output as GitHub's `<details>` section.  ([#3440][])

* tag '0.11.5':
  BF: make test for url download more reliable in cases where connection fails
  RF: remove stale commented out duecredit in setup.py.  It has now its own section
@yarikoptic yarikoptic added this to the 0.11.x milestone Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants