Skip to main content

Configuration file finder.

Project description

conf-finder

test test coverage

Configuration file finder.

The configuration file/directory is searched for in the following locations by default:

  • The current directory
  • Git root repository (if the current directory is within a repository)
  • XDG config home ($XDG_CONFIG_HOME; if not set, ~/.config is used)
  • Home directory

To locate the configuration directory, the tool searches for a dot-prefixed name (e.g., .mytool) in all locations except for the XDG config home. Within the XDG config home, a name without the dot prefix (e.g., mytool) is searched for.

If no directory is found, the path under the XDG config home is returned.

To locate the configuration file, the tool first searches for a dot-prefixed file (e.g., .myconf.txt) in all locations except for the XDG config home. Within the XDG config home, a file name without the dot prefix (e.g., myconf.txt) is searched for. Following this, an attempt is made to find the file within the located configuration directories.

If no file is found, the path under the configuration directory within the XDG config home is returned.

Requirement

  • Python 3.9, 3.10, 3.11

Installation

$ pip install conf-finder

Usage

from conf_finder import ConfFinder


cf = ConfFinder('mytool')
print(cf.directory())

This script searches for:

  • ./.mytool
  • /.mytool if here is under the git repository.
  • $XDG_CONFIG_HOME/mytool (If XDG_CONFIG_HOME is not set, use ~/.config.)
  • ~/.mytool

If no directory is found, return $XDG_CONFIG_HOME/mytool (or ~/.config/mytool).

from conf_finder import ConfFinder


cf = ConfFinder('mytool')
print(cf.conf(exe='toml'))

This script searches for:

  • ./.mytool.toml
  • /.mytool.toml if here is under the git repository.
  • $XDG_CONFIG_HOME/mytool.toml (If XDG_CONFIG_HOME is not set, use ~/.config.)
  • ~/.mytool.toml
  • ./.mytool/conf.toml
  • /.mytool/conf.toml
  • $XDG_CONFIG_HOME/mytool/conf.toml
  • ~/.mytool/conf.toml
from conf_finder import ConfFinder


cf = ConfFinder('mytool')
print(cf.conf('mytool', 'toml', 'myconf'))

This script searches for:

  • ./.myconf.toml
  • /.myconf.toml
  • $XDG_CONFIG_HOME/myconf.toml
  • ~/.myconf.toml
  • ./.mytool/myconf.toml
  • /.mytool/myconf.toml
  • $XDG_CONFIG_HOME/mytool/myconf.toml
  • ~/.mytool/myconf.toml

If you wish to search for only files directly placed under the search directories, conf_type to 'file':

from conf_finder import ConfFinder


cf = ConfFinder('mytool', conf_type='file')
print(cf.conf('mytool', 'toml', 'myconf'))

This script searches for:

  • ./.myconf.toml
  • /.myconf.toml
  • $XDG_CONFIG_HOME/myconf.toml
  • ~/.myconf.toml

If no file is found, $XDG_CONFIG_HOME/myconf.toml is returned.

To search for only directories, conf_type to 'dir' instead.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conf_finder-0.3.1.tar.gz (74.8 kB view details)

Uploaded Source

Built Distribution

conf_finder-0.3.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file conf_finder-0.3.1.tar.gz.

File metadata

  • Download URL: conf_finder-0.3.1.tar.gz
  • Upload date:
  • Size: 74.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.15

File hashes

Hashes for conf_finder-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3df3a3eaf2a1af8920c3b91b6b2068a4620c5b4e6fac8711e6da4582e0ed591f
MD5 c7f3c2ff4b301ac57b2c06cd62c06347
BLAKE2b-256 257e233812e2ab32874a11da2113bce4981df6d6d43da94221204aa6afc986b2

See more details on using hashes here.

File details

Details for the file conf_finder-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for conf_finder-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4e7d4a87839f54433bd3d7ed3be09fc1e1ca8f251f7df3d2ff87dbfbcd1bd69
MD5 d134a69b12909201e925f261254f2e20
BLAKE2b-256 9653c5d92b192f8e6d0ab7e08c629db999750a2d07c2771ba76195e365017b7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page