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 dask settings to preferences #5490

Merged
merged 10 commits into from
Feb 17, 2023
Merged

Add dask settings to preferences #5490

merged 10 commits into from
Feb 17, 2023

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Jan 18, 2023

Description

This is the alternative implementation for #4436 PR with using core qt_json_builder features instead of magicgui.

The main advantage of this PR is that it introduces a general mechanism for easily add similar fields in future

Same as in the original PR there are no tests.

Type of change

  • Bug-fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

References

How has this been tested?

  • example: the test suite for my feature covers cases x, y, and z
  • example: all tests pass with my change
  • example: I check if my changes works with both PySide and PyQt backends
    as there are small differences between the two Qt bindings.

Final checklist:

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • If I included new strings, I have used trans. to make them localizable.
    For more information see our translations guide.

@github-actions github-actions bot added preferences Issues relating to the creation of new preference fields/panels qt Relates to qt labels Jan 18, 2023
@Czaki
Copy link
Collaborator Author

Czaki commented Jan 18, 2023

@jni Which PR one do you prefer? This or #4436?

@Czaki Czaki marked this pull request as ready for review January 18, 2023 15:52
@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #5490 (5335aa9) into main (6d27f81) will decrease coverage by 0.01%.
The diff coverage is 91.17%.

@@            Coverage Diff             @@
##             main    #5490      +/-   ##
==========================================
- Coverage   89.40%   89.40%   -0.01%     
==========================================
  Files         609      609              
  Lines       51146    51178      +32     
