A command-line tool to remove code sections marked with tags from Python files and Jupyter notebooks.
Caviar processes Python files (.py) and Jupyter notebooks (.ipynb) to remove code sections enclosed between configurable start and end tags. This is particularly useful for creating clean exercise templates by removing solution code.
pip install -e .caviar --source <source_dir> --target <target_dir> --starting-tag <start> --ending-tag <end>--source: Source directory containing files to process--target: Target directory where processed files will be saved--starting-tag: Tag marking the beginning of content to remove (default:STRIP_START)--ending-tag: Tag marking the end of content to remove (default:STRIP_END)
You can also set parameters using environment variables:
export SOURCE=/path/to/source
export TARGET=/path/to/target
export STARTING_TAG=STRIP_START
export ENDING_TAG=STRIP_ENDGiven a Python file with tagged content:
print("This will be kept")
# STRIP_START
print("This will be removed")
x = 42
# STRIP_END
print("This will also be kept")Running Caviar will produce:
print("This will be kept")
print("This will also be kept")- ✅ Processes Python files (
.py) - ✅ Processes Jupyter notebooks (
.ipynb) - ✅ Processes Markdown files (
.md) - ✅ Preserves directory structure
- ✅ Handles missing end tags gracefully (no crashes)
- ✅ Configurable start/end tags
- ✅ Environment variable support
- Python ≥ 3.6
- click ≥ 8.1.7
- nbformat == 5.10.4
MIT License - see project metadata for details.