Page MenuHomeDevCentral

Provide configuration paths
ClosedPublic

Authored by dereckson on Apr 19 2026, 09:07.
Tags
None
Referenced Files
F49756937: D4082.id10686.diff
Mon, Sep 14, 10:36
Unknown Object (File)
Fri, Sep 11, 21:07
Unknown Object (File)
Mon, Sep 7, 06:11
Unknown Object (File)
Mon, Sep 7, 03:32
Unknown Object (File)
Sun, Sep 6, 22:15
Unknown Object (File)
Wed, Sep 2, 02:22
Unknown Object (File)
Tue, Sep 1, 23:52
Unknown Object (File)
Tue, Sep 1, 23:43
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.