A powerful Python utility to clean up development dependency directories and free up valuable disk space.
This tool helps you manage and remove common development directories like node_modules
, venv
, .env
, and other cache directories that can consume significant storage space over time.
- π― Configurable target directories (
node_modules
,venv
,.env
, etc.) - π Dry run mode to preview deletions
- π Size calculation and reporting
- π‘οΈ Protected system paths
- π Detailed logging
- π¨ Color-coded output
- π€ Interactive and non-interactive modes
- πͺ Robust error handling
- Clone the repository:
git clone [email protected]:SSB-054/dep-cleaner.git
cd dep-cleaner
- Install required dependencies:
pip install -r requirements.txt
# Basic cleanup (will prompt for confirmation)
python remove_dep.py
# Start cleanup from a specific directory
python remove_dep.py --root /path/to/projects
# Preview what would be deleted (dry run)
python remove_dep.py --dry-run
# Clean specific directory types
python remove_dep.py --target-dirs node_modules venv .pytest_cache
# Non-interactive mode with logging
python remove_dep.py --no-interactive --log-file cleanup.log
# Combine multiple options
python remove_dep.py --root /home/user/projects --dry-run --target-dirs node_modules venv
Argument | Short | Description |
---|---|---|
--root |
-r |
Root directory to start the search (default: /) |
--dry-run |
-d |
Show what would be deleted without actually deleting |
--no-interactive |
-n |
Delete without asking for confirmation |
--log-file |
-l |
Path to log file |
--target-dirs |
-t |
Space-separated list of directory names to target |
You can modify the DEFAULT_TARGET_DIRS
set in the script to include additional directory types:
DEFAULT_TARGET_DIRS = {
'venv',
'node_modules',
'.env',
'__pycache__',
'.pytest_cache',
'.mypy_cache',
'your_custom_dir' # Add your custom directory here
}
Add or remove protected paths by modifying the DEFAULT_PROTECTED_PATHS
set:
DEFAULT_PROTECTED_PATHS = {
'/usr',
'/bin',
'/sbin',
'/var',
'/etc',
'/lib',
'/lib64',
'/boot',
'/sys',
'/root',
'/your/protected/path' # Add your protected path here
}
The script uses the colorama
library for colored output. You can modify the colors by changing the Fore
color values:
print(f"{Fore.GREEN}Success message") # Green text
print(f"{Fore.YELLOW}Warning message") # Yellow text
print(f"{Fore.RED}Error message") # Red text
Starting cleanup from: /home/user/projects
Delete /home/user/projects/project1/node_modules (156.42 MB)? [y/N]: y
Delete /home/user/projects/project2/venv (89.75 MB)? [y/N]: y
Cleanup Summary:
Directories processed: 2
Total space freed: 246.17 MB
Failed operations: 0
- Protected Paths: System-critical directories are protected from deletion
- Size Confirmation: Shows directory size before deletion
- Dry Run Mode: Preview what would be deleted
- Logging: Detailed logging of all operations
- Interactive Confirmation: Prompts for confirmation before each deletion
Contributions are always welcome! Here's how you can help:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement
) - Make your changes
- Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/improvement
) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Suraj Singh Bisht
- Email: [email protected]
- GitHub: @surajsinghbisht054
- Basic functionality for cleaning dependency directories
- Support for multiple target directories
- Interactive and non-interactive modes
- Dry run capability
- Size reporting
- Protected paths
- Logging system
βοΈ If you find this tool useful, please consider giving it a star on GitHub!