Comment Remover CLI
A high-accuracy Python tool for removing comments from programming files while preserving important code patterns such as color codes, URLs, and preprocessor directives.
Features
- Universal Language Support: 20+ programming languages including Python, JavaScript, TypeScript, C/C++, Java, C#, Go, Rust, HTML, CSS, SQL, PHP, Ruby, and Shell scripts
- Safe Operation: Automatic backup creation before processing
- Undo Capability: Restore original files from backup
- Configurable Settings: JSON-based configuration system
- Demo Mode: Generate test files for validation
- High Performance: Efficient processing of entire directory trees
- Recursive Scanning: Processes all subdirectories automatically
- Robust Error Handling: Graceful handling of permission errors and encoding issues
Installation
From PyPI (Recommended)
pip install comment-remover-cli
From Source
git clone https://github.com/guider23/Comms.git
cd Comms
pip install .
Quick Start
# Remove comments from current directory
python -m comms.cli
# Remove comments from specific directory
python -m comms.cli /path/to/your/project
# Create demo files for testing
python -m comms.cli --demo
# Restore files from backup
python -m comms.cli --undo
# Display help information
python -m comms.cli --help
Command Line Options
python -m comms.cli [directory] [options]
Options:
-h, --help Show help message and exit
--demo Create demo files with comments for testing
--undo Restore files from most recent backup
--config FILE Use custom configuration file (default: config.json)
Supported Languages
| Language | Extensions | Line Comments | Block Comments |
|---|---|---|---|
| Python | .py | # | """ """ or ''' ''' |
| JavaScript/TypeScript | .js, .jsx, .ts, .tsx | // | /* */ |
| Java | .java | // | /* */ |
| C/C++ | .c, .cpp, .h, .hpp | // | /* */ |
| C# | .cs | // | /* */ |
| Go | .go | // | /* */ |
| Rust | .rs | // | /* */ |
| PHP | .php | // | /* */ |
| Ruby | .rb | # | =begin =end |
| Shell/Bash | .sh, .bash | # | - |
| SQL | .sql | -- | /* */ |
| HTML | .html, .htm | - | |
| CSS | .css | - | /* */ |
| SCSS/Sass | .scss, .sass | // | /* */ |
| Lua | .lua | -- | --[[ ]] |
| Swift | .swift | // | /* */ |
| Kotlin | .kt, .kts | // | /* */ |
Pattern Preservation
The tool intelligently preserves:
- Color codes:
#FF5733,#123ABC - URLs:
https://example.com,http://site.com - Shebangs:
#!/usr/bin/env python - C Preprocessor:
#include,#define,#if,#endif, etc. - Content in strings: Comments inside quoted strings remain untouched
Example Usage
Before Processing
Python file:
#!/usr/bin/env python3
# This is a comment to remove
import requests # Another comment
def get_data():
"""This docstring stays"""
url = "https://api.example.com" # URL preserved
color = "#FF5733" # Color code preserved
# This comment will be removed
return requests.get(url)
After Processing
Python file:
#!/usr/bin/env python3
import requests
def get_data():
"""This docstring stays"""
url = "https://api.example.com"
color = "#FF5733"
return requests.get(url)
Configuration
Create a config.json file to customize behavior:
{
"languages": {
"python": {
"extensions": [".py"],
"line_comment": "#",
"block_comment_start": "\"\"\"",
"block_comment_end": "\"\"\""
},
"javascript": {
"extensions": [".js", ".jsx"],
"line_comment": "//",
"block_comment_start": "/*",
"block_comment_end": "*/"
}
},
"backup_enabled": true,
"backup_directory": ".backup",
"skip_patterns": [
"node_modules/",
".git/",
"__pycache__/"
]
}
Safety Features
Automatic Backups
- All original files are backed up to
.backup/directory - Backup directory structure mirrors your project structure
- Previous backups are overwritten on each run
Undo Operation
# Restore from most recent backup
python -m comms.cli --undo
Pre-execution Warning
The tool displays:
- Number of files to be processed
- File types detected
- Clear warning about the operation
- Requires explicit confirmation
Error Handling
- Permission errors: Gracefully skipped with warnings
- Encoding issues: Uses UTF-8 with error tolerance
- Backup failures: File processing is skipped if backup fails
- Malformed files: Processing continues with error reporting
Advanced Usage
Custom Configuration
python -m comms.cli --config custom-config.json /my/project
Processing Specific File Types
Edit config.json to limit processing to specific languages or add new ones.
Integration with Build Systems
# In your build script
python -m comms.cli src/ --config production-config.json
Technical Details
String Handling
- Properly handles escaped quotes in strings
- Supports single, double, and triple-quoted strings (Python)
- Preserves multiline strings and docstrings
Comment Detection
- State-machine based parsing for accuracy
- Context-aware comment detection
- Handles nested comment structures
Performance
- Processes files sequentially for reliability
- Memory-efficient line-by-line processing for large files
- Minimal I/O operations
Requirements
- Python 3.6 or higher
- No external dependencies
- Cross-platform (Windows, macOS, Linux)
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
git clone https://github.com/guider23/Comms.git
cd Comms
pip install -e .
Running Tests
python -m pytest tests/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: Report bugs on GitHub Issues
- PyPI Package: comment-remover-cli
- Documentation: Full docs at GitHub Repository
Changelog
v1.1.0
- Professional documentation
- Improved error handling
- Enhanced pattern preservation
- Updated PyPI package
v1.0.0
- Initial release
- Support for 20+ programming languages
- Automatic backup and undo functionality
- Configurable settings
Made for developers who value clean, production-ready code.
Metadata
Release files for comment-remover-cli 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| comment_remover_cli-1.2.1.tar.gz | 17.4 kB | Without provenance | Details for comment_remover_cli-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| comment_remover_cli-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for comment_remover_cli-1.2.1-py3-none-any.whl |
Total release size: 36.8 kB
Release files / comment_remover_cli-1.2.1.tar.gz
| Download URL | comment_remover_cli-1.2.1.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dba11d6998b728175c95e35fbba933b64b68e178536c3cbb64aea4d28e57565
|
|
BLAKE2b-256 checksum How to use checksums |
e86540a9b6e1c2c7a53968c4ac35067bc8692234f5287749a93f02c13bb9e6cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.0
|
Release files / comment_remover_cli-1.2.1-py3-none-any.whl
| Download URL | comment_remover_cli-1.2.1-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b13aa02f504fb4bdb452a9eedbd3f7052c783b445012ffedae249b69a36ff36
|
|
BLAKE2b-256 checksum How to use checksums |
524c95f2e53fa1d645674652adaa9b2388be58050e315454425a1ac424a9efde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.0
|
Security for comment-remover-cli 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.