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.1.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

conf_finder-0.1.3-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: conf_finder-0.1.3.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for conf_finder-0.1.3.tar.gz
Algorithm Hash digest
SHA256 99e35ae3b419d46f11ce54fa045ee93899b326066e464c9dd674f79a9e84640b
MD5 8bf3d71a8dda81177b57e12dc99c8071
BLAKE2b-256 eff026877e594231955ade54550708b3cb37df3e80081d77b76ff53f5456ab62

See more details on using hashes here.

File details

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

File metadata

  • Download URL: conf_finder-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for conf_finder-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 816f0aefed835bc262a0dc50a9e6319a0079f1c5e2e7d9707824c9d615e99287
MD5 9f090a43f7a37bbc90c3458601b1a69f
BLAKE2b-256 0a71b3e0fbf565dbd6bddb5db2f9dafe4b5bbcc385f3b0391009a15d8a5713dd

See more details on using hashes here.

Supported by

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