strip-comments 2026.6.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strip_comments-2026.6.20/MANIFEST.in +16 -0
- strip_comments-2026.6.20/PKG-INFO +262 -0
- strip_comments-2026.6.20/README.md +171 -0
- strip_comments-2026.6.20/pyproject.toml +140 -0
- strip_comments-2026.6.20/setup.cfg +4 -0
- strip_comments-2026.6.20/strip_comments/__init__.py +0 -0
- strip_comments-2026.6.20/strip_comments/_version.py +24 -0
- strip_comments-2026.6.20/strip_comments/cli.py +258 -0
- strip_comments-2026.6.20/strip_comments/formatters.py +35 -0
- strip_comments-2026.6.20/strip_comments/languages.py +129 -0
- strip_comments-2026.6.20/strip_comments/parser.py +64 -0
- strip_comments-2026.6.20/strip_comments/stripper.py +91 -0
- strip_comments-2026.6.20/strip_comments.egg-info/PKG-INFO +262 -0
- strip_comments-2026.6.20/strip_comments.egg-info/SOURCES.txt +17 -0
- strip_comments-2026.6.20/strip_comments.egg-info/dependency_links.txt +1 -0
- strip_comments-2026.6.20/strip_comments.egg-info/entry_points.txt +2 -0
- strip_comments-2026.6.20/strip_comments.egg-info/not-zip-safe +1 -0
- strip_comments-2026.6.20/strip_comments.egg-info/requires.txt +91 -0
- strip_comments-2026.6.20/strip_comments.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Ship the importable package only. Everything else (tests, docs, CI config,
|
|
2
|
+
# project metadata files) is excluded so the sdist installs just the code.
|
|
3
|
+
graft strip_comments
|
|
4
|
+
|
|
5
|
+
prune tests
|
|
6
|
+
prune docs
|
|
7
|
+
prune .github
|
|
8
|
+
|
|
9
|
+
exclude CLAUDE.md
|
|
10
|
+
exclude README.md
|
|
11
|
+
exclude LICENSE
|
|
12
|
+
exclude Makefile
|
|
13
|
+
exclude .gitignore
|
|
14
|
+
|
|
15
|
+
global-exclude __pycache__
|
|
16
|
+
global-exclude *.py[cod]
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: strip-comments
|
|
3
|
+
Version: 2026.6.20
|
|
4
|
+
Summary: Strip comments and documentation from source files using tree-sitter
|
|
5
|
+
Author-email: Alireza Savand <alireza.savand@gmail.com>
|
|
6
|
+
Maintainer-email: Alireza Savand <alireza.savand@gmail.com>
|
|
7
|
+
License-Expression: GPL-3.0-only
|
|
8
|
+
Keywords: comments,docstrings,tree-sitter,source-code,tokens,llm,cli
|
|
9
|
+
Platform: OS Independent
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Pre-processors
|
|
19
|
+
Classifier: Topic :: Utilities
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: tree-sitter
|
|
23
|
+
Requires-Dist: tree-sitter-python
|
|
24
|
+
Provides-Extra: javascript
|
|
25
|
+
Requires-Dist: tree-sitter-javascript; extra == "javascript"
|
|
26
|
+
Provides-Extra: typescript
|
|
27
|
+
Requires-Dist: tree-sitter-typescript; extra == "typescript"
|
|
28
|
+
Provides-Extra: html
|
|
29
|
+
Requires-Dist: tree-sitter-html; extra == "html"
|
|
30
|
+
Provides-Extra: css
|
|
31
|
+
Requires-Dist: tree-sitter-css; extra == "css"
|
|
32
|
+
Provides-Extra: go
|
|
33
|
+
Requires-Dist: tree-sitter-go; extra == "go"
|
|
34
|
+
Provides-Extra: rust
|
|
35
|
+
Requires-Dist: tree-sitter-rust; extra == "rust"
|
|
36
|
+
Provides-Extra: c
|
|
37
|
+
Requires-Dist: tree-sitter-c; extra == "c"
|
|
38
|
+
Provides-Extra: cpp
|
|
39
|
+
Requires-Dist: tree-sitter-cpp; extra == "cpp"
|
|
40
|
+
Provides-Extra: java
|
|
41
|
+
Requires-Dist: tree-sitter-java; extra == "java"
|
|
42
|
+
Provides-Extra: ruby
|
|
43
|
+
Requires-Dist: tree-sitter-ruby; extra == "ruby"
|
|
44
|
+
Provides-Extra: php
|
|
45
|
+
Requires-Dist: tree-sitter-php; extra == "php"
|
|
46
|
+
Provides-Extra: bash
|
|
47
|
+
Requires-Dist: tree-sitter-bash; extra == "bash"
|
|
48
|
+
Provides-Extra: json
|
|
49
|
+
Requires-Dist: tree-sitter-json; extra == "json"
|
|
50
|
+
Provides-Extra: lua
|
|
51
|
+
Requires-Dist: tree-sitter-lua; extra == "lua"
|
|
52
|
+
Provides-Extra: swift
|
|
53
|
+
Requires-Dist: tree-sitter-swift; extra == "swift"
|
|
54
|
+
Provides-Extra: kotlin
|
|
55
|
+
Requires-Dist: tree-sitter-kotlin; extra == "kotlin"
|
|
56
|
+
Provides-Extra: toml
|
|
57
|
+
Requires-Dist: tree-sitter-toml; extra == "toml"
|
|
58
|
+
Provides-Extra: dockerfile
|
|
59
|
+
Requires-Dist: tree-sitter-dockerfile; extra == "dockerfile"
|
|
60
|
+
Provides-Extra: csharp
|
|
61
|
+
Requires-Dist: tree-sitter-c-sharp; extra == "csharp"
|
|
62
|
+
Provides-Extra: zig
|
|
63
|
+
Requires-Dist: tree-sitter-zig; extra == "zig"
|
|
64
|
+
Provides-Extra: all
|
|
65
|
+
Requires-Dist: tree-sitter-javascript; extra == "all"
|
|
66
|
+
Requires-Dist: tree-sitter-typescript; extra == "all"
|
|
67
|
+
Requires-Dist: tree-sitter-html; extra == "all"
|
|
68
|
+
Requires-Dist: tree-sitter-css; extra == "all"
|
|
69
|
+
Requires-Dist: tree-sitter-go; extra == "all"
|
|
70
|
+
Requires-Dist: tree-sitter-rust; extra == "all"
|
|
71
|
+
Requires-Dist: tree-sitter-c; extra == "all"
|
|
72
|
+
Requires-Dist: tree-sitter-cpp; extra == "all"
|
|
73
|
+
Requires-Dist: tree-sitter-java; extra == "all"
|
|
74
|
+
Requires-Dist: tree-sitter-ruby; extra == "all"
|
|
75
|
+
Requires-Dist: tree-sitter-php; extra == "all"
|
|
76
|
+
Requires-Dist: tree-sitter-bash; extra == "all"
|
|
77
|
+
Requires-Dist: tree-sitter-json; extra == "all"
|
|
78
|
+
Requires-Dist: tree-sitter-lua; extra == "all"
|
|
79
|
+
Requires-Dist: tree-sitter-swift; extra == "all"
|
|
80
|
+
Requires-Dist: tree-sitter-kotlin; extra == "all"
|
|
81
|
+
Requires-Dist: tree-sitter-toml; extra == "all"
|
|
82
|
+
Requires-Dist: tree-sitter-dockerfile; extra == "all"
|
|
83
|
+
Requires-Dist: tree-sitter-c-sharp; extra == "all"
|
|
84
|
+
Requires-Dist: tree-sitter-zig; extra == "all"
|
|
85
|
+
Provides-Extra: dev
|
|
86
|
+
Requires-Dist: ruff; extra == "dev"
|
|
87
|
+
Requires-Dist: coverage; extra == "dev"
|
|
88
|
+
Requires-Dist: mypy; extra == "dev"
|
|
89
|
+
Requires-Dist: build; extra == "dev"
|
|
90
|
+
Requires-Dist: twine; extra == "dev"
|
|
91
|
+
|
|
92
|
+
# strip-comments
|
|
93
|
+
|
|
94
|
+
Strip comments and documentation from source files using tree-sitter.
|
|
95
|
+
Blank lines are removed from the output by default, producing compact, token-efficient code.
|
|
96
|
+
Designed for AI coding agents to read code without comment noise.
|
|
97
|
+
|
|
98
|
+
## Installation
|
|
99
|
+
|
|
100
|
+
### pip
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install strip-comments
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
To support additional languages, install their tree-sitter grammar:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install tree-sitter-javascript tree-sitter-typescript
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Or install all supported grammars at once:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pip install strip-comments[all]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### uv / uvx
|
|
119
|
+
|
|
120
|
+
Run without installing:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
uvx strip-comments myfile.py
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
With all languages:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
uvx --with strip-comments[all] strip-comments myfile.py
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Or install as a tool:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
uv tool install strip-comments
|
|
136
|
+
# with all languages
|
|
137
|
+
uv tool install strip-comments[all]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Supported Languages
|
|
141
|
+
|
|
142
|
+
The following languages are supported. Only Python is required by default;
|
|
143
|
+
other grammars are optional dependencies.
|
|
144
|
+
|
|
145
|
+
| Language | Extension | Install Command |
|
|
146
|
+
|----------|-----------|-----------------|
|
|
147
|
+
| Python | `.py` | (included) |
|
|
148
|
+
| JavaScript | `.js` | `pip install tree-sitter-javascript` |
|
|
149
|
+
| TypeScript | `.ts` | `pip install tree-sitter-typescript` |
|
|
150
|
+
| TSX | `.tsx` | `pip install tree-sitter-typescript` |
|
|
151
|
+
| HTML | `.html` | `pip install tree-sitter-html` |
|
|
152
|
+
| CSS | `.css` | `pip install tree-sitter-css` |
|
|
153
|
+
| Go | `.go` | `pip install tree-sitter-go` |
|
|
154
|
+
| Rust | `.rs` | `pip install tree-sitter-rust` |
|
|
155
|
+
| C | `.c` | `pip install tree-sitter-c` |
|
|
156
|
+
| C++ | `.cpp` | `pip install tree-sitter-cpp` |
|
|
157
|
+
| Java | `.java` | `pip install tree-sitter-java` |
|
|
158
|
+
| Ruby | `.rb` | `pip install tree-sitter-ruby` |
|
|
159
|
+
| PHP | `.php` | `pip install tree-sitter-php` |
|
|
160
|
+
| Bash | `.sh` | `pip install tree-sitter-bash` |
|
|
161
|
+
| JSON | `.json` | `pip install tree-sitter-json` |
|
|
162
|
+
| Lua | `.lua` | `pip install tree-sitter-lua` |
|
|
163
|
+
| Swift | `.swift` | `pip install tree-sitter-swift` |
|
|
164
|
+
| Kotlin | `.kt` | `pip install tree-sitter-kotlin` |
|
|
165
|
+
| TOML | `.toml` | `pip install tree-sitter-toml` |
|
|
166
|
+
| Dockerfile | `.dockerfile` | `pip install tree-sitter-dockerfile` |
|
|
167
|
+
| C# | `.cs` | `pip install tree-sitter-c-sharp` |
|
|
168
|
+
| Zig | `.zig` | `pip install tree-sitter-zig` |
|
|
169
|
+
|
|
170
|
+
## Usage
|
|
171
|
+
|
|
172
|
+
Strip comments from a single file:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
strip-comments myfile.py
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Process all files in a directory:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
strip-comments src/
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Pass glob patterns directly:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
strip-comments "src/**/*.py"
|
|
188
|
+
strip-comments "tests/test_*.py"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Filter by glob pattern:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
strip-comments src/ --include "*.py" --exclude "test_*.py"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
When using recursive patterns (`**`), common noise directories are automatically excluded:
|
|
198
|
+
`.git/`, `node_modules/`, `__pycache__/`, `.venv/`, `venv/`, `.tox/`, `dist/`, `build/`,
|
|
199
|
+
`.eggs/`, `.mypy_cache/`, `.pytest_cache/`, `.ruff_cache/`, `.idea/`, `.vscode/`, and `*.egg-info/`.
|
|
200
|
+
|
|
201
|
+
To disable this and search all directories:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
strip-comments src/ --include "**/*.py" --no-default-excludes
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Pipe source through stdin (useful for editor integrations):
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
cat myfile.py | strip-comments --stdin --lang py
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Output as JSON:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
strip-comments src/ --json > output.json
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Coding Agent Integration
|
|
220
|
+
|
|
221
|
+
Works with any agent that reads an instructions file. Add the snippet below to
|
|
222
|
+
`CLAUDE.md`, `AGENTS.md`, `.cursorrules`, or your tool's equivalent:
|
|
223
|
+
|
|
224
|
+
````markdown
|
|
225
|
+
## Tool: strip-comments
|
|
226
|
+
|
|
227
|
+
When reading source files to explore or understand the codebase, use
|
|
228
|
+
`strip-comments` instead of reading the raw file. It removes comments, docstrings,
|
|
229
|
+
and blank lines, giving you the same code with fewer tokens.
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
strip-comments <file> # single file
|
|
233
|
+
strip-comments <file1> <file2> ... # multiple files (each under a "=== path ===" header)
|
|
234
|
+
strip-comments <dir> --include "**/*.py" # directory, recursive filter
|
|
235
|
+
strip-comments "src/**/*.py" # glob pattern
|
|
236
|
+
cat <file> | strip-comments --stdin --lang py # pipe via stdin
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Read the raw file instead when you are about to edit it, or when the comments or
|
|
240
|
+
docstrings themselves are relevant — stripped output has shifted line numbers and
|
|
241
|
+
omits text, so it must not be used as the basis for edits.
|
|
242
|
+
````
|
|
243
|
+
|
|
244
|
+
## Options
|
|
245
|
+
|
|
246
|
+
- `--json` — Output as JSON instead of plain text
|
|
247
|
+
- `--include PATTERN` — Include files matching glob pattern
|
|
248
|
+
- `--exclude PATTERN` — Exclude files matching glob pattern
|
|
249
|
+
- `--no-default-excludes` — Do not exclude common directories
|
|
250
|
+
- `--stdin` — Read source from stdin (requires `--lang`)
|
|
251
|
+
- `-l, --lang` — Language for stdin mode (e.g. `py`, `.py`, `python`)
|
|
252
|
+
- `--stdin-filename` — Display name for stdin output (default: `<stdin>`)
|
|
253
|
+
|
|
254
|
+
## Development
|
|
255
|
+
|
|
256
|
+
Run the test suite:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
python -m unittest discover -s tests -v
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Requires Python 3.13+.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# strip-comments
|
|
2
|
+
|
|
3
|
+
Strip comments and documentation from source files using tree-sitter.
|
|
4
|
+
Blank lines are removed from the output by default, producing compact, token-efficient code.
|
|
5
|
+
Designed for AI coding agents to read code without comment noise.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### pip
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install strip-comments
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
To support additional languages, install their tree-sitter grammar:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install tree-sitter-javascript tree-sitter-typescript
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or install all supported grammars at once:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install strip-comments[all]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### uv / uvx
|
|
28
|
+
|
|
29
|
+
Run without installing:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uvx strip-comments myfile.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
With all languages:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
uvx --with strip-comments[all] strip-comments myfile.py
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or install as a tool:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv tool install strip-comments
|
|
45
|
+
# with all languages
|
|
46
|
+
uv tool install strip-comments[all]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Supported Languages
|
|
50
|
+
|
|
51
|
+
The following languages are supported. Only Python is required by default;
|
|
52
|
+
other grammars are optional dependencies.
|
|
53
|
+
|
|
54
|
+
| Language | Extension | Install Command |
|
|
55
|
+
|----------|-----------|-----------------|
|
|
56
|
+
| Python | `.py` | (included) |
|
|
57
|
+
| JavaScript | `.js` | `pip install tree-sitter-javascript` |
|
|
58
|
+
| TypeScript | `.ts` | `pip install tree-sitter-typescript` |
|
|
59
|
+
| TSX | `.tsx` | `pip install tree-sitter-typescript` |
|
|
60
|
+
| HTML | `.html` | `pip install tree-sitter-html` |
|
|
61
|
+
| CSS | `.css` | `pip install tree-sitter-css` |
|
|
62
|
+
| Go | `.go` | `pip install tree-sitter-go` |
|
|
63
|
+
| Rust | `.rs` | `pip install tree-sitter-rust` |
|
|
64
|
+
| C | `.c` | `pip install tree-sitter-c` |
|
|
65
|
+
| C++ | `.cpp` | `pip install tree-sitter-cpp` |
|
|
66
|
+
| Java | `.java` | `pip install tree-sitter-java` |
|
|
67
|
+
| Ruby | `.rb` | `pip install tree-sitter-ruby` |
|
|
68
|
+
| PHP | `.php` | `pip install tree-sitter-php` |
|
|
69
|
+
| Bash | `.sh` | `pip install tree-sitter-bash` |
|
|
70
|
+
| JSON | `.json` | `pip install tree-sitter-json` |
|
|
71
|
+
| Lua | `.lua` | `pip install tree-sitter-lua` |
|
|
72
|
+
| Swift | `.swift` | `pip install tree-sitter-swift` |
|
|
73
|
+
| Kotlin | `.kt` | `pip install tree-sitter-kotlin` |
|
|
74
|
+
| TOML | `.toml` | `pip install tree-sitter-toml` |
|
|
75
|
+
| Dockerfile | `.dockerfile` | `pip install tree-sitter-dockerfile` |
|
|
76
|
+
| C# | `.cs` | `pip install tree-sitter-c-sharp` |
|
|
77
|
+
| Zig | `.zig` | `pip install tree-sitter-zig` |
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
Strip comments from a single file:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
strip-comments myfile.py
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Process all files in a directory:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
strip-comments src/
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Pass glob patterns directly:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
strip-comments "src/**/*.py"
|
|
97
|
+
strip-comments "tests/test_*.py"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Filter by glob pattern:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
strip-comments src/ --include "*.py" --exclude "test_*.py"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
When using recursive patterns (`**`), common noise directories are automatically excluded:
|
|
107
|
+
`.git/`, `node_modules/`, `__pycache__/`, `.venv/`, `venv/`, `.tox/`, `dist/`, `build/`,
|
|
108
|
+
`.eggs/`, `.mypy_cache/`, `.pytest_cache/`, `.ruff_cache/`, `.idea/`, `.vscode/`, and `*.egg-info/`.
|
|
109
|
+
|
|
110
|
+
To disable this and search all directories:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
strip-comments src/ --include "**/*.py" --no-default-excludes
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Pipe source through stdin (useful for editor integrations):
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
cat myfile.py | strip-comments --stdin --lang py
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Output as JSON:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
strip-comments src/ --json > output.json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Coding Agent Integration
|
|
129
|
+
|
|
130
|
+
Works with any agent that reads an instructions file. Add the snippet below to
|
|
131
|
+
`CLAUDE.md`, `AGENTS.md`, `.cursorrules`, or your tool's equivalent:
|
|
132
|
+
|
|
133
|
+
````markdown
|
|
134
|
+
## Tool: strip-comments
|
|
135
|
+
|
|
136
|
+
When reading source files to explore or understand the codebase, use
|
|
137
|
+
`strip-comments` instead of reading the raw file. It removes comments, docstrings,
|
|
138
|
+
and blank lines, giving you the same code with fewer tokens.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
strip-comments <file> # single file
|
|
142
|
+
strip-comments <file1> <file2> ... # multiple files (each under a "=== path ===" header)
|
|
143
|
+
strip-comments <dir> --include "**/*.py" # directory, recursive filter
|
|
144
|
+
strip-comments "src/**/*.py" # glob pattern
|
|
145
|
+
cat <file> | strip-comments --stdin --lang py # pipe via stdin
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Read the raw file instead when you are about to edit it, or when the comments or
|
|
149
|
+
docstrings themselves are relevant — stripped output has shifted line numbers and
|
|
150
|
+
omits text, so it must not be used as the basis for edits.
|
|
151
|
+
````
|
|
152
|
+
|
|
153
|
+
## Options
|
|
154
|
+
|
|
155
|
+
- `--json` — Output as JSON instead of plain text
|
|
156
|
+
- `--include PATTERN` — Include files matching glob pattern
|
|
157
|
+
- `--exclude PATTERN` — Exclude files matching glob pattern
|
|
158
|
+
- `--no-default-excludes` — Do not exclude common directories
|
|
159
|
+
- `--stdin` — Read source from stdin (requires `--lang`)
|
|
160
|
+
- `-l, --lang` — Language for stdin mode (e.g. `py`, `.py`, `python`)
|
|
161
|
+
- `--stdin-filename` — Display name for stdin output (default: `<stdin>`)
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
Run the test suite:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
python -m unittest discover -s tests -v
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Requires Python 3.13+.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3", "setuptools_scm[toml]>=8"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "strip-comments"
|
|
7
|
+
description = "Strip comments and documentation from source files using tree-sitter"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.13"
|
|
10
|
+
license = "GPL-3.0-only"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Alireza Savand", email = "alireza.savand@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
maintainers = [
|
|
15
|
+
{ name = "Alireza Savand", email = "alireza.savand@gmail.com" },
|
|
16
|
+
]
|
|
17
|
+
keywords = [
|
|
18
|
+
"comments",
|
|
19
|
+
"docstrings",
|
|
20
|
+
"tree-sitter",
|
|
21
|
+
"source-code",
|
|
22
|
+
"tokens",
|
|
23
|
+
"llm",
|
|
24
|
+
"cli",
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 4 - Beta",
|
|
28
|
+
"Environment :: Console",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
33
|
+
"Programming Language :: Python :: 3.13",
|
|
34
|
+
"Programming Language :: Python :: 3.14",
|
|
35
|
+
"Topic :: Software Development :: Pre-processors",
|
|
36
|
+
"Topic :: Utilities",
|
|
37
|
+
]
|
|
38
|
+
dependencies = [
|
|
39
|
+
"tree-sitter",
|
|
40
|
+
"tree-sitter-python",
|
|
41
|
+
]
|
|
42
|
+
dynamic = ["version"]
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
javascript = ["tree-sitter-javascript"]
|
|
46
|
+
typescript = ["tree-sitter-typescript"]
|
|
47
|
+
html = ["tree-sitter-html"]
|
|
48
|
+
css = ["tree-sitter-css"]
|
|
49
|
+
go = ["tree-sitter-go"]
|
|
50
|
+
rust = ["tree-sitter-rust"]
|
|
51
|
+
c = ["tree-sitter-c"]
|
|
52
|
+
cpp = ["tree-sitter-cpp"]
|
|
53
|
+
java = ["tree-sitter-java"]
|
|
54
|
+
ruby = ["tree-sitter-ruby"]
|
|
55
|
+
php = ["tree-sitter-php"]
|
|
56
|
+
bash = ["tree-sitter-bash"]
|
|
57
|
+
json = ["tree-sitter-json"]
|
|
58
|
+
lua = ["tree-sitter-lua"]
|
|
59
|
+
swift = ["tree-sitter-swift"]
|
|
60
|
+
kotlin = ["tree-sitter-kotlin"]
|
|
61
|
+
toml = ["tree-sitter-toml"]
|
|
62
|
+
dockerfile = ["tree-sitter-dockerfile"]
|
|
63
|
+
csharp = ["tree-sitter-c-sharp"]
|
|
64
|
+
zig = ["tree-sitter-zig"]
|
|
65
|
+
all = [
|
|
66
|
+
"tree-sitter-javascript",
|
|
67
|
+
"tree-sitter-typescript",
|
|
68
|
+
"tree-sitter-html",
|
|
69
|
+
"tree-sitter-css",
|
|
70
|
+
"tree-sitter-go",
|
|
71
|
+
"tree-sitter-rust",
|
|
72
|
+
"tree-sitter-c",
|
|
73
|
+
"tree-sitter-cpp",
|
|
74
|
+
"tree-sitter-java",
|
|
75
|
+
"tree-sitter-ruby",
|
|
76
|
+
"tree-sitter-php",
|
|
77
|
+
"tree-sitter-bash",
|
|
78
|
+
"tree-sitter-json",
|
|
79
|
+
"tree-sitter-lua",
|
|
80
|
+
"tree-sitter-swift",
|
|
81
|
+
"tree-sitter-kotlin",
|
|
82
|
+
"tree-sitter-toml",
|
|
83
|
+
"tree-sitter-dockerfile",
|
|
84
|
+
"tree-sitter-c-sharp",
|
|
85
|
+
"tree-sitter-zig",
|
|
86
|
+
]
|
|
87
|
+
dev = [
|
|
88
|
+
"ruff",
|
|
89
|
+
"coverage",
|
|
90
|
+
"mypy",
|
|
91
|
+
"build",
|
|
92
|
+
"twine",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[project.scripts]
|
|
96
|
+
strip-comments = "strip_comments.cli:main"
|
|
97
|
+
|
|
98
|
+
[tool.setuptools]
|
|
99
|
+
zip-safe = false
|
|
100
|
+
packages = ["strip_comments"]
|
|
101
|
+
platforms = ["OS Independent"]
|
|
102
|
+
include-package-data = false
|
|
103
|
+
# Ship code only: do not bundle the LICENSE file into the wheel/sdist.
|
|
104
|
+
license-files = []
|
|
105
|
+
|
|
106
|
+
[tool.setuptools_scm]
|
|
107
|
+
write_to = "strip_comments/_version.py"
|
|
108
|
+
|
|
109
|
+
[tool.mypy]
|
|
110
|
+
python_version = "3.14"
|
|
111
|
+
strict = true
|
|
112
|
+
ignore_missing_imports = true
|
|
113
|
+
|
|
114
|
+
[tool.ruff]
|
|
115
|
+
target-version = "py314"
|
|
116
|
+
line-length = 120
|
|
117
|
+
exclude = ["tests/fixtures", "strip_comments/_version.py"]
|
|
118
|
+
|
|
119
|
+
[tool.ruff.lint]
|
|
120
|
+
select = [
|
|
121
|
+
"E",
|
|
122
|
+
"W",
|
|
123
|
+
"F",
|
|
124
|
+
"I",
|
|
125
|
+
"N",
|
|
126
|
+
"UP",
|
|
127
|
+
"B",
|
|
128
|
+
"C4",
|
|
129
|
+
"SIM",
|
|
130
|
+
]
|
|
131
|
+
ignore = ["E501", "SIM108"]
|
|
132
|
+
|
|
133
|
+
[tool.ruff.lint.pydocstyle]
|
|
134
|
+
convention = "google"
|
|
135
|
+
|
|
136
|
+
[tool.ruff.format]
|
|
137
|
+
quote-style = "double"
|
|
138
|
+
indent-style = "space"
|
|
139
|
+
skip-magic-trailing-comma = false
|
|
140
|
+
line-ending = "auto"
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '2026.6.20'
|
|
22
|
+
__version_tuple__ = version_tuple = (2026, 6, 20)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = 'g58a9e8cdf'
|