An implementation of Apache Ant FileSet and Globs
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:
- Includes files from one or more Ant Globs, then
- Optionally excludes files matching further Ant Globs.
Ant Globs are a superset of ordinary file system globs. The key differences:
- They match whole paths, eg /root/myapp/*.py
- ** matches any directory or directories, eg /root/**/*.py matches /root/one/two/my.py
- You can match the topmost directory or directories, eg /root/**, or
- The parent directory of the file, eg **/parent/*.py, or
- Any parent directory, eg **/test/**/*.py
This approach is the de-facto standard in several other languages and tools, including Apache Ant and Maven, Ruby (Dir) and Perforce (…).
- Can recursively scan subdirectories
- Matches arbitrary directories in the path (eg /1/**/2/**/3/**/*.py).
- Has a high level interface:
- Specify one or more globs to find files
- Globs can be used to exclude files
- Ant, and Formic, has a set of default excludes. These are files and directories that, by default, are automatically excluded from all searches. The majority of these are files and directories related to VCS (eg .svn directories). Formic adds __pycache__.
- Iterate through all matches in the sub-tree
- Is more efficient with many common patterns; it runs relatively faster on large directory trees with large numbers of files.
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 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.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size formic-0.9beta8.tar.gz (45.5 kB)||File type Source||Python version None||Upload date||Hashes View|
|Filename, size formic-0.9beta8-py2.7.egg (69.8 kB)||File type Egg||Python version 2.7||Upload date||Hashes View|