Skip to content

Implement user-specific settings storage to prevent writing to application config.py#14

Merged
tmaier-kettering merged 3 commits into
copilot/fix-4a73586b-cec7-493a-824b-9a936f99931dfrom
copilot/fix-0802d40d-2ad0-42a3-9c3b-7a57f732649d
Sep 26, 2025
Merged

Implement user-specific settings storage to prevent writing to application config.py#14
tmaier-kettering merged 3 commits into
copilot/fix-4a73586b-cec7-493a-824b-9a936f99931dfrom
copilot/fix-0802d40d-2ad0-42a3-9c3b-7a57f732649d

Conversation

Copilot AI commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

Problem

The application was writing user settings directly to settings/config.py within the application directory, which causes issues in:

  • PyInstaller bundled environments where files are stored in read-only temporary directories (e.g., _MEI* folders)
  • Environments with restricted write permissions to application directories
  • Multi-user systems where application files should remain unchanged

Solution

Implemented a new user-specific settings storage system that:

  1. Stores user settings in platform-appropriate directories:

    • Windows: %APPDATA%\CodebookAI\config.json
    • macOS: ~/Library/Application Support/CodebookAI\config.json
    • Linux: ~/.config/CodebookAI\config.json
  2. Maintains config.py as read-only defaults: The original settings/config.py now serves exclusively as the source of default values and is never modified by the application.

  3. Provides seamless configuration merging: The new settings/user_config.py module automatically merges user overrides with defaults from config.py, making the transition transparent to existing code.

Key Changes

New User Configuration Module

  • Added settings/user_config.py with platform-specific directory detection
  • JSON-based settings storage with atomic writes for reliability
  • Graceful error handling that falls back to defaults when user config is corrupted

Updated Settings Window

  • Removed _write_config_file() method that wrote directly to config.py
  • Updated to use new get_setting() and set_setting() functions
  • Simplified save process without needing file backups

Updated Configuration Usage

  • Modified batch_processing/batch_method.py to use the new configuration system
  • All config.attribute calls now go through the user config system
  • Maintains backward compatibility with identical setting names

Enhanced Documentation

  • Updated wiki/File/Settings.md to document the new storage locations and configuration architecture

Benefits

  • ✅ PyInstaller Compatible: Works correctly in bundled application environments
  • ✅ Cross-Platform: Automatically detects appropriate user directories for each OS
  • ✅ Secure: No permission issues writing to application directories
  • ✅ User-Friendly: Settings stored in standard locations users expect
  • ✅ Robust: Graceful fallback handling for corrupted or missing configuration files
  • ✅ Maintainable: Clean separation between application defaults and user customizations

Testing

The implementation has been thoroughly tested for:

  • Platform-specific directory detection on Windows, macOS, and Linux
  • Settings persistence and retrieval with proper default fallbacks
  • Error handling for malformed JSON and missing files
  • Protection of the original config.py from modifications
  • Security vulnerabilities (none detected via CodeQL analysis)

This change ensures the application works reliably across all deployment scenarios while maintaining a clean separation between application defaults and user-specific settings.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/tmaier-kettering/tmaier-kettering%2FCodebookAI/languages
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Update the settings handling in the application so that when saving user settings, the software does not attempt to write to config.py within the application or bundled directory (such as PyInstaller's _MEI* temp folder). Instead, store user-modifiable settings in a user-writable location (e.g., %APPDATA%/CodebookAI/config.json on Windows, or an equivalent user config directory on other platforms). Ensure all code that saves or loads settings is updated to read defaults from config.py but write and update user-specific settings in the appropriate user directory. Refactor any UI or logic that writes directly to config.py to use this new system, and handle merging defaults with user overrides when loading the configuration.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 26, 2025 01:50
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Copilot AI changed the title Update the settings handling in the application so that when saving user settings, the software does not attempt to write to config.py within the application or bundled directory (such as PyInstaller's _MEI* temp folder). Instead, store user-modifiable... Implement user-specific settings storage to prevent writing to application config.py Sep 26, 2025
@tmaier-kettering tmaier-kettering marked this pull request as ready for review September 26, 2025 02:50
@tmaier-kettering tmaier-kettering merged commit 3f016f8 into copilot/fix-4a73586b-cec7-493a-824b-9a936f99931d Sep 26, 2025
@tmaier-kettering tmaier-kettering deleted the copilot/fix-0802d40d-2ad0-42a3-9c3b-7a57f732649d branch September 26, 2025 02:50
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.

2 participants