code-to-txt 0.1.0__tar.gz → 0.2.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/LICENSE +21 -0
- code_to_txt-0.2.0/PKG-INFO +440 -0
- code_to_txt-0.2.0/README.md +416 -0
- code_to_txt-0.2.0/pyproject.toml +48 -0
- code_to_txt-0.2.0/src/code_to_txt/cli.py +229 -0
- {code_to_txt-0.1.0 → code_to_txt-0.2.0}/src/code_to_txt/code_to_txt.py +121 -42
- code_to_txt-0.2.0/src/code_to_txt/config.py +161 -0
- code_to_txt-0.1.0/PKG-INFO +0 -24
- code_to_txt-0.1.0/README.md +0 -3
- code_to_txt-0.1.0/pyproject.toml +0 -30
- code_to_txt-0.1.0/src/code_to_txt/cli.py +0 -96
- {code_to_txt-0.1.0 → code_to_txt-0.2.0}/src/code_to_txt/__init__.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Andrii Sonsiadlo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code-to-txt
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Convert code files to a single text file for LLM consumption
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Andrii Sonsiadlo
|
|
8
|
+
Author-email: andrii.sonsiadlo@gmail.com
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Requires-Dist: click (>=8.3.1,<9.0.0)
|
|
18
|
+
Requires-Dist: gitpython (>=3.1.46,<4.0.0)
|
|
19
|
+
Requires-Dist: pathspec (>=1.0.4,<2.0.0)
|
|
20
|
+
Requires-Dist: pyperclip (>=1.8.2,<2.0.0)
|
|
21
|
+
Requires-Dist: pyyaml (>=6.0.0,<7.0.0)
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# CodeToTxt
|
|
25
|
+
|
|
26
|
+
A powerful Python package to convert code files into a single text file, perfect for feeding into Large Language
|
|
27
|
+
Models (LLMs) or for easy code review and documentation.
|
|
28
|
+
|
|
29
|
+
## Features
|
|
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
|
+
**Core Features:**
|
|
41
|
+
|
|
42
|
+
- 📁 Convert entire directories of code into a single text file
|
|
43
|
+
- 🌳 Optional directory tree visualization
|
|
44
|
+
- 🚫 Respects `.gitignore` patterns automatically
|
|
45
|
+
- 🎨 Customizable file separators and output format
|
|
46
|
+
- 🔧 Flexible file filtering by extension or glob patterns
|
|
47
|
+
- 📦 Easy to use CLI and Python API
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install code-to-txt
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or with Poetry:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
poetry add code-to-txt
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
### Basic Usage
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Convert all code files in current directory with timestamp
|
|
67
|
+
code-to-txt -t
|
|
68
|
+
|
|
69
|
+
# Convert specific directory
|
|
70
|
+
code-to-txt ./my-project -o project.txt
|
|
71
|
+
|
|
72
|
+
# Copy to clipboard instead of saving
|
|
73
|
+
code-to-txt --clipboard-only
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Specify File Types
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Multiple extensions (space or comma separated)
|
|
80
|
+
code-to-txt -e ".py .js .ts"
|
|
81
|
+
code-to-txt -e ".py,.js,.ts"
|
|
82
|
+
|
|
83
|
+
# Using glob patterns
|
|
84
|
+
code-to-txt -g "*.py" -g "src/**/*.js"
|
|
85
|
+
code-to-txt -g "*.py" -g "*.md"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Advanced Usage
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Exclude patterns
|
|
92
|
+
code-to-txt -x "tests/*" -x "*.test.js"
|
|
93
|
+
|
|
94
|
+
# Don't use .gitignore
|
|
95
|
+
code-to-txt --no-gitignore
|
|
96
|
+
|
|
97
|
+
# Don't show directory tree
|
|
98
|
+
code-to-txt --no-tree
|
|
99
|
+
|
|
100
|
+
# Custom separator
|
|
101
|
+
code-to-txt --separator "---"
|
|
102
|
+
|
|
103
|
+
# Combine options
|
|
104
|
+
code-to-txt -t -c -e ".py .js" -x "tests/*"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Configuration File
|
|
108
|
+
|
|
109
|
+
Create a default configuration file:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
code-to-txt --init-config
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This creates `.code-to-txt.yml` with default settings:
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
# Output file name
|
|
119
|
+
output: codetotxt.txt
|
|
120
|
+
|
|
121
|
+
# File extensions to include (null = use defaults)
|
|
122
|
+
extensions: null
|
|
123
|
+
|
|
124
|
+
# Patterns to exclude
|
|
125
|
+
exclude:
|
|
126
|
+
- "tests/*"
|
|
127
|
+
- "*.test.js"
|
|
128
|
+
- "node_modules/*"
|
|
129
|
+
|
|
130
|
+
# Glob patterns (alternative to extensions)
|
|
131
|
+
glob: [ ]
|
|
132
|
+
|
|
133
|
+
# Options
|
|
134
|
+
no_gitignore: false
|
|
135
|
+
no_tree: false
|
|
136
|
+
separator: "================"
|
|
137
|
+
clipboard: false
|
|
138
|
+
clipboard_only: false
|
|
139
|
+
timestamp: false
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Use the config file:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
code-to-txt --config .code-to-txt.yml
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Note:** CLI arguments override config file settings.
|
|
149
|
+
|
|
150
|
+
### Example Configurations
|
|
151
|
+
|
|
152
|
+
**Python Project:**
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
extensions: [ .py ]
|
|
156
|
+
exclude: [ "tests/*", "*.pyc", "__pycache__/*", "venv/*", ".venv/*" ]
|
|
157
|
+
timestamp: true
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**JavaScript/TypeScript Project:**
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
extensions: [ .js, .ts, .jsx, .tsx ]
|
|
164
|
+
exclude: [ "node_modules/*", "dist/*", "build/*", "*.test.js", "*.spec.ts" ]
|
|
165
|
+
no_tree: false
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**C/C++ Project:**
|
|
169
|
+
|
|
170
|
+
```yaml
|
|
171
|
+
extensions: [ .c, .cpp, .h, .hpp ]
|
|
172
|
+
exclude: [ "build/*", "*.o", "*.a", "cmake-build-*" ]
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Using Glob Patterns:**
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
glob: [ "src/**/*.py", "lib/**/*.py", "*.md" ]
|
|
179
|
+
extensions: null # Ignore extensions when using glob
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Command Line Options
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
Usage: code-to-txt [OPTIONS] [PATH]
|
|
186
|
+
|
|
187
|
+
Arguments:
|
|
188
|
+
PATH Directory to scan (default: current directory)
|
|
189
|
+
|
|
190
|
+
Options:
|
|
191
|
+
-o, --output PATH Output file path (default: codetotxt_YYYYMMDD_HHMMSS.txt)
|
|
192
|
+
-e, --extensions TEXT File extensions to include (space or comma separated)
|
|
193
|
+
-x, --exclude TEXT Patterns to exclude (can be used multiple times)
|
|
194
|
+
-g, --glob TEXT Glob patterns to include (can be used multiple times)
|
|
195
|
+
--no-gitignore Don't respect .gitignore files
|
|
196
|
+
--no-tree Don't include directory tree in output
|
|
197
|
+
--separator TEXT Separator between files (default: ====...)
|
|
198
|
+
-c, --clipboard Copy output to clipboard in addition to file
|
|
199
|
+
--clipboard-only Copy to clipboard only (don't save file)
|
|
200
|
+
--config PATH Path to config file (.yml or .yaml)
|
|
201
|
+
--init-config Create default configuration file
|
|
202
|
+
-t, --timestamp Add timestamp to output filename
|
|
203
|
+
--help Show this message and exit
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Python API
|
|
207
|
+
|
|
208
|
+
### Basic Usage
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from code_to_txt import CodeToText
|
|
212
|
+
|
|
213
|
+
# Create instance
|
|
214
|
+
code_to_text = CodeToText(
|
|
215
|
+
root_path="./my-project",
|
|
216
|
+
output_file="output.txt",
|
|
217
|
+
include_extensions={".py", ".js"},
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# Convert to file
|
|
221
|
+
num_files = code_to_text.convert(add_tree=True)
|
|
222
|
+
print(f"Processed {num_files} files")
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Generate Content for Clipboard
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from code_to_txt import CodeToText
|
|
229
|
+
|
|
230
|
+
# Generate content without writing to file
|
|
231
|
+
code_to_text = CodeToText(
|
|
232
|
+
root_path="./my-project",
|
|
233
|
+
output_file=None, # No file needed
|
|
234
|
+
include_extensions={".py"},
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
content = code_to_text.generate_content(add_tree=True)
|
|
238
|
+
print(f"Generated {len(content)} characters")
|
|
239
|
+
|
|
240
|
+
# Copy to clipboard using pyperclip
|
|
241
|
+
import pyperclip
|
|
242
|
+
|
|
243
|
+
pyperclip.copy(content)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Using Glob Patterns
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
from code_to_txt import CodeToText
|
|
250
|
+
|
|
251
|
+
code_to_text = CodeToText(
|
|
252
|
+
root_path="./my-project",
|
|
253
|
+
output_file="output.txt",
|
|
254
|
+
glob_patterns=["*.py", "src/**/*.js", "**/*.md"],
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
num_files = code_to_text.convert()
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Advanced Configuration
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from code_to_txt import CodeToText
|
|
264
|
+
|
|
265
|
+
code_to_text = CodeToText(
|
|
266
|
+
root_path="./my-project",
|
|
267
|
+
output_file="detailed_output.txt",
|
|
268
|
+
include_extensions={".py", ".js", ".ts"},
|
|
269
|
+
exclude_patterns=["tests/*", "*.test.js", "node_modules/*"],
|
|
270
|
+
gitignore=True, # Respect .gitignore (default)
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
num_files = code_to_text.convert(
|
|
274
|
+
add_tree=True,
|
|
275
|
+
separator="=" * 100,
|
|
276
|
+
)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Default File Extensions
|
|
280
|
+
|
|
281
|
+
When no extensions are specified, CodeToTxt includes these file types by default:
|
|
282
|
+
|
|
283
|
+
- **Python:** `.py`
|
|
284
|
+
- **JavaScript/TypeScript:** `.js`, `.ts`, `.jsx`, `.tsx`
|
|
285
|
+
- **Systems:** `.c`, `.cpp`, `.h`, `.hpp`, `.java`, `.cs`, `.go`, `.rs`
|
|
286
|
+
- **Web:** `.html`, `.css`, `.scss`
|
|
287
|
+
- **Config:** `.yaml`, `.yml`, `.json`, `.toml`, `.xml`
|
|
288
|
+
- **Documentation:** `.md`, `.txt`, `.rst`
|
|
289
|
+
- **Scripts:** `.sh`, `.bash`, `.zsh`
|
|
290
|
+
- **Other:** `.rb`, `.php`, `.swift`, `.kt`, `.scala`, `.r`, `.sql`
|
|
291
|
+
|
|
292
|
+
## Default Ignore Patterns
|
|
293
|
+
|
|
294
|
+
CodeToTxt automatically ignores common build artifacts and dependencies:
|
|
295
|
+
|
|
296
|
+
- `__pycache__`, `*.pyc`, `*.pyo`, `*.pyd`
|
|
297
|
+
- `.git`, `.svn`, `.hg`
|
|
298
|
+
- `node_modules`
|
|
299
|
+
- `.venv`, `venv`, `.env`
|
|
300
|
+
- `*.egg-info`, `dist`, `build`
|
|
301
|
+
- `.pytest_cache`, `.mypy_cache`, `.ruff_cache`
|
|
302
|
+
- `*.so`, `*.dylib`, `*.dll`
|
|
303
|
+
|
|
304
|
+
Plus any patterns in your `.gitignore` file.
|
|
305
|
+
|
|
306
|
+
## Output Format
|
|
307
|
+
|
|
308
|
+
The generated file includes:
|
|
309
|
+
|
|
310
|
+
1. **Header:** Source directory and file count
|
|
311
|
+
2. **Directory Tree:** Visual representation of the file structure (optional)
|
|
312
|
+
3. **File Contents:** Each file with its relative path and content
|
|
313
|
+
|
|
314
|
+
Example output:
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
Code Export from: /path/to/project
|
|
318
|
+
Total files: 4
|
|
319
|
+
================================================================================
|
|
320
|
+
|
|
321
|
+
DIRECTORY TREE:
|
|
322
|
+
================================================================================
|
|
323
|
+
my-project/
|
|
324
|
+
├── src/
|
|
325
|
+
│ ├── main.py
|
|
326
|
+
│ └── utils.py
|
|
327
|
+
├── tests/
|
|
328
|
+
│ └── test_main.py
|
|
329
|
+
└── README.md
|
|
330
|
+
|
|
331
|
+
================================================================================
|
|
332
|
+
|
|
333
|
+
FILE 1/4: src/main.py
|
|
334
|
+
================================================================================
|
|
335
|
+
def main():
|
|
336
|
+
print("Hello, World!")
|
|
337
|
+
|
|
338
|
+
if __name__ == "__main__":
|
|
339
|
+
main()
|
|
340
|
+
|
|
341
|
+
================================================================================
|
|
342
|
+
...
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Use Cases
|
|
346
|
+
|
|
347
|
+
- 📚 **Code Review:** Share entire codebase in a single file
|
|
348
|
+
- 🤖 **LLM Input:** Feed code to ChatGPT, Claude, or other AI assistants
|
|
349
|
+
- 📖 **Documentation:** Create comprehensive code documentation
|
|
350
|
+
- 🔍 **Code Search:** Easy text-based search across entire project
|
|
351
|
+
- 📊 **Analysis:** Input for code analysis tools
|
|
352
|
+
- 💾 **Archival:** Simple code backup format
|
|
353
|
+
|
|
354
|
+
## Tips & Tricks
|
|
355
|
+
|
|
356
|
+
### For Large Projects
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Use specific extensions to reduce size
|
|
360
|
+
code-to-txt -e ".py" -t
|
|
361
|
+
|
|
362
|
+
# Exclude heavy directories
|
|
363
|
+
code-to-txt -x "node_modules/*" -x "venv/*" -x "dist/*"
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### For LLM Consumption
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
# Copy directly to clipboard for pasting into ChatGPT/Claude
|
|
370
|
+
code-to-txt --clipboard-only -e ".py .md"
|
|
371
|
+
|
|
372
|
+
# Or save and copy
|
|
373
|
+
code-to-txt -t -c -e ".py .js"
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### For Specific Features
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# Only include source files, exclude tests
|
|
380
|
+
code-to-txt -g "src/**/*.py" -g "lib/**/*.py"
|
|
381
|
+
|
|
382
|
+
# Only documentation
|
|
383
|
+
code-to-txt -e ".md .rst .txt"
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
## Requirements
|
|
387
|
+
|
|
388
|
+
- Python 3.10+
|
|
389
|
+
- Dependencies: `click`, `gitpython`, `pathspec`, `pyperclip`, `pyyaml`
|
|
390
|
+
|
|
391
|
+
## Development
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Clone repository
|
|
395
|
+
git clone https://github.com/AndriiSonsiadlo/code-to-txt.git
|
|
396
|
+
cd code-to-txt
|
|
397
|
+
|
|
398
|
+
# Install with Poetry
|
|
399
|
+
poetry install
|
|
400
|
+
|
|
401
|
+
# Run tests
|
|
402
|
+
poetry run pytest
|
|
403
|
+
|
|
404
|
+
# Run linting
|
|
405
|
+
poetry run ruff check .
|
|
406
|
+
poetry run mypy src/
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
## Contributing
|
|
410
|
+
|
|
411
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
412
|
+
|
|
413
|
+
## License
|
|
414
|
+
|
|
415
|
+
MIT License - see LICENSE file for details.
|
|
416
|
+
|
|
417
|
+
## Changelog
|
|
418
|
+
|
|
419
|
+
### v0.2.0
|
|
420
|
+
|
|
421
|
+
- ✨ Added automatic timestamp generation for output files
|
|
422
|
+
- 📋 Added clipboard support (`--clipboard` and `--clipboard-only`)
|
|
423
|
+
- 🎯 Improved extension handling (space/comma separated)
|
|
424
|
+
- 🔍 Added glob pattern support
|
|
425
|
+
- ⚙️ Added configuration file support (`.code-to-txt.yml`)
|
|
426
|
+
- 🚀 Expanded default file extensions and ignore patterns
|
|
427
|
+
- 🐛 Various bug fixes and improvements
|
|
428
|
+
|
|
429
|
+
### v0.1.0
|
|
430
|
+
|
|
431
|
+
- 🎉 Initial release
|
|
432
|
+
- 📁 Basic directory to text conversion
|
|
433
|
+
- 🌳 Directory tree generation
|
|
434
|
+
- 🚫 .gitignore support
|
|
435
|
+
- 🎨 Customizable separators
|
|
436
|
+
|
|
437
|
+
## Acknowledgments
|
|
438
|
+
|
|
439
|
+
Created by Andrii Sonsiadlo
|
|
440
|
+
|