Skip to content

Fix custom colormaps location (store them in the application config dir) - #88

Merged
PierreRaybaut merged 2 commits into
developfrom
fix/70-custom-colormaps-config-dir
Oct 29, 2026
Merged

PierreRaybaut merged 2 commits into
developfrom
fix/70-custom-colormaps-config-dir

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Contributor

Summary

Fixes #70: custom colormaps are now stored in the configuration directory of the application, instead of a ~/.none directory shared by all applications.

Root cause

  • plotpy.config.CONF had no application name, so CONF.get_path() resolved to ~/.none (and created it).
  • CUSTOM_COLORMAPS_PATH was computed once at import time: an application naming PlotPy's configuration afterwards never got its own custom colormaps.

As a result, the location depended on the import order. For example, the DataLab application used ~/.plotpy, whereas DataLab scripts and tests used ~/.none, and DataLab's intended ~/.DataLab_v1/plotpy was never used.

Changes

  • CONF is now a PlotPyUserConfig, named "plotpy" by default:
    • set_application() calls registered callbacks;
    • get_path() no longer creates the configuration directory, which is only created when a file is written.
  • plotpy.mathutils.colormap:
    • new get_custom_colormaps_path(), computed on demand (CUSTOM_COLORMAPS_PATH remains available through a module __getattr__);
    • new reload_custom_colormaps(), called on each CONF.set_application(), which updates CUSTOM_COLORMAPS and ALL_COLORMAPS in place (they are imported by name elsewhere);
    • migration: if the application's custom colormaps file does not exist yet, colormaps from the legacy .none and .plotpy directories are merged and copied into it. Legacy files are left untouched.
  • Tests: new test_colormap_config.py, plus an isolated_config_dir fixture so that colormap tests (including test_colormap_manager) no longer write into the user's real configuration directory.
  • Release notes (2.12.0, bug fixes).

Resulting locations

Context Before After
PlotPy alone ~/.none ~/.plotpy
Application calling CONF.set_application("MyApp/plotpy", ...) after import ~/.none or ~/.plotpy ~/.MyApp/plotpy
DataLab (application, scripts, tests) ~/.plotpy or ~/.none ~/.DataLab_v1/plotpy

(~ is ~/.config on Linux.)

Known limitation

Migration happens once per application, when its file does not exist yet. A user whose ~/.plotpy file was already written (e.g., by DataLab 1.3) keeps only that file for standalone PlotPy applications: colormaps saved only in ~/.none are not merged into it.

Tests

  • New tests fail without the fix and pass with it.
  • Full suite: 428 passed, 16 skipped (Windows, PyQt5, Python 3.14).
  • Checked with DataLab develop in an isolated home containing legacy .none and .plotpy files: both the application and the script entry points now load the merged colormaps from ~/.DataLab_v1/plotpy.

PlotPy's configuration had no application name, so custom colormaps
were saved in a "~/.none" directory shared by all applications, which
was created as soon as colormaps were loaded. Their path was moreover
computed at import time, so that an application naming PlotPy's
configuration afterwards (e.g. "DataLab_v1/plotpy") never got its own
custom colormaps.

- Name PlotPy's configuration "plotpy" by default
- Compute the custom colormaps path on demand, and reload custom
  colormaps in place each time CONF.set_application is called
  (CUSTOM_COLORMAPS_PATH remains available, computed on demand)
- The first time, copy custom colormaps from the legacy ".none" and
  ".plotpy" directories, without modifying the legacy files
- Do not create the configuration directory on path lookups
- Run colormap tests in a temporary configuration directory

Closes #70

Assisted-by: Claude Opus 5.5
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