A Python wrapper around `git` to check filenames against `.gitignore` files
Project description
git-check-ignore
This is a wrapper around git's check-ignore
command.
It can be used to determine if a particular pathname would be ignored by a repository's
.gitignore files. It shells out to git to accomplish this. This has the
disadvantage that you must have git installed and available on your PATH, but has the
advantage that this module's results will always agree with git's.
Installation
git-check-ignore can be installed from PyPI:
pip install git-check-ignore
Documentation
Documentation can be found at https://dd-dockyard.github.io/git-check-ignore/
The source code can be found at https://github.com/dd-dockyard/git-check-ignore
Example Usage
The ignored_pathnames and not_ignored_pathnames functions are the simplest way to use this module.
Given a list of names, they iterate through the names that would or would not be ignored by git:
from git_check_ignore import ignored_pathnames, not_ignored_pathnames
for ignored in ignored_pathnames("README.md", "foo.py", "bar.py"):
print(f"{ignored} is ignored")
for not_ignored in not_ignored_pathnames("README.md", "foo.py", "bar.py"):
print(f"{not_ignored} is not ignored")
The ignored_paths and not_ignored_paths functions are the same, but return pathlib.Path objects:
from git_check_ignore import ignored_pathnames, not_ignored_pathnames
for ignored in ignored_paths("README.md", "foo.py", "bar.py"):
if ignored.exists():
print(f"{ignored} is ignored and exists")
for not_ignored in not_ignored_paths("README.md", "foo.py", "bar.py"):
if not_ignored.exists():
print(f"{not_ignored} is not ignored and exists")
The git_check_ignore function provides the most information, and allows you to determine which .gitignore pattern matched a particular pathname:
from git_check_ignore import git_check_ignore
for r in git_check_ignore("README.md", "foo.py", "bar.py"):
if r.ignored:
print(f"{r.pathname} is ignored")
if r.match:
print(f"matched {r.match.pattern} at line {r.match.linenum} of {r.match.source}")
License
This software is provided under the terms of the AGPL 3.0 license.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_check_ignore-1.0.0.tar.gz.
File metadata
- Download URL: git_check_ignore-1.0.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e69227be41262449d9069fb6650518b9ee22fb73c1774a2a8da68029381e3d3e
|
|
| MD5 |
9fe24d42f90e93af850dbee7991b13df
|
|
| BLAKE2b-256 |
639931ad5160b1449e8dc48a27ca4157bdb4001c54221e9561af41ea9e7df1a6
|
Provenance
The following attestation bundles were made for git_check_ignore-1.0.0.tar.gz:
Publisher:
publish.yml on dd-dockyard/git-check-ignore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
git_check_ignore-1.0.0.tar.gz -
Subject digest:
e69227be41262449d9069fb6650518b9ee22fb73c1774a2a8da68029381e3d3e - Sigstore transparency entry: 200841493
- Sigstore integration time:
-
Permalink:
dd-dockyard/git-check-ignore@7752325d629aac588dd506d403904788249efdc0 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/dd-dockyard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7752325d629aac588dd506d403904788249efdc0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file git_check_ignore-1.0.0-py3-none-any.whl.
File metadata
- Download URL: git_check_ignore-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95838a58ea4c3bb39a18db73d1e748d3f51222a52e5f6a377e63fcca7bbbbe20
|
|
| MD5 |
a7eda76c5c53d1228899fb736a269fb3
|
|
| BLAKE2b-256 |
6e1f8930bbc47f939f53c89bf74e7f2522fe896634c8669c0d3c9928e219b5c3
|
Provenance
The following attestation bundles were made for git_check_ignore-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on dd-dockyard/git-check-ignore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
git_check_ignore-1.0.0-py3-none-any.whl -
Subject digest:
95838a58ea4c3bb39a18db73d1e748d3f51222a52e5f6a377e63fcca7bbbbe20 - Sigstore transparency entry: 200841496
- Sigstore integration time:
-
Permalink:
dd-dockyard/git-check-ignore@7752325d629aac588dd506d403904788249efdc0 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/dd-dockyard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7752325d629aac588dd506d403904788249efdc0 -
Trigger Event:
push
-
Statement type: