gitignorefile


Namegitignorefile JSON
Version 1.1.2 PyPI version JSON
download
home_pagehttps://github.com/excitoon/gitignorefile
SummaryA spec-compliant `.gitignore` parser for Python
upload_time2022-09-04 15:50:02
maintainer
docs_urlNone
authorVladimir Chebotarev
requires_python
licenseMIT
keywords git gitignore
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `gitignorefile`

[![Black](https://github.com/excitoon/gitignorefile/actions/workflows/black.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/black.yml)
[![Linux](https://github.com/excitoon/gitignorefile/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/ubuntu.yml)
[![OS X](https://github.com/excitoon/gitignorefile/actions/workflows/macos.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/macos.yml)
[![Windows](https://github.com/excitoon/gitignorefile/actions/workflows/windows.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/windows.yml)
[![PyPI](https://badge.fury.io/py/gitignorefile.svg)](https://badge.fury.io/py/gitignorefile)

A spec-compliant `.gitignore` parser for Python.

## Installation

```
pip3 install gitignorefile
```

## Usage

### `gitignorefile.parse()`

Parses single `.gitignore` file. Suppose `/home/michael/project/.gitignore` contains the following:

```
__pycache__/
*.py[cod]
```

Then:

```python3
import gitignorefile

matches = gitignorefile.parse("/home/michael/project/.gitignore")
matches("/home/michael/project/main.py") # False
matches("/home/michael/project/main.pyc") # True
matches("/home/michael/project/dir/main.pyc") # True
matches("/home/michael/project/__pycache__") # True
```

### `gitignorefile.ignore()`

`shutil.copytree()` ignore function which checks if file is ignored by any `.gitignore` in the directory tree.

Example:

```python3
import shutil
import gitignorefile

shutil.copytree("/source", "/destination", ignore=gitignorefile.ignore())
```

### `gitignorefile.ignored()`

Checks if file is ignored by any `.gitignore` in the directory tree.

```python3
import gitignorefile

gitignorefile.ignored("/home/michael/project/main.py") # False
```

### `gitignorefile.Cache`

Caches `.gitignore` rules discovered in the directory tree.

```python3
import gitignorefile

matches = gitignorefile.Cache()
matches("/home/michael/project/main.py") # False
matches("/home/michael/project/main.pyc") # True
matches("/home/michael/project/dir/main.pyc") # True
matches("/home/michael/project/__pycache__") # True
```

### Custom ignore file sources

You could override files, that will be used to fetch ignore rules. Default value is `[".gitignore", ".git/info/exclude"]`.

```python3
import gitignorefile

matches = gitignorefile.Cache(ignore_names=[".mylovelytoolignore"])
matches("/home/michael/project/main.py") # False
matches("/home/michael/project/main.pyc") # True
matches("/home/michael/project/dir/main.pyc") # True
matches("/home/michael/project/__pycache__") # True
```


## Credits

- https://github.com/snark/ignorance by Steve Cook
- https://github.com/mherrmann/gitignore_parser by Michael Herrmann
- https://github.com/bitranox/igittigitt by Robert Nowotny
- https://github.com/cpburnz/python-path-specification by Caleb Burns
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/excitoon/gitignorefile",
    "name": "gitignorefile",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "git,gitignore",
    "author": "Vladimir Chebotarev",
    "author_email": "vladimir.chebotarev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/91/ae/d983db08d9c5f3dd593b46316d115b8988c25c554072293603a7bc7d52ed/gitignorefile-1.1.2.tar.gz",
    "platform": null,
    "description": "# `gitignorefile`\n\n[![Black](https://github.com/excitoon/gitignorefile/actions/workflows/black.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/black.yml)\n[![Linux](https://github.com/excitoon/gitignorefile/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/ubuntu.yml)\n[![OS X](https://github.com/excitoon/gitignorefile/actions/workflows/macos.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/macos.yml)\n[![Windows](https://github.com/excitoon/gitignorefile/actions/workflows/windows.yml/badge.svg)](https://github.com/excitoon/gitignorefile/actions/workflows/windows.yml)\n[![PyPI](https://badge.fury.io/py/gitignorefile.svg)](https://badge.fury.io/py/gitignorefile)\n\nA spec-compliant `.gitignore` parser for Python.\n\n## Installation\n\n```\npip3 install gitignorefile\n```\n\n## Usage\n\n### `gitignorefile.parse()`\n\nParses single `.gitignore` file. Suppose `/home/michael/project/.gitignore` contains the following:\n\n```\n__pycache__/\n*.py[cod]\n```\n\nThen:\n\n```python3\nimport gitignorefile\n\nmatches = gitignorefile.parse(\"/home/michael/project/.gitignore\")\nmatches(\"/home/michael/project/main.py\") # False\nmatches(\"/home/michael/project/main.pyc\") # True\nmatches(\"/home/michael/project/dir/main.pyc\") # True\nmatches(\"/home/michael/project/__pycache__\") # True\n```\n\n### `gitignorefile.ignore()`\n\n`shutil.copytree()` ignore function which checks if file is ignored by any `.gitignore` in the directory tree.\n\nExample:\n\n```python3\nimport shutil\nimport gitignorefile\n\nshutil.copytree(\"/source\", \"/destination\", ignore=gitignorefile.ignore())\n```\n\n### `gitignorefile.ignored()`\n\nChecks if file is ignored by any `.gitignore` in the directory tree.\n\n```python3\nimport gitignorefile\n\ngitignorefile.ignored(\"/home/michael/project/main.py\") # False\n```\n\n### `gitignorefile.Cache`\n\nCaches `.gitignore` rules discovered in the directory tree.\n\n```python3\nimport gitignorefile\n\nmatches = gitignorefile.Cache()\nmatches(\"/home/michael/project/main.py\") # False\nmatches(\"/home/michael/project/main.pyc\") # True\nmatches(\"/home/michael/project/dir/main.pyc\") # True\nmatches(\"/home/michael/project/__pycache__\") # True\n```\n\n### Custom ignore file sources\n\nYou could override files, that will be used to fetch ignore rules. Default value is `[\".gitignore\", \".git/info/exclude\"]`.\n\n```python3\nimport gitignorefile\n\nmatches = gitignorefile.Cache(ignore_names=[\".mylovelytoolignore\"])\nmatches(\"/home/michael/project/main.py\") # False\nmatches(\"/home/michael/project/main.pyc\") # True\nmatches(\"/home/michael/project/dir/main.pyc\") # True\nmatches(\"/home/michael/project/__pycache__\") # True\n```\n\n\n## Credits\n\n- https://github.com/snark/ignorance by Steve Cook\n- https://github.com/mherrmann/gitignore_parser by Michael Herrmann\n- https://github.com/bitranox/igittigitt by Robert Nowotny\n- https://github.com/cpburnz/python-path-specification by Caleb Burns",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A spec-compliant `.gitignore` parser for Python",
    "version": "1.1.2",
    "split_keywords": [
        "git",
        "gitignore"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "91aed983db08d9c5f3dd593b46316d115b8988c25c554072293603a7bc7d52ed",
                "md5": "2c1ee729c45e71c5520faf0e0395d094",
                "sha256": "ce1f6c97d46d7684d3dd3cf768185a3b252a715e026b6fc90103b64d826e4656"
            },
            "downloads": -1,
            "filename": "gitignorefile-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2c1ee729c45e71c5520faf0e0395d094",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12171,
            "upload_time": "2022-09-04T15:50:02",
            "upload_time_iso_8601": "2022-09-04T15:50:02.040859Z",
            "url": "https://files.pythonhosted.org/packages/91/ae/d983db08d9c5f3dd593b46316d115b8988c25c554072293603a7bc7d52ed/gitignorefile-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-04 15:50:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "excitoon",
    "github_project": "gitignorefile",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "gitignorefile"
}
        
Elapsed time: 0.05727s