Git Product home page Git Product logo

py-pathmatch's Introduction

Pathmatch

Python implementation of git's wildmatch and POSIX.1-2008 fnmatch.

The aim of this package is to provide a file matching module complying with the POSIX standard and allow compatibility with git.

Example

from pathmatch import wildmatch

# Pattern matching auto-generated test files (extension .pyc, .pyo or .pyd inside tests/)
pattern = u'tests/**/*.py[cod]'

# Match single files:
wildmatch.match(pattern, u'tests/auto.pyc')  # True
wildmatch.match(pattern, u'auto.pyc')  # False

# Filter a collection:
files = [
    u'tests/deep/auto.pyd',
    u'tests/module.py',
    u'package/auto.pyc',
    u'tests/auto.pyo'
]
list(wildmatch.filter(pattern, files))  # [u'tests/deep/auto.pyd', u'tests/auto.pyo']

# Compile a pattern
compiled = wildmatch.WildmatchPattern(pattern)

compiled.match(u'tests/')  # False

Features

wildmatch support

Currently, the following wildmatch features are supported:

  • Wildstar ** operator and associated semantics (/ requires a literal match)
  • Literal matching
  • Question mark ? (any character) and asterisk * (any string) operators
  • Bracket expressions [abc] (character alternatives)

Bracket expression features:

  • Negation (supports both ^ and ! meta-characters)
  • Range expressions a-z
  • Collation Symbol [.ch.]
  • Equivalence classes syntax [=e=], but fallback to collation symbol semantics
  • Supports the path_name flag to exclude / (which requires a literal match)

See test_wildmatch.py for more details.

Limitations:

  • case_fold (case insensitive) option is not supported
  • period (require literal match for leading period) option is not supported
  • Negated bracket expression with multi-character collating elements are not supported
  • Character classes [:alpha:] for bracket expressions are not supported

Contributions are welcomed

fnmatch support

The dedicated fnmatch module is not yet configured (this should just be a subset of wildmatch).

Contributing

Tests

You can execute the tests with the following command:

python -m unittest discover -s . -p test*.py

References:

License

MIT License, Copyright (c) 2016 Charles Samborski

py-pathmatch's People

Contributors

demurgos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.