conf-finder


Nameconf-finder JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/rcmdnk/conf-finder
SummaryConfiguration file finder.
upload_time2023-10-04 05:38:21
maintainer
docs_urlNone
authorrcmdnk
requires_python>=3.9,<4.0
licenseApache-2.0
keywords xgb xgb_config_home git config
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # conf-finder

[![test](https://github.com/rcmdnk/conf-finder/actions/workflows/test.yml/badge.svg)](https://github.com/rcmdnk/conf-finder/actions/workflows/test.yml)
[![test coverage](https://img.shields.io/badge/coverage-check%20here-blue.svg)](https://github.com/rcmdnk/conf-finder/tree/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

```bash
$ pip install conf-finder
```

## Usage

```python
from conf_finder import ConfFinder


cf = ConfFinder("mytool")
print(cf.directory())
```

This script searches for:

- **./.mytool**
- **<Git root directory>/.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`).

```python
from conf_finder import ConfFinder


cf = ConfFinder("mytool")
print(cf.conf(exe="toml"))
```

This script searches for:

- **./.mytool.toml**
- **<Git root directory>/.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**
- **<Git root directory>/.mytool/conf.toml**
- **$XDG_CONFIG_HOME/mytool/conf.toml**
- **~/.mytool/conf.toml**

```python
from conf_finder import ConfFinder


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

This script searches for:

- **./.myconf.toml**
- **<Git root directory>/.myconf.toml**
- **$XDG_CONFIG_HOME/myconf.toml**
- **~/.myconf.toml**
- **./.mytool/myconf.toml**
- **<Git root directory>/.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'`:

```python
from conf_finder import ConfFinder


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

This script searches for:

- **./.myconf.toml**
- **<Git root directory>/.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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rcmdnk/conf-finder",
    "name": "conf-finder",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "XGB,XGB_CONFIG_HOME,Git,CONFIG",
    "author": "rcmdnk",
    "author_email": "rcmdnk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f5/64/d549f987ab3688ef898d135dbabcf67518df10299acd52518601ccfda77f/conf_finder-0.1.2.tar.gz",
    "platform": null,
    "description": "# conf-finder\n\n[![test](https://github.com/rcmdnk/conf-finder/actions/workflows/test.yml/badge.svg)](https://github.com/rcmdnk/conf-finder/actions/workflows/test.yml)\n[![test coverage](https://img.shields.io/badge/coverage-check%20here-blue.svg)](https://github.com/rcmdnk/conf-finder/tree/coverage)\n\nConfiguration file finder.\n\nThe configuration file/directory is searched for in the following locations by default:\n\n- The current directory\n- Git root repository (if the current directory is within a repository)\n- XDG config home (`$XDG_CONFIG_HOME`; if not set, **~/.config** is used)\n- Home directory\n\nTo locate the configuration directory, the tool searches for a dot-prefixed\nname (e.g., .**mytool**) in all locations except for the XDG config home.\nWithin the XDG config home, a name without the dot prefix (e.g., **mytool**)\nis searched for.\n\nIf no directory is found, the path under the XDG config home is returned.\n\nTo locate the configuration file, the tool first searches for a dot-prefixed\nfile (e.g., **.myconf.txt**) in all locations except for the XDG config home.\nWithin the XDG config home, a file name without the dot prefix\n(e.g., **myconf.txt**) is searched for. Following this, an attempt is made\nto find the file within the located configuration directories.\n\nIf no file is found, the path under the configuration directory within\nthe XDG config home is returned.\n\n## Requirement\n\n- Python 3.9, 3.10, 3.11\n\n## Installation\n\n```bash\n$ pip install conf-finder\n```\n\n## Usage\n\n```python\nfrom conf_finder import ConfFinder\n\n\ncf = ConfFinder(\"mytool\")\nprint(cf.directory())\n```\n\nThis script searches for:\n\n- **./.mytool**\n- **<Git root directory>/.mytool** if here is under the git repository.\n- **$XDG_CONFIG_HOME/mytool** (If `XDG_CONFIG_HOME` is not set, use `~/.config`.)\n- **~/.mytool**\n\nIf no directory is found, return `$XDG_CONFIG_HOME/mytool` (or `~/.config/mytool`).\n\n```python\nfrom conf_finder import ConfFinder\n\n\ncf = ConfFinder(\"mytool\")\nprint(cf.conf(exe=\"toml\"))\n```\n\nThis script searches for:\n\n- **./.mytool.toml**\n- **<Git root directory>/.mytool.toml** if here is under the git repository.\n- **$XDG_CONFIG_HOME/mytool.toml** (If `XDG_CONFIG_HOME` is not set, use `~/.config`.)\n- **~/.mytool.toml**\n- **./.mytool/conf.toml**\n- **<Git root directory>/.mytool/conf.toml**\n- **$XDG_CONFIG_HOME/mytool/conf.toml**\n- **~/.mytool/conf.toml**\n\n```python\nfrom conf_finder import ConfFinder\n\n\ncf = ConfFinder(\"mytool\")\nprint(cf.conf(\"mytool\", \"toml\", \"myconf\"))\n```\n\nThis script searches for:\n\n- **./.myconf.toml**\n- **<Git root directory>/.myconf.toml**\n- **$XDG_CONFIG_HOME/myconf.toml**\n- **~/.myconf.toml**\n- **./.mytool/myconf.toml**\n- **<Git root directory>/.mytool/myconf.toml**\n- **$XDG_CONFIG_HOME/mytool/myconf.toml**\n- **~/.mytool/myconf.toml**\n\nIf you wish to search for only files directly placed under the search directories,\n`conf_type` to `'file'`:\n\n```python\nfrom conf_finder import ConfFinder\n\n\ncf = ConfFinder(\"mytool\", conf_type=\"file\")\nprint(cf.conf(\"mytool\", \"toml\", \"myconf\"))\n```\n\nThis script searches for:\n\n- **./.myconf.toml**\n- **<Git root directory>/.myconf.toml**\n- **$XDG_CONFIG_HOME/myconf.toml**\n- **~/.myconf.toml**\n\nIf no file is found, **$XDG_CONFIG_HOME/myconf.toml** is returned.\n\nTo search for only directories, `conf_type` to `'dir'` instead.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Configuration file finder.",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/rcmdnk/conf-finder",
        "Repository": "https://github.com/rcmdnk/conf-finder"
    },
    "split_keywords": [
        "xgb",
        "xgb_config_home",
        "git",
        "config"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f5a8e016c87c96d60349e0efe93af0eaf2866a2d793bb731e5d3e4bbf823059d",
                "md5": "7613fe73d666d5cab124606f22e2bb6e",
                "sha256": "eceacd520659be9965ef96c99cd27fca3d55f7a5bf2e84b89428d8d02a3ac22b"
            },
            "downloads": -1,
            "filename": "conf_finder-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7613fe73d666d5cab124606f22e2bb6e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 8394,
            "upload_time": "2023-10-04T05:38:20",
            "upload_time_iso_8601": "2023-10-04T05:38:20.687974Z",
            "url": "https://files.pythonhosted.org/packages/f5/a8/e016c87c96d60349e0efe93af0eaf2866a2d793bb731e5d3e4bbf823059d/conf_finder-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f564d549f987ab3688ef898d135dbabcf67518df10299acd52518601ccfda77f",
                "md5": "a75878179b1865aa577419fe1ebeb81d",
                "sha256": "7a9dd22ad36e83d39b62f7985772c9ade1fc73fddc86aa42229bfa7288f4595b"
            },
            "downloads": -1,
            "filename": "conf_finder-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a75878179b1865aa577419fe1ebeb81d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 8263,
            "upload_time": "2023-10-04T05:38:21",
            "upload_time_iso_8601": "2023-10-04T05:38:21.947799Z",
            "url": "https://files.pythonhosted.org/packages/f5/64/d549f987ab3688ef898d135dbabcf67518df10299acd52518601ccfda77f/conf_finder-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-04 05:38:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rcmdnk",
    "github_project": "conf-finder",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "conf-finder"
}
        
Elapsed time: 0.12715s