Skip to content

Conversation

@TimMonko
Copy link
Member

@TimMonko TimMonko commented Dec 2, 2025

This pull request introduces significant improvements to settings management and persistence in the ndev-settings package, including a robust new implementation of the Settings class, enhanced plugin compatibility documentation, and dependency adjustments. The new system ensures reliable merging, caching, and resetting of settings, with improved handling for package discovery and editable installs.

Major settings management improvements:

  • Completely rewrote the Settings class in src/ndev_settings/_settings.py to robustly manage persistent settings:
    • Settings are now loaded from a user config directory using appdirs, with automatic merging from all installed packages via entry points.
    • Implements caching with a hash to detect package changes, ensuring settings are re-discovered and merged as needed.
    • Supports editable installs and various edge cases for package resource discovery.
    • Adds a clear_settings function to delete cached settings and force re-discovery.
  • Improved the reset_values_to_defaults logic in src/ndev_settings/_cli.py:
    • Now skips metadata keys and handles malformed entries more gracefully, preserving keys starting with _. [1] [2] [3]

User-facing enhancements:

  • Expanded the README.md with detailed documentation:
    • Added instructions on modifying, saving, and resetting settings.
    • Included a performance note on npe1 plugin compatibility and a workaround to improve widget loading times.
    • Explained how settings persistence and caching work, including storage locations and cache clearing.

Dependency and packaging updates:

  • Added appdirs as a required dependency in pyproject.toml for platform-appropriate config storage.
  • Updated optional dependencies and development dependencies for consistency and improved testing support.

API and export changes:

  • Exported the new clear_settings function from the package root in src/ndev_settings/__init__.py.

These changes provide a more reliable, user-friendly, and extensible settings system for ndev plugins, with clear documentation and improved developer experience.

@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 95.88235% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/ndev_settings/_settings.py 96.20% 6 Missing ⚠️
src/ndev_settings/_cli.py 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a caching mechanism for settings to improve load time, switches the dynamic choices API to a public method, and aligns test scaffolding and configuration with the new behavior.

  • Add persistent user settings cache with invalidation based on entry-points hash
  • Rename _get_dynamic_choices to get_dynamic_choices and update call sites/tests
  • Adjust test fixtures to disable persistence during tests; update dependency groups in tooling configs

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/ndev_settings/_settings.py Major refactor to add a persistent cache under XDG_CONFIG_HOME, entry-point hash invalidation, public get_dynamic_choices, and group sync/save logic.
src/ndev_settings/_settings_widget.py Updates widget to use the new public get_dynamic_choices API.
tests/test_settings.py Updates tests to reflect save-sync behavior and first-wins external merge semantics; switches to public get_dynamic_choices; adds deterministic expectations for external conflicts.
tests/conftest.py Adds autouse fixtures to disable persistence and to redirect default settings file path for tests; resets singleton between tests.
src/ndev_settings/init.py Exposes clear_settings in package exports and updates all.
tox.ini Switches dependency_groups from testing to dev to match pyproject.
pyproject.toml Renames dependency group to dev, adjusts extras for napari, adds dev-time dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TimMonko TimMonko changed the title use caching for settings file to improve load time Caching settings, editable install support, and better validation Dec 3, 2025
@TimMonko TimMonko merged commit 96bec7d into ndev-kit:main Dec 3, 2025
14 checks passed
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.

1 participant