code-to-txt 0.2.0__tar.gz → 0.3.0__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.
- {code_to_txt-0.2.0 → code_to_txt-0.3.0}/PKG-INFO +93 -67
- {code_to_txt-0.2.0 → code_to_txt-0.3.0}/README.md +92 -66
- {code_to_txt-0.2.0 → code_to_txt-0.3.0}/pyproject.toml +2 -2
- code_to_txt-0.3.0/src/code_to_txt/.extensions +34 -0
- code_to_txt-0.3.0/src/code_to_txt/.ignore +20 -0
- {code_to_txt-0.2.0 → code_to_txt-0.3.0}/src/code_to_txt/__init__.py +1 -0
- code_to_txt-0.3.0/src/code_to_txt/cli.py +246 -0
- code_to_txt-0.3.0/src/code_to_txt/code_to_txt.py +329 -0
- {code_to_txt-0.2.0 → code_to_txt-0.3.0}/src/code_to_txt/config.py +13 -7
- code_to_txt-0.3.0/src/code_to_txt/utils.py +13 -0
- code_to_txt-0.2.0/src/code_to_txt/cli.py +0 -229
- code_to_txt-0.2.0/src/code_to_txt/code_to_txt.py +0 -259
- {code_to_txt-0.2.0 → code_to_txt-0.3.0}/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-to-txt
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Convert code files to a single text file for LLM consumption
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -28,15 +28,6 @@ Models (LLMs) or for easy code review and documentation.
|
|
|
28
28
|
|
|
29
29
|
## Features
|
|
30
30
|
|
|
31
|
-
✨ **New in v0.2.0:**
|
|
32
|
-
|
|
33
|
-
- 🕐 **Automatic timestamps** in output filenames
|
|
34
|
-
- 📋 **Clipboard support** - copy output directly to clipboard
|
|
35
|
-
- 🎯 **Better extension handling** - specify multiple extensions without repeating `-e` flag
|
|
36
|
-
- 🔍 **Glob pattern support** - use patterns like `*.py` or `src/**/*.js`
|
|
37
|
-
- ⚙️ **Configuration file support** - save your preferences in `.code-to-txt.yml`
|
|
38
|
-
- 🚀 **Enhanced defaults** - more file types and ignore patterns out of the box
|
|
39
|
-
|
|
40
31
|
**Core Features:**
|
|
41
32
|
|
|
42
33
|
- 📁 Convert entire directories of code into a single text file
|
|
@@ -63,9 +54,18 @@ poetry add code-to-txt
|
|
|
63
54
|
### Basic Usage
|
|
64
55
|
|
|
65
56
|
```bash
|
|
66
|
-
#
|
|
57
|
+
# Show version
|
|
58
|
+
code-to-txt --version
|
|
59
|
+
|
|
60
|
+
# Convert all code files with timestamp
|
|
67
61
|
code-to-txt -t
|
|
68
62
|
|
|
63
|
+
# Preview what would be processed
|
|
64
|
+
code-to-txt --dry-run
|
|
65
|
+
|
|
66
|
+
# Get codebase statistics
|
|
67
|
+
code-to-txt --stats
|
|
68
|
+
|
|
69
69
|
# Convert specific directory
|
|
70
70
|
code-to-txt ./my-project -o project.txt
|
|
71
71
|
|
|
@@ -88,6 +88,9 @@ code-to-txt -g "*.py" -g "*.md"
|
|
|
88
88
|
### Advanced Usage
|
|
89
89
|
|
|
90
90
|
```bash
|
|
91
|
+
# Limit file sizes (useful for LLM token limits)
|
|
92
|
+
code-to-txt --max-file-size 500
|
|
93
|
+
|
|
91
94
|
# Exclude patterns
|
|
92
95
|
code-to-txt -x "tests/*" -x "*.test.js"
|
|
93
96
|
|
|
@@ -116,7 +119,7 @@ This creates `.code-to-txt.yml` with default settings:
|
|
|
116
119
|
|
|
117
120
|
```yaml
|
|
118
121
|
# Output file name
|
|
119
|
-
output:
|
|
122
|
+
output: code-to-txt.txt
|
|
120
123
|
|
|
121
124
|
# File extensions to include (null = use defaults)
|
|
122
125
|
extensions: null
|
|
@@ -125,7 +128,12 @@ extensions: null
|
|
|
125
128
|
exclude:
|
|
126
129
|
- "tests/*"
|
|
127
130
|
- "*.test.js"
|
|
131
|
+
- "*.test.ts"
|
|
132
|
+
- "*.spec.js"
|
|
133
|
+
- "*.spec.ts"
|
|
128
134
|
- "node_modules/*"
|
|
135
|
+
- "__pycache__/*"
|
|
136
|
+
- "*.pyc"
|
|
129
137
|
|
|
130
138
|
# Glob patterns (alternative to extensions)
|
|
131
139
|
glob: [ ]
|
|
@@ -137,6 +145,7 @@ separator: "================"
|
|
|
137
145
|
clipboard: false
|
|
138
146
|
clipboard_only: false
|
|
139
147
|
timestamp: false
|
|
148
|
+
max_file_size: null
|
|
140
149
|
```
|
|
141
150
|
|
|
142
151
|
Use the config file:
|
|
@@ -155,6 +164,7 @@ code-to-txt --config .code-to-txt.yml
|
|
|
155
164
|
extensions: [ .py ]
|
|
156
165
|
exclude: [ "tests/*", "*.pyc", "__pycache__/*", "venv/*", ".venv/*" ]
|
|
157
166
|
timestamp: true
|
|
167
|
+
max_file_size: 500
|
|
158
168
|
```
|
|
159
169
|
|
|
160
170
|
**JavaScript/TypeScript Project:**
|
|
@@ -163,20 +173,18 @@ timestamp: true
|
|
|
163
173
|
extensions: [ .js, .ts, .jsx, .tsx ]
|
|
164
174
|
exclude: [ "node_modules/*", "dist/*", "build/*", "*.test.js", "*.spec.ts" ]
|
|
165
175
|
no_tree: false
|
|
176
|
+
max_file_size: 1000
|
|
166
177
|
```
|
|
167
178
|
|
|
168
|
-
**
|
|
169
|
-
|
|
170
|
-
```yaml
|
|
171
|
-
extensions: [ .c, .cpp, .h, .hpp ]
|
|
172
|
-
exclude: [ "build/*", "*.o", "*.a", "cmake-build-*" ]
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
**Using Glob Patterns:**
|
|
179
|
+
**LLM-Optimized:**
|
|
176
180
|
|
|
177
181
|
```yaml
|
|
178
|
-
|
|
179
|
-
|
|
182
|
+
extensions: [ .py, .js, .md ]
|
|
183
|
+
exclude: [ "tests/*", "*.test.*", "node_modules/*", "dist/*", "build/*" ]
|
|
184
|
+
timestamp: true
|
|
185
|
+
clipboard: true
|
|
186
|
+
max_file_size: 200
|
|
187
|
+
no_tree: false
|
|
180
188
|
```
|
|
181
189
|
|
|
182
190
|
## Command Line Options
|
|
@@ -194,12 +202,16 @@ Options:
|
|
|
194
202
|
-g, --glob TEXT Glob patterns to include (can be used multiple times)
|
|
195
203
|
--no-gitignore Don't respect .gitignore files
|
|
196
204
|
--no-tree Don't include directory tree in output
|
|
197
|
-
--separator TEXT Separator between files
|
|
205
|
+
--separator TEXT Separator between files
|
|
198
206
|
-c, --clipboard Copy output to clipboard in addition to file
|
|
199
207
|
--clipboard-only Copy to clipboard only (don't save file)
|
|
200
208
|
--config PATH Path to config file (.yml or .yaml)
|
|
201
209
|
--init-config Create default configuration file
|
|
202
210
|
-t, --timestamp Add timestamp to output filename
|
|
211
|
+
-v, --version Show version and exit
|
|
212
|
+
--dry-run Show which files would be processed
|
|
213
|
+
--stats Show detailed statistics
|
|
214
|
+
--max-file-size INT Skip files larger than N KB
|
|
203
215
|
--help Show this message and exit
|
|
204
216
|
```
|
|
205
217
|
|
|
@@ -210,15 +222,13 @@ Options:
|
|
|
210
222
|
```python
|
|
211
223
|
from code_to_txt import CodeToText
|
|
212
224
|
|
|
213
|
-
|
|
214
|
-
code_to_text = CodeToText(
|
|
225
|
+
code_to_txt = CodeToText(
|
|
215
226
|
root_path="./my-project",
|
|
216
227
|
output_file="output.txt",
|
|
217
228
|
include_extensions={".py", ".js"},
|
|
218
229
|
)
|
|
219
230
|
|
|
220
|
-
|
|
221
|
-
num_files = code_to_text.convert(add_tree=True)
|
|
231
|
+
num_files = code_to_txt.convert(add_tree=True)
|
|
222
232
|
print(f"Processed {num_files} files")
|
|
223
233
|
```
|
|
224
234
|
|
|
@@ -226,54 +236,47 @@ print(f"Processed {num_files} files")
|
|
|
226
236
|
|
|
227
237
|
```python
|
|
228
238
|
from code_to_txt import CodeToText
|
|
239
|
+
import pyperclip
|
|
229
240
|
|
|
230
|
-
|
|
231
|
-
code_to_text = CodeToText(
|
|
241
|
+
code_to_txt = CodeToText(
|
|
232
242
|
root_path="./my-project",
|
|
233
|
-
output_file=None,
|
|
243
|
+
output_file=None,
|
|
234
244
|
include_extensions={".py"},
|
|
235
245
|
)
|
|
236
246
|
|
|
237
|
-
content =
|
|
238
|
-
print(f"Generated {len(content)} characters")
|
|
239
|
-
|
|
240
|
-
# Copy to clipboard using pyperclip
|
|
241
|
-
import pyperclip
|
|
242
|
-
|
|
247
|
+
content = code_to_txt.generate_content(add_tree=True)
|
|
243
248
|
pyperclip.copy(content)
|
|
244
249
|
```
|
|
245
250
|
|
|
246
|
-
###
|
|
251
|
+
### Get Statistics
|
|
247
252
|
|
|
248
253
|
```python
|
|
249
254
|
from code_to_txt import CodeToText
|
|
250
255
|
|
|
251
|
-
|
|
256
|
+
code_to_txt = CodeToText(
|
|
252
257
|
root_path="./my-project",
|
|
253
|
-
output_file=
|
|
254
|
-
|
|
258
|
+
output_file=None,
|
|
259
|
+
max_file_size_kb=500,
|
|
255
260
|
)
|
|
256
261
|
|
|
257
|
-
|
|
262
|
+
stats = code_to_txt.calculate_statistics()
|
|
263
|
+
print(f"Total files: {stats['total_files']}")
|
|
264
|
+
print(f"Total size: {stats['total_size_bytes'] / 1024 / 1024:.2f} MB")
|
|
265
|
+
print(f"Total lines: {stats['total_lines']:,}")
|
|
258
266
|
```
|
|
259
267
|
|
|
260
|
-
###
|
|
268
|
+
### Using Glob Patterns
|
|
261
269
|
|
|
262
270
|
```python
|
|
263
271
|
from code_to_txt import CodeToText
|
|
264
272
|
|
|
265
|
-
|
|
273
|
+
code_to_txt = CodeToText(
|
|
266
274
|
root_path="./my-project",
|
|
267
|
-
output_file="
|
|
268
|
-
|
|
269
|
-
exclude_patterns=["tests/*", "*.test.js", "node_modules/*"],
|
|
270
|
-
gitignore=True, # Respect .gitignore (default)
|
|
275
|
+
output_file="output.txt",
|
|
276
|
+
glob_patterns=["*.py", "src/**/*.js", "**/*.md"],
|
|
271
277
|
)
|
|
272
278
|
|
|
273
|
-
num_files =
|
|
274
|
-
add_tree=True,
|
|
275
|
-
separator="=" * 100,
|
|
276
|
-
)
|
|
279
|
+
num_files = code_to_txt.convert()
|
|
277
280
|
```
|
|
278
281
|
|
|
279
282
|
## Default File Extensions
|
|
@@ -301,7 +304,7 @@ CodeToTxt automatically ignores common build artifacts and dependencies:
|
|
|
301
304
|
- `.pytest_cache`, `.mypy_cache`, `.ruff_cache`
|
|
302
305
|
- `*.so`, `*.dylib`, `*.dll`
|
|
303
306
|
|
|
304
|
-
Plus any patterns in your `.gitignore` file.
|
|
307
|
+
Plus any patterns in your `.gitignore` file (including parent directories).
|
|
305
308
|
|
|
306
309
|
## Output Format
|
|
307
310
|
|
|
@@ -353,34 +356,43 @@ if __name__ == "__main__":
|
|
|
353
356
|
|
|
354
357
|
## Tips & Tricks
|
|
355
358
|
|
|
356
|
-
### For
|
|
359
|
+
### For LLM Consumption
|
|
357
360
|
|
|
358
361
|
```bash
|
|
359
|
-
#
|
|
360
|
-
code-to-txt
|
|
362
|
+
# Step 1: Check what you're working with
|
|
363
|
+
code-to-txt --stats
|
|
361
364
|
|
|
362
|
-
#
|
|
363
|
-
code-to-txt -
|
|
365
|
+
# Step 2: Preview files
|
|
366
|
+
code-to-txt --dry-run --max-file-size 200
|
|
367
|
+
|
|
368
|
+
# Step 3: Copy to clipboard with size limit
|
|
369
|
+
code-to-txt --clipboard-only --max-file-size 200 -e ".py .md"
|
|
370
|
+
|
|
371
|
+
# See token estimate:
|
|
372
|
+
# Estimated tokens: ~95,000
|
|
364
373
|
```
|
|
365
374
|
|
|
366
|
-
### For
|
|
375
|
+
### For Large Projects
|
|
367
376
|
|
|
368
377
|
```bash
|
|
369
|
-
#
|
|
370
|
-
code-to-txt
|
|
378
|
+
# Use specific extensions to reduce size
|
|
379
|
+
code-to-txt -e ".py" -t --max-file-size 500
|
|
371
380
|
|
|
372
|
-
#
|
|
373
|
-
code-to-txt -
|
|
381
|
+
# Exclude heavy directories
|
|
382
|
+
code-to-txt -x "node_modules/*" -x "venv/*" -x "dist/*"
|
|
383
|
+
|
|
384
|
+
# Get statistics first
|
|
385
|
+
code-to-txt --stats --max-file-size 300
|
|
374
386
|
```
|
|
375
387
|
|
|
376
|
-
###
|
|
388
|
+
### Debug Ignore Patterns
|
|
377
389
|
|
|
378
390
|
```bash
|
|
379
|
-
#
|
|
380
|
-
code-to-txt -
|
|
391
|
+
# See which files are being skipped and why
|
|
392
|
+
code-to-txt --dry-run
|
|
381
393
|
|
|
382
|
-
#
|
|
383
|
-
code-to-txt -
|
|
394
|
+
# Compare with and without gitignore
|
|
395
|
+
code-to-txt --dry-run --no-gitignore
|
|
384
396
|
```
|
|
385
397
|
|
|
386
398
|
## Requirements
|
|
@@ -416,6 +428,20 @@ MIT License - see LICENSE file for details.
|
|
|
416
428
|
|
|
417
429
|
## Changelog
|
|
418
430
|
|
|
431
|
+
### v0.3.0
|
|
432
|
+
|
|
433
|
+
- 🔧 Refactored codebase for better maintainability
|
|
434
|
+
- 📁 Externalized default extensions and ignore patterns to separate files
|
|
435
|
+
- 🐛 Fixed critical gitignore bug (now checks parent directories)
|
|
436
|
+
- 🔍 Improved cross-platform path handling
|
|
437
|
+
- 📊 Added `--stats` flag for detailed codebase statistics
|
|
438
|
+
- 🎯 Added `--dry-run` mode to preview without processing
|
|
439
|
+
- 📏 Added `--max-file-size` to skip large files
|
|
440
|
+
- 🔢 Added token estimation for LLM consumption
|
|
441
|
+
- 📝 Added skip tracking to see which files were excluded
|
|
442
|
+
- 🚀 Improved method naming and code structure
|
|
443
|
+
- ✅ Enhanced test coverage
|
|
444
|
+
|
|
419
445
|
### v0.2.0
|
|
420
446
|
|
|
421
447
|
- ✨ Added automatic timestamp generation for output files
|
|
@@ -5,15 +5,6 @@ Models (LLMs) or for easy code review and documentation.
|
|
|
5
5
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
|
-
✨ **New in v0.2.0:**
|
|
9
|
-
|
|
10
|
-
- 🕐 **Automatic timestamps** in output filenames
|
|
11
|
-
- 📋 **Clipboard support** - copy output directly to clipboard
|
|
12
|
-
- 🎯 **Better extension handling** - specify multiple extensions without repeating `-e` flag
|
|
13
|
-
- 🔍 **Glob pattern support** - use patterns like `*.py` or `src/**/*.js`
|
|
14
|
-
- ⚙️ **Configuration file support** - save your preferences in `.code-to-txt.yml`
|
|
15
|
-
- 🚀 **Enhanced defaults** - more file types and ignore patterns out of the box
|
|
16
|
-
|
|
17
8
|
**Core Features:**
|
|
18
9
|
|
|
19
10
|
- 📁 Convert entire directories of code into a single text file
|
|
@@ -40,9 +31,18 @@ poetry add code-to-txt
|
|
|
40
31
|
### Basic Usage
|
|
41
32
|
|
|
42
33
|
```bash
|
|
43
|
-
#
|
|
34
|
+
# Show version
|
|
35
|
+
code-to-txt --version
|
|
36
|
+
|
|
37
|
+
# Convert all code files with timestamp
|
|
44
38
|
code-to-txt -t
|
|
45
39
|
|
|
40
|
+
# Preview what would be processed
|
|
41
|
+
code-to-txt --dry-run
|
|
42
|
+
|
|
43
|
+
# Get codebase statistics
|
|
44
|
+
code-to-txt --stats
|
|
45
|
+
|
|
46
46
|
# Convert specific directory
|
|
47
47
|
code-to-txt ./my-project -o project.txt
|
|
48
48
|
|
|
@@ -65,6 +65,9 @@ code-to-txt -g "*.py" -g "*.md"
|
|
|
65
65
|
### Advanced Usage
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
+
# Limit file sizes (useful for LLM token limits)
|
|
69
|
+
code-to-txt --max-file-size 500
|
|
70
|
+
|
|
68
71
|
# Exclude patterns
|
|
69
72
|
code-to-txt -x "tests/*" -x "*.test.js"
|
|
70
73
|
|
|
@@ -93,7 +96,7 @@ This creates `.code-to-txt.yml` with default settings:
|
|
|
93
96
|
|
|
94
97
|
```yaml
|
|
95
98
|
# Output file name
|
|
96
|
-
output:
|
|
99
|
+
output: code-to-txt.txt
|
|
97
100
|
|
|
98
101
|
# File extensions to include (null = use defaults)
|
|
99
102
|
extensions: null
|
|
@@ -102,7 +105,12 @@ extensions: null
|
|
|
102
105
|
exclude:
|
|
103
106
|
- "tests/*"
|
|
104
107
|
- "*.test.js"
|
|
108
|
+
- "*.test.ts"
|
|
109
|
+
- "*.spec.js"
|
|
110
|
+
- "*.spec.ts"
|
|
105
111
|
- "node_modules/*"
|
|
112
|
+
- "__pycache__/*"
|
|
113
|
+
- "*.pyc"
|
|
106
114
|
|
|
107
115
|
# Glob patterns (alternative to extensions)
|
|
108
116
|
glob: [ ]
|
|
@@ -114,6 +122,7 @@ separator: "================"
|
|
|
114
122
|
clipboard: false
|
|
115
123
|
clipboard_only: false
|
|
116
124
|
timestamp: false
|
|
125
|
+
max_file_size: null
|
|
117
126
|
```
|
|
118
127
|
|
|
119
128
|
Use the config file:
|
|
@@ -132,6 +141,7 @@ code-to-txt --config .code-to-txt.yml
|
|
|
132
141
|
extensions: [ .py ]
|
|
133
142
|
exclude: [ "tests/*", "*.pyc", "__pycache__/*", "venv/*", ".venv/*" ]
|
|
134
143
|
timestamp: true
|
|
144
|
+
max_file_size: 500
|
|
135
145
|
```
|
|
136
146
|
|
|
137
147
|
**JavaScript/TypeScript Project:**
|
|
@@ -140,20 +150,18 @@ timestamp: true
|
|
|
140
150
|
extensions: [ .js, .ts, .jsx, .tsx ]
|
|
141
151
|
exclude: [ "node_modules/*", "dist/*", "build/*", "*.test.js", "*.spec.ts" ]
|
|
142
152
|
no_tree: false
|
|
153
|
+
max_file_size: 1000
|
|
143
154
|
```
|
|
144
155
|
|
|
145
|
-
**
|
|
146
|
-
|
|
147
|
-
```yaml
|
|
148
|
-
extensions: [ .c, .cpp, .h, .hpp ]
|
|
149
|
-
exclude: [ "build/*", "*.o", "*.a", "cmake-build-*" ]
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
**Using Glob Patterns:**
|
|
156
|
+
**LLM-Optimized:**
|
|
153
157
|
|
|
154
158
|
```yaml
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
extensions: [ .py, .js, .md ]
|
|
160
|
+
exclude: [ "tests/*", "*.test.*", "node_modules/*", "dist/*", "build/*" ]
|
|
161
|
+
timestamp: true
|
|
162
|
+
clipboard: true
|
|
163
|
+
max_file_size: 200
|
|
164
|
+
no_tree: false
|
|
157
165
|
```
|
|
158
166
|
|
|
159
167
|
## Command Line Options
|
|
@@ -171,12 +179,16 @@ Options:
|
|
|
171
179
|
-g, --glob TEXT Glob patterns to include (can be used multiple times)
|
|
172
180
|
--no-gitignore Don't respect .gitignore files
|
|
173
181
|
--no-tree Don't include directory tree in output
|
|
174
|
-
--separator TEXT Separator between files
|
|
182
|
+
--separator TEXT Separator between files
|
|
175
183
|
-c, --clipboard Copy output to clipboard in addition to file
|
|
176
184
|
--clipboard-only Copy to clipboard only (don't save file)
|
|
177
185
|
--config PATH Path to config file (.yml or .yaml)
|
|
178
186
|
--init-config Create default configuration file
|
|
179
187
|
-t, --timestamp Add timestamp to output filename
|
|
188
|
+
-v, --version Show version and exit
|
|
189
|
+
--dry-run Show which files would be processed
|
|
190
|
+
--stats Show detailed statistics
|
|
191
|
+
--max-file-size INT Skip files larger than N KB
|
|
180
192
|
--help Show this message and exit
|
|
181
193
|
```
|
|
182
194
|
|
|
@@ -187,15 +199,13 @@ Options:
|
|
|
187
199
|
```python
|
|
188
200
|
from code_to_txt import CodeToText
|
|
189
201
|
|
|
190
|
-
|
|
191
|
-
code_to_text = CodeToText(
|
|
202
|
+
code_to_txt = CodeToText(
|
|
192
203
|
root_path="./my-project",
|
|
193
204
|
output_file="output.txt",
|
|
194
205
|
include_extensions={".py", ".js"},
|
|
195
206
|
)
|
|
196
207
|
|
|
197
|
-
|
|
198
|
-
num_files = code_to_text.convert(add_tree=True)
|
|
208
|
+
num_files = code_to_txt.convert(add_tree=True)
|
|
199
209
|
print(f"Processed {num_files} files")
|
|
200
210
|
```
|
|
201
211
|
|
|
@@ -203,54 +213,47 @@ print(f"Processed {num_files} files")
|
|
|
203
213
|
|
|
204
214
|
```python
|
|
205
215
|
from code_to_txt import CodeToText
|
|
216
|
+
import pyperclip
|
|
206
217
|
|
|
207
|
-
|
|
208
|
-
code_to_text = CodeToText(
|
|
218
|
+
code_to_txt = CodeToText(
|
|
209
219
|
root_path="./my-project",
|
|
210
|
-
output_file=None,
|
|
220
|
+
output_file=None,
|
|
211
221
|
include_extensions={".py"},
|
|
212
222
|
)
|
|
213
223
|
|
|
214
|
-
content =
|
|
215
|
-
print(f"Generated {len(content)} characters")
|
|
216
|
-
|
|
217
|
-
# Copy to clipboard using pyperclip
|
|
218
|
-
import pyperclip
|
|
219
|
-
|
|
224
|
+
content = code_to_txt.generate_content(add_tree=True)
|
|
220
225
|
pyperclip.copy(content)
|
|
221
226
|
```
|
|
222
227
|
|
|
223
|
-
###
|
|
228
|
+
### Get Statistics
|
|
224
229
|
|
|
225
230
|
```python
|
|
226
231
|
from code_to_txt import CodeToText
|
|
227
232
|
|
|
228
|
-
|
|
233
|
+
code_to_txt = CodeToText(
|
|
229
234
|
root_path="./my-project",
|
|
230
|
-
output_file=
|
|
231
|
-
|
|
235
|
+
output_file=None,
|
|
236
|
+
max_file_size_kb=500,
|
|
232
237
|
)
|
|
233
238
|
|
|
234
|
-
|
|
239
|
+
stats = code_to_txt.calculate_statistics()
|
|
240
|
+
print(f"Total files: {stats['total_files']}")
|
|
241
|
+
print(f"Total size: {stats['total_size_bytes'] / 1024 / 1024:.2f} MB")
|
|
242
|
+
print(f"Total lines: {stats['total_lines']:,}")
|
|
235
243
|
```
|
|
236
244
|
|
|
237
|
-
###
|
|
245
|
+
### Using Glob Patterns
|
|
238
246
|
|
|
239
247
|
```python
|
|
240
248
|
from code_to_txt import CodeToText
|
|
241
249
|
|
|
242
|
-
|
|
250
|
+
code_to_txt = CodeToText(
|
|
243
251
|
root_path="./my-project",
|
|
244
|
-
output_file="
|
|
245
|
-
|
|
246
|
-
exclude_patterns=["tests/*", "*.test.js", "node_modules/*"],
|
|
247
|
-
gitignore=True, # Respect .gitignore (default)
|
|
252
|
+
output_file="output.txt",
|
|
253
|
+
glob_patterns=["*.py", "src/**/*.js", "**/*.md"],
|
|
248
254
|
)
|
|
249
255
|
|
|
250
|
-
num_files =
|
|
251
|
-
add_tree=True,
|
|
252
|
-
separator="=" * 100,
|
|
253
|
-
)
|
|
256
|
+
num_files = code_to_txt.convert()
|
|
254
257
|
```
|
|
255
258
|
|
|
256
259
|
## Default File Extensions
|
|
@@ -278,7 +281,7 @@ CodeToTxt automatically ignores common build artifacts and dependencies:
|
|
|
278
281
|
- `.pytest_cache`, `.mypy_cache`, `.ruff_cache`
|
|
279
282
|
- `*.so`, `*.dylib`, `*.dll`
|
|
280
283
|
|
|
281
|
-
Plus any patterns in your `.gitignore` file.
|
|
284
|
+
Plus any patterns in your `.gitignore` file (including parent directories).
|
|
282
285
|
|
|
283
286
|
## Output Format
|
|
284
287
|
|
|
@@ -330,34 +333,43 @@ if __name__ == "__main__":
|
|
|
330
333
|
|
|
331
334
|
## Tips & Tricks
|
|
332
335
|
|
|
333
|
-
### For
|
|
336
|
+
### For LLM Consumption
|
|
334
337
|
|
|
335
338
|
```bash
|
|
336
|
-
#
|
|
337
|
-
code-to-txt
|
|
339
|
+
# Step 1: Check what you're working with
|
|
340
|
+
code-to-txt --stats
|
|
338
341
|
|
|
339
|
-
#
|
|
340
|
-
code-to-txt -
|
|
342
|
+
# Step 2: Preview files
|
|
343
|
+
code-to-txt --dry-run --max-file-size 200
|
|
344
|
+
|
|
345
|
+
# Step 3: Copy to clipboard with size limit
|
|
346
|
+
code-to-txt --clipboard-only --max-file-size 200 -e ".py .md"
|
|
347
|
+
|
|
348
|
+
# See token estimate:
|
|
349
|
+
# Estimated tokens: ~95,000
|
|
341
350
|
```
|
|
342
351
|
|
|
343
|
-
### For
|
|
352
|
+
### For Large Projects
|
|
344
353
|
|
|
345
354
|
```bash
|
|
346
|
-
#
|
|
347
|
-
code-to-txt
|
|
355
|
+
# Use specific extensions to reduce size
|
|
356
|
+
code-to-txt -e ".py" -t --max-file-size 500
|
|
348
357
|
|
|
349
|
-
#
|
|
350
|
-
code-to-txt -
|
|
358
|
+
# Exclude heavy directories
|
|
359
|
+
code-to-txt -x "node_modules/*" -x "venv/*" -x "dist/*"
|
|
360
|
+
|
|
361
|
+
# Get statistics first
|
|
362
|
+
code-to-txt --stats --max-file-size 300
|
|
351
363
|
```
|
|
352
364
|
|
|
353
|
-
###
|
|
365
|
+
### Debug Ignore Patterns
|
|
354
366
|
|
|
355
367
|
```bash
|
|
356
|
-
#
|
|
357
|
-
code-to-txt -
|
|
368
|
+
# See which files are being skipped and why
|
|
369
|
+
code-to-txt --dry-run
|
|
358
370
|
|
|
359
|
-
#
|
|
360
|
-
code-to-txt -
|
|
371
|
+
# Compare with and without gitignore
|
|
372
|
+
code-to-txt --dry-run --no-gitignore
|
|
361
373
|
```
|
|
362
374
|
|
|
363
375
|
## Requirements
|
|
@@ -393,6 +405,20 @@ MIT License - see LICENSE file for details.
|
|
|
393
405
|
|
|
394
406
|
## Changelog
|
|
395
407
|
|
|
408
|
+
### v0.3.0
|
|
409
|
+
|
|
410
|
+
- 🔧 Refactored codebase for better maintainability
|
|
411
|
+
- 📁 Externalized default extensions and ignore patterns to separate files
|
|
412
|
+
- 🐛 Fixed critical gitignore bug (now checks parent directories)
|
|
413
|
+
- 🔍 Improved cross-platform path handling
|
|
414
|
+
- 📊 Added `--stats` flag for detailed codebase statistics
|
|
415
|
+
- 🎯 Added `--dry-run` mode to preview without processing
|
|
416
|
+
- 📏 Added `--max-file-size` to skip large files
|
|
417
|
+
- 🔢 Added token estimation for LLM consumption
|
|
418
|
+
- 📝 Added skip tracking to see which files were excluded
|
|
419
|
+
- 🚀 Improved method naming and code structure
|
|
420
|
+
- ✅ Enhanced test coverage
|
|
421
|
+
|
|
396
422
|
### v0.2.0
|
|
397
423
|
|
|
398
424
|
- ✨ Added automatic timestamp generation for output files
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "code-to-txt"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Convert code files to a single text file for LLM consumption"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Andrii Sonsiadlo", email = "andrii.sonsiadlo@gmail.com" }
|
|
@@ -45,4 +45,4 @@ python_version = "3.10"
|
|
|
45
45
|
warn_return_any = true
|
|
46
46
|
warn_unused_configs = true
|
|
47
47
|
disallow_untyped_defs = true
|
|
48
|
-
ignore_missing_imports = true
|
|
48
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.py
|
|
2
|
+
.js
|
|
3
|
+
.ts
|
|
4
|
+
.jsx
|
|
5
|
+
.tsx
|
|
6
|
+
.java
|
|
7
|
+
.c
|
|
8
|
+
.cpp
|
|
9
|
+
.h
|
|
10
|
+
.hpp
|
|
11
|
+
.cs
|
|
12
|
+
.go
|
|
13
|
+
.rs
|
|
14
|
+
.rb
|
|
15
|
+
.php
|
|
16
|
+
.swift
|
|
17
|
+
.kt
|
|
18
|
+
.scala
|
|
19
|
+
.r
|
|
20
|
+
.sql
|
|
21
|
+
.sh
|
|
22
|
+
.bash
|
|
23
|
+
.zsh
|
|
24
|
+
.yaml
|
|
25
|
+
.yml
|
|
26
|
+
.json
|
|
27
|
+
.toml
|
|
28
|
+
.xml
|
|
29
|
+
.html
|
|
30
|
+
.css
|
|
31
|
+
.scss
|
|
32
|
+
.md
|
|
33
|
+
.txt
|
|
34
|
+
.rst
|