Skip to main content

Reusable settings and customization widget for the ndev-kit

Project description

ndev-settings

License BSD-3 PyPI Python Version tests codecov napari hub npe2 Copier

Reusable settings and customization widget for the ndev-kit


This napari plugin was generated with copier using the napari-plugin-template v1.1.0.

Installation

You can install ndev-settings via pip:

pip install ndev-settings

If napari is not already installed, you can install ndev-settings with napari and Qt via:

pip install "ndev-settings[all]"

To install latest development version :

pip install git+https://github.com/ndev-kit/ndev-settings.git

Use with external libraries

External libraries can provide their settings in YAML format with the same structure as your main ndev_settings.yaml.

Step 1: Create a YAML file in the external library (e.g., ndev_settings.yaml):

ndevio_reader:
  preferred_reader:
    default: bioio-ome-tiff
    dynamic_choices:
      fallback_message: No readers found
      provider: bioio.readers
    tooltip: Preferred reader to use when opening images
    value: bioio-ome-tiff
  scene_handling:
    choices:
    - Open Scene Widget
    - View All Scenes
    - View First Scene Only
    default: Open Scene Widget
    tooltip: How to handle files with multiple scenes
    value: View First Scene Only
  clear_layers_on_new_scene:
    default: false
    tooltip: Whether to clear the viewer when selecting a new scene
    value: false

ndevio_export:
  canvas_scale:
    default: 1.0
    max: 100.0
    min: 0.1
    tooltip: Scales exported figures and screenshots by this value
    value: 1.0
  override_canvas_size:
    default: false
    tooltip: Whether to override the canvas size when exporting canvas screenshot
    value: false
  canvas_size:
    default: !!python/tuple
    - 1024
    - 1024
    tooltip: Height x width of the canvas when exporting a screenshot
    value: !!python/tuple
    - 1024
    - 1024

Step 2: Register the entry point in pyproject.toml:

[project.entry-points."ndev_settings.manifest"]
ndevio = "ndevio:ndev_settings.yaml"

Step 3: Use the autogenerated widget in napari!

external settings contributed automatically to the ndev-settings widget

Usage Example

from ndev_settings import get_settings

settings = get_settings()

# Access settings from main file
print(settings.Canvas.canvas_scale)

# Access settings from external libraries (if installed)
print(settings.Reader.preferred_reader)  # From ndevio
print(settings.Export.compression_level)  # From ndevio

# Modify and save settings
settings.Canvas.canvas_scale = 2.0
settings.save()  # Persists across sessions

# Reset to defaults
settings.reset_to_default("canvas_scale")  # Reset single setting
settings.reset_to_default(group="Canvas")  # Reset entire group
settings.reset_to_default()  # Reset all settings

Performance Note: npe1 Plugin Compatibility

If you have many legacy npe1 plugins installed (e.g., napari-assistant, napari-segment-blobs-and-things-with-membranes, napari-simpleitk-image-processing), you may experience slow widget loading times (10+ seconds) the first time you open the settings plugin widget in a napari session. This is a known issue in napari's npe1 compatibility layer, not specific to ndev-settings. The npe1 adapter iterates through all plugin widgets and performs expensive metadata lookups for each legacy plugin.

Workaround: If you don't need npe1 runtime behavior plugins, you can disable the adapter in napari:

  1. Go to File -> Preferences -> Plugins
  2. Uncheck "Use npe2 adapter"
  3. Restart napari

This dramatically improves widget loading times since only pure npe2 plugins are discovered.

How Settings Persistence Works

Settings are automatically cached to improve startup performance:

  1. First load: Settings are discovered from all installed packages via entry points, merged together, and saved to a user config file
  2. Subsequent loads: Settings are loaded directly from the cached file (much faster)
  3. Package changes: When packages are installed/removed, settings are re-discovered and merged while preserving your customizations

Storage location: Settings are stored in a platform-appropriate config directory:

  • Windows: %LOCALAPPDATA%\ndev-settings\settings.yaml
  • macOS: ~/Library/Application Support/ndev-settings/settings.yaml
  • Linux: ~/.config/ndev-settings/settings.yaml

Clearing the cache: To force re-discovery of settings (e.g., after manual edits to package YAML files):

from ndev_settings import clear_settings
clear_settings()  # Deletes cached settings, next load will re-discover

Pre-commit hook

You can use the reset-settings-values pre-commit hook to reset all settings values to their defaults before committing. To do so, add the following to your .pre-commit-config.yaml:

-   repo: https://github.com/ndev-kit/ndev-settings
    rev: v0.3.0
    hooks:
      - id: reset-settings-values

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the BSD-3 license, "ndev-settings" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndev_settings-0.4.1.tar.gz (67.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ndev_settings-0.4.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file ndev_settings-0.4.1.tar.gz.

File metadata

  • Download URL: ndev_settings-0.4.1.tar.gz
  • Upload date:
  • Size: 67.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ndev_settings-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f65ddc315d0ef7929515459254bee571e542dd265b7747315909b238b27af6ff
MD5 b86e31b5040297e530441ce9489f4869
BLAKE2b-256 145a424a8906bfeeb7c666268a0523f9a82e42b5a224fea49d6e6c329b0e0fea

See more details on using hashes here.

Provenance

The following attestation bundles were made for ndev_settings-0.4.1.tar.gz:

Publisher: test_and_deploy.yml on ndev-kit/ndev-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ndev_settings-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: ndev_settings-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ndev_settings-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68bf1e9ec289c94db95d1e61fd4e8489b81d239ff65872401ef56e6ef6261c73
MD5 215b7c650b2ca9eca010ae376f715173
BLAKE2b-256 9b05f6b82e8c98ed79bb224ab6fd2d0010e1ad4ef8d5da0874b8c9614ccdb8f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ndev_settings-0.4.1-py3-none-any.whl:

Publisher: test_and_deploy.yml on ndev-kit/ndev-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page