Page MenuHomeDevCentral

Provide configuration paths
ClosedPublic

Authored by dereckson on Apr 19 2026, 09:07.
Tags
None
Referenced Files
F46148694: D4082.diff
Tue, Aug 25, 08:56
F46037249: D4082.id10686.diff
Mon, Aug 24, 18:31
F46026149: D4082.id10687.diff
Mon, Aug 24, 17:07
Unknown Object (File)
Sat, Aug 22, 01:45
Unknown Object (File)
Fri, Aug 21, 19:40
Unknown Object (File)
Fri, Aug 21, 19:38
Unknown Object (File)
Thu, Aug 20, 19:25
Unknown Object (File)
Mon, Aug 17, 23:54
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 6651
Build 6937: 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.