|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +DeepDiff is a Python library for deep comparison, searching, and hashing of Python objects. It provides: |
| 8 | +- **DeepDiff**: Deep difference detection between objects |
| 9 | +- **DeepSearch**: Search for objects within other objects |
| 10 | +- **DeepHash**: Content-based hashing for any object |
| 11 | +- **Delta**: Git-like diff objects that can be applied to other objects |
| 12 | +- **CLI**: Command-line interface via `deep` command |
| 13 | + |
| 14 | +## Development Commands |
| 15 | + |
| 16 | +### Setup |
| 17 | +```bash |
| 18 | +# Install with all development dependencies |
| 19 | +uv pip install -e ".[cli,coverage,dev,docs,static,test]" |
| 20 | +# OR using uv (recommended) |
| 21 | +uv sync --all-extras |
| 22 | +``` |
| 23 | + |
| 24 | +**Virtual Environment**: Activate with `source ~/.venvs/deep/bin/activate` before running tests or Python commands |
| 25 | + |
| 26 | + |
| 27 | +### Testing |
| 28 | +```bash |
| 29 | +# Run tests with coverage |
| 30 | +source ~/.venvs/deep/bin/activate && pytest --cov=deepdiff --cov-report term-missing |
| 31 | + |
| 32 | +# Run tests including slow ones |
| 33 | +source ~/.venvs/deep/bin/activate && pytest --cov=deepdiff --runslow |
| 34 | + |
| 35 | +# Run single test file |
| 36 | +source ~/.venvs/deep/bin/activate && pytest tests/test_diff_text.py |
| 37 | + |
| 38 | +# Run tests across multiple Python versions. No need to use this unless getting ready for creating a new build |
| 39 | +source ~/.venvs/deep/bin/activate && nox -s pytest |
| 40 | +``` |
| 41 | + |
| 42 | +### **Type Checking with Pyright:** |
| 43 | +Always use this pattern for type checking: |
| 44 | +```bash |
| 45 | +source ~/.venvs/deep/bin/activate && pyright {file_path} |
| 46 | +``` |
| 47 | + |
| 48 | +Examples: |
| 49 | +- `source ~/.venvs/deep/bin/activate && pyright deepdiff/diff.py` - Type check specific file |
| 50 | +- `source ~/.venvs/deep/bin/activate && pyright deepdiff/` - Type check entire module |
| 51 | +- `source ~/.venvs/deep/bin/activate && pyright .` - Type check entire repo |
| 52 | + |
| 53 | + |
| 54 | +### Common Pitfalls to Avoid |
| 55 | + |
| 56 | +1. **Forgetting Virtual Environment**: ALWAYS activate venv before ANY Python command: |
| 57 | + ```bash |
| 58 | + source ~/.venvs/deep/bin/activate |
| 59 | + ``` |
| 60 | +2. **Running pytest without venv**: This will cause import errors. Always use: |
| 61 | + ```bash |
| 62 | + source ~/.venvs/deep/bin/activate && pytest |
| 63 | + ``` |
| 64 | +3. **Running module commands without venv**: Commands like `capi run`, `cettings shell`, etc. all require venv to be activated first |
| 65 | + |
| 66 | + |
| 67 | +### Slow quality checks only to run before creating a build |
| 68 | +```bash |
| 69 | +# Linting (max line length: 120) |
| 70 | +nox -s flake8 |
| 71 | + |
| 72 | +# Type checking |
| 73 | +nox -s mypy |
| 74 | + |
| 75 | +# Run all quality checks |
| 76 | +nox |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | +## Architecture |
| 81 | + |
| 82 | +### Core Structure |
| 83 | +- **deepdiff/diff.py**: Main DeepDiff implementation (most complex component) |
| 84 | +- **deepdiff/deephash.py**: DeepHash functionality |
| 85 | +- **deepdiff/base.py**: Shared base classes and functionality |
| 86 | +- **deepdiff/model.py**: Core data structures and result objects |
| 87 | +- **deepdiff/helper.py**: Utility functions and type definitions |
| 88 | +- **deepdiff/delta.py**: Delta objects for applying changes |
| 89 | + |
| 90 | +### Key Patterns |
| 91 | +- **Inheritance**: `Base` class provides common functionality with mixins |
| 92 | +- **Result Objects**: Different result formats (`ResultDict`, `TreeResult`, `TextResult`) |
| 93 | +- **Path Navigation**: Consistent path notation for nested object access |
| 94 | +- **Performance**: LRU caching and numpy array optimization |
| 95 | + |
| 96 | +### Testing |
| 97 | +- Located in `/tests/` directory |
| 98 | +- Organized by functionality (e.g., `test_diff_text.py`, `test_hash.py`) |
| 99 | +- Aims for ~100% test coverage |
| 100 | +- Uses pytest with comprehensive fixtures |
| 101 | + |
| 102 | +## Development Notes |
| 103 | + |
| 104 | +- **Python Support**: 3.9+ and PyPy3 |
| 105 | +- **Main Branch**: `master` (PRs typically go to `dev` branch) |
| 106 | +- **Build System**: Modern `pyproject.toml` with `flit_core` |
| 107 | +- **Dependencies**: Core dependency is `orderly-set>=5.4.1,<6` |
| 108 | +- **CLI Tool**: Available as `deep` command after installation with `[cli]` extra |
0 commit comments