Page MenuHomeDevCentral

Provide configuration paths
ClosedPublic

Authored by dereckson on Apr 19 2026, 09:07.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 28, 15:52
Unknown Object (File)
Fri, May 22, 16:40
Unknown Object (File)
Fri, May 22, 12:42
Unknown Object (File)
Fri, May 22, 12:25
Unknown Object (File)
Fri, May 22, 05:18
Unknown Object (File)
Thu, May 21, 15:19
Unknown Object (File)
Tue, May 19, 21:32
Unknown Object (File)
Tue, May 19, 21:32
Subscribers
None

Details

Summary

A common question is how to parse a configuration file
in /usr/local/etc vs /etc, or in current vs home vs system dir.

The function get_configuration_paths is intended to offer the four
solutions. Script is expected to remove the non relevant ones.

The try/except block and the or {} allows to silently ignore
configuration error. They need to be removed when config is mandatory.

Test Plan

With a .foo.conf file containing alpha:\n foo: 42:

$ python3
>>> import config
>>> config.parse_configuration()
{'alpha': {'foo': 42}}

Diff Detail

Repository
rSNIPPETS Snippets
Lint
Lint Passed
Unit
No Test Coverage
Branch
main
Build Status
Buildable 6646
Build 6932: arc lint + arc unit

Event Timeline

dereckson created this revision.
This revision is now accepted and ready to land.Apr 19 2026, 13:53
yousra requested changes to this revision.Apr 19 2026, 14:17

@dereckson I think it is better to use os.path.expanduser to resolve the user configuration path instead of relying on $HOME, as it provides a more robust and portable way to determine the user’s home directory across environments.

https://www.geeksforgeeks.org/python/python-os-path-expanduser-method/

This revision now requires changes to proceed.Apr 19 2026, 14:17

Use os.path.expanduser

>>> import os
>>> get_configuration_paths()
['.foo.conf', '/home/dereckson/.config/foo.conf', '/usr/local/etc/foo.conf', '/etc/foo.conf']
This revision is now accepted and ready to land.Apr 19 2026, 17:12
This revision was automatically updated to reflect the committed changes.