Skip to content

Centralize utilities for configuration loading and path parsing#1448

Open
noah-thor wants to merge 1 commit intoapple:mainfrom
noah-thor:user-config-utility-no-toml
Open

Centralize utilities for configuration loading and path parsing#1448
noah-thor wants to merge 1 commit intoapple: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

}
} else {
guard let resolved = UserConfiguration.resolve(from: .home, relativePath: "config.toml") else {
return
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.

Should we throw here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good catch or should I say good throw

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wait actually this is the case in which a user has not provided an explicit path to the file, so we just want to be ok (not throw) if they do not yet have a toml file created at all. I will add a comment

let path = configFile.string
guard FileManager.default.fileExists(atPath: path) else {
do {
return try TOMLDecoder().decode(T.self, from: Data("".utf8))
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.

Could we make T Initable and just return an instance here?

Copy link
Copy Markdown
Contributor Author

@noah-thor noah-thor May 4, 2026

Choose a reason for hiding this comment

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

Is that an existing protocol? I can't seem to find it. I assume its like:

protocol Initable {
  init()
}

?

Comment on lines +37 to +44
if let envPath = ProcessInfo.processInfo.environment["CONTAINER_APP_ROOT"], !envPath.isEmpty {
return FilePath(envPath)
}
let appSupportURL = FileManager.default.urls(
for: .applicationSupportDirectory,
in: .userDomainMask
).first!.appendingPathComponent("com.apple.container")
return FilePath(appSupportURL.path(percentEncoded: false))
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.

Could we dedup this with ApplicationRoot?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You mean completely remove the ApplicationRoot and/or just have a single definition? I think that makes sense I was just hesitant to touch that code

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