Formic2: Apache Ant FileSet and Globs
Formic2 is a Python library that implements Apache Ant's FileSet and Globs patterns, including the `**` directory wildcard. It provides a programmatic and command-line interface for concisely specifying and retrieving sets of files based on inclusion and exclusion rules. Version 1.0.3 was released in May 2018, and the project's release cadence is considered stalled with no recent updates.
Warnings
- gotcha The library officially supports Python 2.6+ or 3.4+. While `requires_python: <4` on PyPI suggests compatibility with Python 3.x versions up to 3.9, the documentation explicitly states it has 'not been tested on other Python version' beyond these old versions. Modern Python environments (3.10+) may encounter untested or compatibility issues.
- breaking The project is no longer actively maintained. The last release was over 7 years ago (May 2018). This means bug fixes, security patches, or new feature development are highly unlikely.
- gotcha File matching behavior for case sensitivity differs between operating systems. `formic` is always case-insensitive on Windows (NT), but is case-sensitive by default on POSIX systems (Linux/macOS) unless `casesensitive=False` is explicitly set in `FileSet`.
Install
-
pip install formic2
Imports
- FileSet
from formic import FileSet
- formic
import formic
Quickstart
import formic
import os
import tempfile
import shutil
# Create a temporary directory and some dummy files for demonstration
temp_dir = tempfile.mkdtemp()
current_dir = os.getcwd()
os.chdir(temp_dir) # Change to temp_dir to simulate working from there
print(f"Working in temporary directory: {temp_dir}")
os.makedirs("src/main/python", exist_ok=True)
os.makedirs("src/test/python", exist_ok=True)
os.makedirs("docs", exist_ok=True)
with open("src/main/python/app.py", "w") as f: f.write("print('app')")
with open("src/main/python/__init__.py", "w") as f: f.write("")
with open("src/test/python/test_app.py", "w") as f: f.write("print('test')")
with open("docs/README.md", "w") as f: f.write("# README")
with open("temp.bak", "w") as f: f.write("backup")
# Example 1: Find all Python files, excluding test files and __init__.py
print("\n--- Example 1: All Python files, excluding test files and __init__.py ---")
fileset1 = formic.FileSet(
include="**/*.py",
exclude=["**/test*/**", "**/__init__.py"],
directory=".", # Specify current directory explicitly
symlinks=False,
)
for file_name in fileset1:
print(file_name)
# Example 2: Find all markdown files
print("\n--- Example 2: All Markdown files ---")
fileset2 = formic.FileSet(
include="**/*.md",
directory="."
)
for file_name in fileset2:
print(file_name)
# Clean up
os.chdir(current_dir) # Change back to original directory
shutil.rmtree(temp_dir)
print(f"\nCleaned up temporary directory: {temp_dir}")