Skip to content

Centralize utilities for configuration loading and path parsing#1448

Merged
katiewasnothere merged 2 commits into
apple:mainfrom
noah-thor:user-config-utility-no-toml
May 8, 2026
Merged

Centralize utilities for configuration loading and path parsing#1448
katiewasnothere merged 2 commits into
apple:mainfrom
noah-thor:user-config-utility-no-toml

Conversation

@noah-thor

Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

This attempts to create a more centralized utility to find and load configuration files, as a follow up to (pr: #1425).

This would make the file apis look something like:

let configPath = UserConfiguration.basePath(for: .appRoot).appending("config/config.toml")

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@noah-thor

Copy link
Copy Markdown
Contributor Author

Mainly looking for API feedback, changes will not be mergable until TOML PR is merged

Comment thread Sources/ContainerPersistence/ConfigurationLoader.swift Outdated
Comment thread Sources/ContainerPersistence/ConfigurationLoader.swift Outdated
Comment thread Sources/ContainerPersistence/UserConfiguration.swift Outdated
@noah-thor noah-thor force-pushed the user-config-utility-no-toml branch from 9da3975 to 83d58aa Compare May 6, 2026 18:06
Separates path resolution (PathUtils) from TOML loading
(ConfigurationLoader) in ContainerPersistence.

- PathUtils: resolves base paths for .home (XDG priority) and .appRoot
- ConfigurationLoader: load() reads from appRoot, copyConfigToAppRoot()
  syncs user config with non-throwing error logging
- ContainerSystemConfig: now non-final with Initable conformance
- All ~17 callsites simplified to ConfigurationLoader.load()
@noah-thor noah-thor force-pushed the user-config-utility-no-toml branch from 83d58aa to 30566ee Compare May 6, 2026 18:24
Changes:
* Remove duplicated UserConfiguration in favor of PathUtils
* Remove stray logger in ConfigurationLoader

@jglogan jglogan 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.

lgtm, see follow-up notes

let containerSystemConfig: ContainerSystemConfig = try ConfigurationLoader.load()
let appRootPath = FilePath(appRoot.path(percentEncoded: false))
try ConfigurationLoader.copyConfigurationToReadOnly(to: appRootPath)
let containerSystemConfig: ContainerSystemConfig = try ConfigurationLoader.load(

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.

nit for the next commit: we can use type inference here and shorten the line

case .home:
let configHome: String
if let xdg = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"], !xdg.isEmpty {
if let xdg = env["XDG_CONFIG_HOME"], !xdg.isEmpty {

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.

Need a follow up PR to scrub ContainerPersistence for string and URL path manipulation. I took care of this for the entity store type.

e.g. we could start here with something like:

    let configHome = env["XDG_CONFIG_HOME"]
        .map { FilePath($0) }
        ?? FilePath(NSHomeDirectory()).appending("/.config")

@katiewasnothere katiewasnothere merged commit 0328f5c into apple:main May 8, 2026
3 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.

4 participants