Skip to content

MathCAT: store YAML preferences with NVDA configuration#19373

Merged
seanbudd merged 2 commits into
nvaccess:betafrom
codeofdusk:mathcat-config-location
Jan 23, 2026
Merged

MathCAT: store YAML preferences with NVDA configuration#19373
seanbudd merged 2 commits into
nvaccess:betafrom
codeofdusk:mathcat-config-location

Conversation

@codeofdusk

@codeofdusk codeofdusk commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Link to issue number:

None

Summary of the issue:

NVDA creates a MathCAT directory in the user's roaming appdata (by default, a sibling of the NVDA config directory) which:

  • might not always be writable;
  • does not follow existing project idioms.

Description of how this pull request fixes the issue:

Relocates the MathCAT preferences yaml to NVDA user configuration.

Testing strategy:

Verified that settings are read and written as expected.

Known issues with pull request:

Since this file is generated from NVDA user config, no settings should be lost. Just in case though, we should probably do this migration before 2026.1 is released.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@codeofdusk

Copy link
Copy Markdown
Contributor Author

CC @RyanMcCleary.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request relocates MathCAT's YAML preferences file from a separate directory in the user's roaming AppData to the NVDA user configuration directory, aligning with NVDA project conventions.

Key Changes:

  • Removed the pathToUserPreferencesFolder() function that pointed to a separate MathCAT directory
  • Updated pathToUserPreferences() to use NVDA's getUserDefaultConfigPath() and renamed the file to mathcat.yaml
  • Removed directory creation logic since NVDA handles config directory initialization

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

Comment thread source/mathPres/MathCAT/preferences.py Outdated
@codeofdusk codeofdusk force-pushed the mathcat-config-location branch from b277a77 to 33949bb Compare December 11, 2025 10:18
@codeofdusk codeofdusk mentioned this pull request Dec 11, 2025
5 tasks
Comment thread source/mathPres/MathCAT/preferences.py
@codeofdusk codeofdusk force-pushed the mathcat-config-location branch from 33949bb to 855c68e Compare December 12, 2025 09:26
@codeofdusk codeofdusk marked this pull request as draft December 12, 2025 10:07
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Dec 16, 2025
@seanbudd

Copy link
Copy Markdown
Member

@codeofdusk - do you intend to continue to work on this?

@seanbudd seanbudd added this to the 2026.1 milestone Jan 15, 2026
@NSoiffer

Copy link
Copy Markdown
Contributor

Sorry to be late to responding to this. Too many emails and these sometimes get lost.

The design idea for Rules/prefs.yaml and %AppData%/MathCAT/prefs.yaml was to have a set of defaults and also a place to store a user's preferences. The defaults are read first and then an user settings are read and that overrides the defaults. Currently, all (or almost all) settings also live in the user prefs dir, but that is just an artifact of how the current MathCAT dialog works.

Because MathCAT can be used in many different projects and some may allow for multiple users, %AppData% (on Windows) is the place where user-specific information is supposed to get stored. However, there is no requirement that there be a user prefs files as long as Rules/prefs.yaml exists. If the built in version of MathCAT wants to either change Rules/prefs.yaml or (probably better) just call SetPreference on all the values in the INI file, that should work.

@seanbudd seanbudd marked this pull request as ready for review January 23, 2026 04:55

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @codeofdusk

@seanbudd seanbudd enabled auto-merge (squash) January 23, 2026 04:57
@seanbudd seanbudd merged commit 9a51178 into nvaccess:beta Jan 23, 2026
73 of 75 checks passed
@SaschaCowley

SaschaCowley commented Feb 3, 2026

Copy link
Copy Markdown
Member

I'm quite concerned about this PR:

  • When running in secure mode, NVDA should not persist config, however this happens here (this was an issue before this PR, as best as I can tell).

  • The Corporate & Government page on the NV Access website mentions:

    Installed copies of NVDA store their configuration including add-ons in %APPDATA%\nvda. To prevent NVDA users from modifying their configuration or add-ons directly, user write access to this folder must also be restricted.

    Will MathCAT work at all without the yaml file and no config provided via the API? Users could also have the rather confusing experience that they are able to change math settings, but these changes won't be applied if write access to %AppData%\nvda is restricted.

IMO we need to either:

seanbudd pushed a commit that referenced this pull request Feb 17, 2026
…9613)

Closes #19597.
Summary of the issue:

After #19373, NVDA math preferences were not honoured by MathCAT.
Description of how this pull request fixes the issue:

Per #19373 (comment), use libmathcat.SetPreference to apply settings changes when they are saved to the NVDA configuration.
SaschaCowley added a commit that referenced this pull request Feb 18, 2026
Follow-up to #18323, #19373 and #19613

### Summary of the issue:

Since the introduction of MathCAT into NVDA in #18323, NVDA has
persisted MathCAT settings to a YAML file . This is at odds with current
project configuration standards, which use either configobj ini files,
or JSON. This also duplicates settings, as they're also saved to
`nvda.ini`.
Originally, these were stored in `%AppData%\MathCAT\prefs.yaml`, but as
of #19373, they are saved to `mathcat.yaml` in NVDA's config directory.
In neither case was `shouldWriteToDisk` checked before saving the
preferences. Additionaly, [NV Access's Corporate & Government
page](https://www.nvaccess.org/corporate-government/) states "To prevent
NVDA users from modifying their configuration or add-ons directly, user
write access to [`%APPDATA%\nvda`] must also be restricted". If
implemented, this would have stopped users from changing their MathCAT
settings in memory, as they had to be saved to YAML to be loaded by
MathCAT.
In #19613, the logic was changed to programmatically apply these
settings with `libmathcat.SetPreference`, which should solve the problem
of users without write access to their NVDA config directory being able
to change their MathCAT preferences. However, the code that wrote the
settings to the YAML file was not removed, nor did it contain any error
handling.

### Description of user facing changes:

None, but may avoid some errors in the logs.

### Description of developer facing changes:

Pyyaml is no-longer a dependency.
`mathPres.MathCAT.preferences.MathCATUserPreferences.save` has been
renamed to `apply`, and no longer saves the settings to YAML. Settings
persistance is handled by NVDA's configuration system.

### Description of development approach:

Removed the code that wrote MathCAT preferences to YAML, and any code
that only it depended on. Renamed `save` to `apply` using VS Code's
refactoring tool. Searched the repo for `yaml` and after confirming that
we don't rely on `pyyaml` anywhere else, ran `uv remove pyyaml`.

### Testing strategy:

Tested by loading the [Wikipedia page on the quadratic
formula](https://en.wikipedia.org/wiki/Quadratic_formula) in firefox.
Located some math and read it. Changed settings one at a time and tested
that they were applied correctly. Restarted NVDA and ensured that the
new settings were still present.

### Known issues with pull request:

None known
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants