Formic is a Python implementation of Apache Ant FileSet and Globs including the directory wildcard **.
FileSet provides a terse way of specifying a set of files without having to enumerate individual files. It:
Ant Globs are a superset of ordinary file system globs. The key differences:
This approach is the de-facto standard in several other languages and tools, including Apache Ant and Maven, Ruby (Dir) and Perforce (...).
Python has built-in support for simple globs in fnmatcher and glob, but Formic:
Formic can be installed from the Cheeseshop with easy_install or pip:
$ easy_install formic
Once installed, you can use Formic either from the command line:
$ formic -i "*.py" -e "__init__.py" "**/*test*/" "test_*"
This will search for files all Python files under the current directory excluding all __init__.py files, any file in directories whose name contains the word ‘test’, and any files that start test_.
Or integrated right into your Python 2.7 project:
import formic
fileset = formic.FileSet(include="**.py",
exclude=["**/*test*/**", "test_*"]
)
for file_name in fileset:
# Do something with file_name
...
That’s about it :)
Formic is written and maintained by Andrew Alcock of Aviser LLP, Singapore.
Formic is Copyright (C) 2012, Aviser LLP and released under GPLv3. Aviser LLP would be happy to discuss other licensing arrangements; for details, please email the maintainer.