Skip to main content

An implementation of Apache Ant FileSet and Globs

Project description

Features

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:

  1. Includes files from one or more Ant Globs, then

  2. 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 (…).

Python has built-in support for simple globs in fnmatcher and glob, but Formic:

  • 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.

Quickstart

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_*"

Or integrated right into your Python 2.7 project:

import formic
fileset = formic.FileSet(include="**.py",
                         exclude=["**/*test*/**", "test_*"]
                         )

for file_name in fileset.qualified_files():
    # Do something with file_name
    ...

That’s about it :)

About

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.

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

formic-0.9beta3.tar.gz (39.7 kB view details)

Uploaded Source

Built Distribution

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

formic-0.9beta3-py2.7.egg (79.4 kB view details)

Uploaded Egg

File details

Details for the file formic-0.9beta3.tar.gz.

File metadata

  • Download URL: formic-0.9beta3.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for formic-0.9beta3.tar.gz
Algorithm Hash digest
SHA256 203a112a2f7ceb9a536af55427538c258b24b4e422eabba876c838a6dc33aaf0
MD5 ee500f969154e549cc5292a244b5f7b9
BLAKE2b-256 e369b087e7b3cc16a7b3be79e56c827c409864228bda9356983f50ee74a3a67e

See more details on using hashes here.

File details

Details for the file formic-0.9beta3-py2.7.egg.

File metadata

  • Download URL: formic-0.9beta3-py2.7.egg
  • Upload date:
  • Size: 79.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for formic-0.9beta3-py2.7.egg
Algorithm Hash digest
SHA256 319e8451699a07cce189082251f8f996990f9babf93e939969076071a57acb48
MD5 468d1e203034965912aa27897a6af082
BLAKE2b-256 6a89f664afebf50e3b2250fbcca67bdc6df94f2472b4c76f823763b369f8232e

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