conf-finder


Nameconf-finder JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/rcmdnk/conf-finder
SummaryConfiguration file finder.
upload_time2024-05-23 00:26:57
maintainerNone
docs_urlNone
authorrcmdnk
requires_python<4.0,>=3.10
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": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "XGB, XGB_CONFIG_HOME, Git, CONFIG",
    "author": "rcmdnk",
    "author_email": "rcmdnk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ef/f0/26877e594231955ade54550708b3cb37df3e80081d77b76ff53f5456ab62/conf_finder-0.1.3.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.3",
    "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": "0a71b3e0fbf565dbd6bddb5db2f9dafe4b5bbcc385f3b0391009a15d8a5713dd",
                "md5": "9f090a43f7a37bbc90c3458601b1a69f",
                "sha256": "816f0aefed835bc262a0dc50a9e6319a0079f1c5e2e7d9707824c9d615e99287"
            },
            "downloads": -1,
            "filename": "conf_finder-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9f090a43f7a37bbc90c3458601b1a69f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 8551,
            "upload_time": "2024-05-23T00:26:55",
            "upload_time_iso_8601": "2024-05-23T00:26:55.250055Z",
            "url": "https://files.pythonhosted.org/packages/0a/71/b3e0fbf565dbd6bddb5db2f9dafe4b5bbcc385f3b0391009a15d8a5713dd/conf_finder-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eff026877e594231955ade54550708b3cb37df3e80081d77b76ff53f5456ab62",
                "md5": "8bf3d71a8dda81177b57e12dc99c8071",
                "sha256": "99e35ae3b419d46f11ce54fa045ee93899b326066e464c9dd674f79a9e84640b"
            },
            "downloads": -1,
            "filename": "conf_finder-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "8bf3d71a8dda81177b57e12dc99c8071",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 8382,
            "upload_time": "2024-05-23T00:26:57",
            "upload_time_iso_8601": "2024-05-23T00:26:57.120086Z",
            "url": "https://files.pythonhosted.org/packages/ef/f0/26877e594231955ade54550708b3cb37df3e80081d77b76ff53f5456ab62/conf_finder-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 00:26:57",
    "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.27110s