==========================================
+ Hits        45729    45755      +26     
- Misses       5417     5423       +6     
Impacted Files Coverage Δ
napari/_qt/qt_viewer.py 78.97% <85.71%> (+0.14%) ⬆️
napari/settings/_application.py 96.55% <91.66%> (-1.28%) ⬇️
...pari/_qt/dialogs/_tests/test_preferences_dialog.py 100.00% <100.00%> (ø)
napari/_qt/dialogs/preferences_dialog.py 90.17% <100.00%> (+0.36%) ⬆️
napari/components/experimental/chunk/_pool.py 85.71% <0.00%> (-7.94%) ⬇️
napari/components/_tests/test_layer_slicer.py 97.98% <0.00%> (-1.21%) ⬇️
napari/_qt/dialogs/qt_package_installer.py 81.81% <0.00%> (+0.39%) ⬆️
napari/utils/theme.py 94.04% <0.00%> (+0.59%) ⬆️
napari/utils/info.py 85.10% <0.00%> (+1.06%) ⬆️
napari/_qt/__init__.py 56.66% <0.00%> (+6.66%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@ppwadhwa ppwadhwa left a comment

Choose a reason for hiding this comment

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

Hi @Czaki ! Thanks for working on this. It makes sense to me and seems straightforward.
I tried it out and it worked mostly well, except that the dask cache values were not updating properly. I added in a few suggestions to make this work, plus a name change on the update function.

napari/_qt/qt_viewer.py Outdated Show resolved Hide resolved
napari/_qt/qt_viewer.py Outdated Show resolved Hide resolved
napari/_qt/qt_viewer.py Outdated Show resolved Hide resolved
@Czaki
Copy link
Collaborator Author

Czaki commented Jan 19, 2023

I decided to workaround in another way. Could you check it now?

napari/_qt/qt_viewer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ppwadhwa ppwadhwa left a comment

Choose a reason for hiding this comment

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

It looks and works great!

@Czaki
Copy link
Collaborator Author

Czaki commented Jan 19, 2023

As I bring here your ideas. Did you have idea how to test it properly?

@ppwadhwa
Copy link
Contributor

As I bring here your ideas. Did you have idea how to test it properly?

I will take a look on Monday morning!

@Czaki
Copy link
Collaborator Author

Czaki commented Feb 1, 2023

@ppwadhwa any update?

@ppwadhwa
Copy link
Contributor

ppwadhwa commented Feb 1, 2023

@Czaki sorry for the delay. I have gotten caught up in other work. I am looking at this now. Thanks for the ping!

@ppwadhwa
Copy link
Contributor

ppwadhwa commented Feb 1, 2023

@Czaki Since there are no tests for the json schema builder, what do you think about adding in a test in the napari/_tests folder with a dummy schema. See if that builds the widget? And include a test for a subschema? I can start working on this, but just wondering if you like this idea?

@ppwadhwa
Copy link
Contributor

ppwadhwa commented Feb 1, 2023

Another option would be to add a test to the preferences dialog.

@ppwadhwa
Copy link
Contributor

ppwadhwa commented Feb 1, 2023

I like the second option better. If you add in the dask field to the dummy settings there, I think its covering the new lines you added in the widget schema builder.

Like this:
In napari/_qt/dialogs/_tests/test_preferences_dialog.py

@pytest.fixture
def pref(qtbot):
    dlg = PreferencesDialog()
    qtbot.addWidget(dlg)
    settings = get_settings()
    assert settings.appearance.theme == 'dark'
    dlg._settings.appearance.theme = 'light'
    assert get_settings().appearance.theme == 'light'
    dask_settings = DaskSettings()
    dask_settings.cache = 4000
    dask_settings.enabled = False
    dlg._settings.application.dask = dask_settings
    yield dlg

@ppwadhwa
Copy link
Contributor

ppwadhwa commented Feb 1, 2023

and maybe add a test to make sure it used the HorizontalObjectSchemaWidget?

def test_dask_widget(qtbot, pref):
    assert isinstance(pref._stack.currentWidget().widget.widgets['dask'], HorizontalObjectSchemaWidget)

@Czaki
Copy link
Collaborator Author

Czaki commented Feb 1, 2023

and maybe add a test to make sure it used the HorizontalObjectSchemaWidget?

def test_dask_widget(qtbot, pref):
    assert isinstance(pref._stack.currentWidget().widget.widgets['dask'], HorizontalObjectSchemaWidget)

I do not understand why changes in fixture but this test looks enough for me.

@github-actions github-actions bot added the tests Something related to our tests label Feb 1, 2023
@ppwadhwa
Copy link
Contributor

ppwadhwa commented Feb 1, 2023

@Czaki you're right -- the fixture isn't needed.

@Czaki
Copy link
Collaborator Author

Czaki commented Feb 14, 2023

Without horizontal widget:
obraz

obraz

Copy link
Member

@jni jni left a comment

Choose a reason for hiding this comment

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

@Czaki and I had a live discussion on this — thanks @Czaki for walking me through both PRs! Some of the points of discussion:

  • @jni: "ok so you are changing a vendored module, which is not so great, has it been changed already?" @Czaki: "yes, and this is only a minor addition that could be considered a bug fix (min/max for spinboxes)." We discussed that we should pay a bit more attention to how we maintain vendored modules (for example, noting the commit hash of the vendored version and keeping a plaintest set of .patches that we applied to that commit). But this should come in later PRs, clearly, and should not be a prerequisite for these improvements.
  • @jni: "not sure about the side by side layout, and we should prefer code simplicity to fancy UI." @Czaki: "the design was discussed long ago and I am trying to preserve the design to avoid longer discussions." This is fair enough, and anyway ties into the discussion above about improving vendoring. We should fix in later PRs.
  • @jni: "does using qt_json_builder further tie us into Qt in the future? Because we want to eventually have models that are completely separate from Qt and potentially different front-ends, including e.g. a web front end." @Czaki: "No, there are other frontends for json-schema so this approach is actually quite portable."

So I'm happy with where this has landed. Thank you @ppwadhwa for all the initial work here and iteration which led us to this point, 🙏 and thanks @Czaki for picking it up and pushing it over the finish line! 🙏 (And for the live walk-through.)

@jni jni added the ready to merge Last chance for comments! Will be merged in ~24h label Feb 14, 2023
@goanpeca
Copy link
Contributor

Note: I would like to add that the code vendored is not an actual package, just a repo created by the user. I also talked to him about maintaining it and making it an actual package. This is on my to do list, so that we would not have to vendor it but just install it and extend it. Also as @Czaki this method of using the json schemas is what other tools like Jupyterlab currently use to handle settings and autogenerate the UI from it -> see reference PR jupyterlab/jupyterlab#11079

@jni jni changed the title Add dask settings to preference, alternative Add dask settings to preferences Feb 17, 2023
@jni jni merged commit 4cb8f9d into napari:main Feb 17, 2023
@jni jni deleted the dask_settings_2 branch February 17, 2023 01:16
@Czaki Czaki removed the ready to merge Last chance for comments! Will be merged in ~24h label Feb 18, 2023
@Czaki Czaki mentioned this pull request Jun 7, 2023
@Czaki Czaki added the feature New feature or request label Jun 13, 2023
@Czaki Czaki added this to the 0.4.18 milestone Jun 13, 2023
Czaki added a commit that referenced this pull request Jun 18, 2023
Co-authored-by: Pam Wadhwa <pepainter@gmail.com>
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 19, 2023
Co-authored-by: Pam Wadhwa <pepainter@gmail.com>
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 21, 2023
Co-authored-by: Pam Wadhwa <pepainter@gmail.com>
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 21, 2023
Co-authored-by: Pam Wadhwa <pepainter@gmail.com>
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
Czaki added a commit that referenced this pull request Jun 21, 2023
Co-authored-by: Pam Wadhwa <pepainter@gmail.com>
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request preferences Issues relating to the creation of new preference fields/panels qt Relates to qt tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants