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

Add config option to disable HTML repr #11159

Merged
merged 8 commits into from
Sep 15, 2022
Merged

Conversation

cbrnr
Copy link
Contributor

@cbrnr cbrnr commented Sep 13, 2022

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
Copy link
Member

@agramfort agramfort left a comment

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
Copy link
Contributor Author

cbrnr commented Sep 14, 2022

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).

@@ -44,6 +44,7 @@ Enhancements
- 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
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
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
Copy link
Member

agramfort commented Sep 14, 2022 via email

@cbrnr
Copy link
Contributor Author

cbrnr commented Sep 14, 2022

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
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
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
Copy link
Contributor Author

cbrnr commented Sep 14, 2022

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
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
Copy link
Contributor Author

cbrnr commented Sep 14, 2022

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
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
Copy link
Contributor Author

cbrnr commented Sep 14, 2022

I could do that? In this PR?

@drammock
Copy link
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
Member

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

@cbrnr
Copy link
Contributor Author

cbrnr commented Sep 14, 2022

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

Copy link
Member

@drammock drammock left a comment

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

@cbrnr
Copy link
Contributor Author

cbrnr commented Sep 15, 2022

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
Member

thanks @cbrnr

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

@cbrnr cbrnr deleted the repr-html-config branch September 15, 2022 12:57
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