Giter VIP home page Giter VIP logo

formic's Introduction

Formic: Apache Ant FileSet and Globs in Python

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 with pip:

$ pip install formic-py3

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 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 :)

About

Formic was originally written by Andrew Alcock of Aviser LLP, Singapore. It was forked by Scott Belden to add python 3 support.

Formic is Copyright (C) 2012, Aviser LLP and python and released under GPLv3. Formic-Py3 is Copyright (C) 2017, Scott Belden.

formic's People

Contributors

atleta avatar scottbelden 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.