Skip to content

Add config option to disable HTML repr - #11159

Merged
agramfort merged 8 commits into
mne-tools:mainfrom
cbrnr:repr-html-config
Sep 15, 2022
Merged

agramfort merged 8 commits into
mne-tools:mainfrom
cbrnr:repr-html-config

Conversation

@cbrnr

@cbrnr cbrnr commented Sep 13, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #9830.

Open questions:

  1. I added four lines of code at the beginning of _repr_html_() of each class that defines this method. We could outsource this (in a decorator?), but it's probably overkill right now. I refactored this into a decorator, I think this is cleaner even for the few classes we have.
  2. I didn't find a way to set a config option only temporarily (for the current session without writing to the config file) – is this possible somehow? set_config() doesn't seem to support it, but maybe I missed a context manager or something similar?

@larsoner larsoner added this to the 1.2 milestone Sep 13, 2022

@agramfort agramfort left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could we test this so the new lines are covered? 🙏 @cbrnr

@cbrnr

cbrnr commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

Sure, I'll add a test. Does anyone have an answer to my second question? Basically, I'm looking for something like mne.set_log_level(), which is only valid within the current session (so not permanently).

Comment thread doc/changes/latest.inc
- Add example of how to obtain time-frequency decomposition using narrow bandpass Hilbert transforms to :ref:`ex-tfr-comparison` (:gh:`11116` by `Alex Rockhill`_)
- Add ``==`` and ``!=`` comparison between `mne.Projection` objects (:gh:`11147` by `Mathieu Scheltienne`_)
- Add ``encoding`` parameter to :func:`mne.io.read_raw_edf` and :func:`mne.io.read_raw_bdf` to support custom (non-UTF8) annotation channel encodings (:gh:`11154` by `Clemens Brunner`_)
- Add config option ``MNE_REPR_HTML`` to disable HTML repr in notebook environments (:gh:`11159` by `Clemens Brunner`_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looking at the doc and thinking where this information could be added I found

https://mne.tools/stable/auto_tutorials/intro/50_configure_mne.html

and this tells me that maybe using mne config mechanism would be the expect thing to do...

what do you think @cbrnr @drammock ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand. Do you want to describe the new config option in the docs? We haven't done this for the other existing options though.

@agramfort

agramfort commented Sep 14, 2022 via email

Copy link
Copy Markdown
Member

@cbrnr

cbrnr commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

If we haven't described our config options so far, I think we should describe all of them. But maybe @drammock knows if there's already some documentation.

@larsoner

Copy link
Copy Markdown
Member

Does anyone have an answer to my second question? Basically, I'm looking for something like mne.set_log_level(), which is only valid within the current session (so not permanently).

The current way to get this behavior is just to set os.environ['...']. It will be temporary to that session

@larsoner

Copy link
Copy Markdown
Member

... and I don't think there is a single place where we describe all options. Instead we try to describe each option around where it's used, e.g., the 3D options should be described in set_3d_options. For this new param since it's more "global" in scope like set_log_level, we could just add it to the config tutorial for now, and figure out in a separate issue if we want to add all options somewhere else later (I'm not yet convinced we should/need to so we should discuss separately).

@cbrnr

cbrnr commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

The current way to get this behavior is just to set os.environ['...']. It will be temporary to that session

OK, that's what I did in the test.

Re describing config options, I'm fine with descriptions in different places, but maybe an overview of all possible values would be nice. Maybe even built into mne.get_config() somehow? Whatever we decide, I'd vote for tackling this in a separate PR, since this is a bit outside the scope of this PR.

@drammock

Copy link
Copy Markdown
Member

I'm fine with descriptions in different places, but maybe an overview of all possible values would be nice. Maybe even built into mne.get_config() somehow?

mne.get_config("") returns a list of all valid config keys. (no explanation of what they do though, but fodder for a search engine or git grep).

@cbrnr

cbrnr commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

mne.get_config("") returns a list of all valid config keys. (no explanation of what they do though, but fodder for a search engine or git grep).

That's probably good enough for now. WDYT @agramfort?

@drammock

Copy link
Copy Markdown
Member

mne.get_config("") returns a list of all valid config keys. (no explanation of what they do though, but fodder for a search engine or git grep).

If we wanted a more thorough documentation of what they all do, a nice way to do it would be for mne.get_config("") to return a dict instead of a tuple, with the dict values being a short one-sentence description of what each key does and its valid values.

@cbrnr

cbrnr commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

I could do that? In this PR?

@drammock

Copy link
Copy Markdown
Member

I could do that? In this PR?

go for it. mne.get_config("") is mostly there for informational/interactive purposes, it's only used twice in the codebase in ways that should be compatible with dict too:

$ git grep "get_config('')"
mne/utils/tests/test_config.py:24:    assert (len(get_config('')) > 10)  # tuple of valid keys
tutorials/intro/50_configure_mne.py:84:assert 'MNEE_USE_CUUDAA' not in mne.get_config('')

@drammock

Copy link
Copy Markdown
Member

oh, rereading, maybe you weren't volunteering :) and even if you were, it should probably be a separate PR.

@cbrnr

cbrnr commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

That's OK, I'll do it in a separate PR. So I guess this one is ready?

@drammock drammock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just one tiny suggestion. Thanks @cbrnr

Comment thread mne/utils/misc.py Resolved
@cbrnr

cbrnr commented Sep 15, 2022

Copy link
Copy Markdown
Contributor Author

All green – @agramfort please feel free to merge if all of your comments have been addressed!

@agramfort
agramfort merged commit 63b430e into mne-tools:main Sep 15, 2022
@agramfort

Copy link
Copy Markdown
Member

thanks @cbrnr

can you open issues for the next PRs to complete to follow up? 🙏

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.

Synchronize __repr__() and _repr_html_()

4 participants