Skip to main content

History

Formic is forked from https://bitbucket.org/aviser/formic. The original project only supports python2.7 and has not been maintained for a long time.

I added Python3 supports and fixed some issues. Formic now can work on any Python 2.6+ or Python 3.4+ system. If not, please file an issue. Yet not tested on other Python version.

Formic has no runtime dependencies outside the Python system libraries.

Install

Formic can be installed from the Cheeseshop with easy_install:

$ easy_install formic2

Or pip:

$ pip install formic2

Quickstart

Once installed, you can use Formic either from the command line to find from the current directory:

$ 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_.

You can also find from the specified directory like below:

$ formic /specified/directory/can/ignore/ -i "*.py" "**/test/**/*.txt" "*.ini"

Output from Formic is formatted like the Unix find command, and so can easily be combined with other executables, eg:

$ formic -i "**/*.bak" | xargs rm

will delete all .bak files in or under the current directory (but excluding VCS directories such as .svn and .hg).

Formic can also be integrated right into your Python project:

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

for file_name in fileset:
    # Do something with file_name
    ...

Formic is always case-insensitive on NT, but can be either case-sensitive or case-insensitive on POSIX.

On NT:

$ formic ./test/ -i "upp*" "upp*/"
/some/where/formic/test/lower/UPPER.txt
/some/where/formic/test/UPPER/lower.txt
/some/where/formic/test/UPPER/UPPER.txt

On POSIX with case-insensitive:

$ formic ./test/ --insensitive -i "upp*" "upp*/"
/some/where/formic/test/lower/UPPER.txt
/some/where/formic/test/UPPER/lower.txt
/some/where/formic/test/UPPER/UPPER.txt

with case-sensitive:

$ formic ./test/ -i "upp*" "upp*/"
$

That’s about it :)

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.

About

Formic is originally written and maintained by Andrew Alcock of Aviser LLP, Singapore.

But now, I forked it on GitHub and will maintain this project voluntarily for a long time.

Release files for formic2 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for formic2 1.0.3
File Size Uploaded
formic2-1.0.3.tar.gz 46.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for formic2 1.0.3
File Interpreter ABI Platform
formic2-1.0.3-py3-none-any.whl Python 3 none any Details
formic2-1.0.3-py2-none-any.whl Python 2 none any Details

Total release size: 112.0 kB

Release files / formic2-1.0.3.tar.gz

Download URL formic2-1.0.3.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
21bedd18fbd9010638b7449c7ce008b424a5f8835c224b81fbd07f666bfc6808
BLAKE2b-256 checksum
How to use checksums
da64ac788d2757dcc9a20a7662da53ec51e1cce4b4400be55716e0bd4f30ec7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / formic2-1.0.3-py3-none-any.whl

Download URL formic2-1.0.3-py3-none-any.whl
Size 32.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0897c188b7d182525de12bc9c0c1472b88856a9d87884f7c38717f8393366c61
BLAKE2b-256 checksum
How to use checksums
1c8ad637ab862578f5c3975f237a99ad3a6ca0130306dd46870a0e57159d3b5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / formic2-1.0.3-py2-none-any.whl

Download URL formic2-1.0.3-py2-none-any.whl
Size 32.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
94abc00d86403585ad4991dd59a66cadbc9a49143e965e20319d1e44ef030a87
BLAKE2b-256 checksum
How to use checksums
f3b0aca6e113afccc52e56732ee17878beeb75dbef394b06553acf1a9b0abb47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.3 This release

3 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page