A spec-compliant `.gitignore` parser for Python
Project description
gitignorefile
A spec-compliant .gitignore
parser for Python.
Installation
pip3 install gitignorefile
Usage
gitignorefile.parse()
Parse single .gitignore
file. Suppose /home/michael/project/.gitignore
contains the following:
__pycache__/
*.py[cod]
Then:
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:
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.
import gitignorefile
gitignorefile.ignored("/home/michael/project/main.py") # False
gitignorefile.Cache
Caches .gitignore
rules discovered in the directory tree.
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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gitignorefile-1.0.5.tar.gz
(10.4 kB
view details)
File details
Details for the file gitignorefile-1.0.5.tar.gz
.
File metadata
- Download URL: gitignorefile-1.0.5.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f05f3889fc2f4d088ea6073c120d1924d3d7ed17fa22a434da32f729bf8ead0 |
|
MD5 | 320cda5df8acc8fcd5714bddb147d501 |
|
BLAKE2b-256 | c35614239f199b3cd510689c9ea6f266c6e6a30d5c8305a85d1986226385f3c9 |