Skip to main content

Use the syntax and semantics of gitignore with custom ignore file names and locations

Project description

ignorelib

Use the syntax and semantics of gitignore with custom ignore file names and locations

git has a comprehensive mechanism for selecting files to ignore inside repositories. ignorelib lets you use the same system, customized to your own needs.

You can read about the semantics of gitignore here: https://git-scm.com/docs/gitignore

This library is a lightly-modified version of the gitignore implementation in dulwich, a pure Python implementation of git.

Installation

python -m pip install ignorelib

Usage

The primary entrypoint is the class factory method IgnoreFilterManager.build(), with the following inputs:

  • path: the root path (required). All path checks you make are relative to this path.
  • global_patterns: an optional list of global ignore patterns. These are the things that should always be ignored (for git, this would be .git to exclude the repo directory)
  • global_ignore_file_paths: an optional list of file paths to attempt to load global ignore patterns from.
    • Relative paths are relative to the root path (for git, this would be .git/info/exclude)
    • User expansion is performed, so paths like (for git) ~/.config/git/ignore work.
    • Files that cannot be loaded are silently ignored, so you don't need to check if they exist or not.
    • Patterns in these files take precendence over the patterns in global_patterns.
  • ignore_file_name: an optional file name for the per-directory ignore file (for git, this would be .gitignore).
  • ignore_case: an optional boolean for specifying whether to ignore case, defaulting to false.

With an IgnoreFilterManager object, you check if a given path is ignored with is_ignored(), which takes a (relative) path and returns True if it matches an ignore pattern. It returns False if it is explicitly not ignored (using a pattern starting with !), or None if the file does not match any patterns. Note that this allows you to distinguish between the default state (not ignoring) and actually matching a pattern that prevents it from being ignored.

To iterate over not-ignored files, IgnoreFilterManager.walk() has the same interface as os.walk() but without taking a root path, as this comes from the the IgnoreFilterManager.

After using an IgnoreFilterManager instance to get a number of paths, you can extract the state (i.e., all loaded patterns with their sources) in a JSON-serializable format with the IgnoreFilterManager.to_dict() method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ignorelib-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ignorelib-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file ignorelib-0.1.0.tar.gz.

File metadata

  • Download URL: ignorelib-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/4.19.128-microsoft-standard

File hashes

Hashes for ignorelib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f39d2ae4bb3673569d1c2a595951ca25a1b9eda0bcdae5525b9eea9b861ee18
MD5 ea5cfe6519b954bd4123f593aa3ad579
BLAKE2b-256 cf6a82e2d88d82a8ac8efb048e38a25867802200c9db14cb9e5454105c6c47b8

See more details on using hashes here.

File details

Details for the file ignorelib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ignorelib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/4.19.128-microsoft-standard

File hashes

Hashes for ignorelib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b99136bc9b2956755ce7ecc661998b98d7fef8562ad72fbc389b10f66624e789
MD5 9c2ea1c3b561d28ed74a9b9251c65ac1
BLAKE2b-256 5909d182b428d5e889c7bb93ada2146f7c4f2df2914556b54253bc86ecf3aabf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page