kopipasta 0.5.0__py3-none-any.whl → 0.7.0__py3-none-any.whl
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.
Potentially problematic release.
This version of kopipasta might be problematic. Click here for more details.
- kopipasta/main.py +80 -20
- {kopipasta-0.5.0.dist-info → kopipasta-0.7.0.dist-info}/METADATA +1 -1
- kopipasta-0.7.0.dist-info/RECORD +8 -0
- kopipasta-0.5.0.dist-info/RECORD +0 -8
- {kopipasta-0.5.0.dist-info → kopipasta-0.7.0.dist-info}/LICENSE +0 -0
- {kopipasta-0.5.0.dist-info → kopipasta-0.7.0.dist-info}/WHEEL +0 -0
- {kopipasta-0.5.0.dist-info → kopipasta-0.7.0.dist-info}/entry_points.txt +0 -0
- {kopipasta-0.5.0.dist-info → kopipasta-0.7.0.dist-info}/top_level.txt +0 -0
kopipasta/main.py
CHANGED
|
@@ -111,8 +111,10 @@ def get_language_for_file(file_path):
|
|
|
111
111
|
def split_python_file(file_content):
|
|
112
112
|
"""
|
|
113
113
|
Splits Python code into logical chunks using the AST module.
|
|
114
|
+
Ensures each chunk is at least 10 lines.
|
|
114
115
|
Returns a list of tuples: (chunk_code, start_line, end_line)
|
|
115
116
|
"""
|
|
117
|
+
import ast
|
|
116
118
|
tree = ast.parse(file_content)
|
|
117
119
|
chunks = []
|
|
118
120
|
prev_end = 0
|
|
@@ -121,22 +123,75 @@ def split_python_file(file_content):
|
|
|
121
123
|
def get_code(start, end):
|
|
122
124
|
return ''.join(lines[start:end])
|
|
123
125
|
|
|
124
|
-
for node in ast.iter_child_nodes(tree)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
nodes = [node for node in ast.iter_child_nodes(tree) if hasattr(node, 'lineno')]
|
|
127
|
+
|
|
128
|
+
i = 0
|
|
129
|
+
while i < len(nodes):
|
|
130
|
+
node = nodes[i]
|
|
131
|
+
start_line = node.lineno - 1 # Convert to 0-indexed
|
|
132
|
+
end_line = getattr(node, 'end_lineno', None)
|
|
133
|
+
if end_line is None:
|
|
134
|
+
end_line = start_line + 1
|
|
135
|
+
|
|
136
|
+
# Merge chunks to meet minimum lines
|
|
137
|
+
chunk_start = start_line
|
|
138
|
+
chunk_end = end_line
|
|
139
|
+
while (chunk_end - chunk_start) < 10 and i + 1 < len(nodes):
|
|
140
|
+
i += 1
|
|
141
|
+
next_node = nodes[i]
|
|
142
|
+
next_start = next_node.lineno - 1
|
|
143
|
+
next_end = getattr(next_node, 'end_lineno', None) or next_start + 1
|
|
144
|
+
chunk_end = next_end
|
|
145
|
+
|
|
146
|
+
# Add code before the node (e.g., imports or global code)
|
|
147
|
+
if prev_end < chunk_start:
|
|
148
|
+
code = get_code(prev_end, chunk_start)
|
|
149
|
+
if code.strip():
|
|
150
|
+
chunks.append((code, prev_end, chunk_start))
|
|
151
|
+
|
|
152
|
+
# Add the merged chunk
|
|
153
|
+
code = get_code(chunk_start, chunk_end)
|
|
154
|
+
chunks.append((code, chunk_start, chunk_end))
|
|
155
|
+
prev_end = chunk_end
|
|
156
|
+
i += 1
|
|
157
|
+
|
|
136
158
|
# Add any remaining code at the end
|
|
137
159
|
if prev_end < len(lines):
|
|
138
|
-
|
|
139
|
-
|
|
160
|
+
code = get_code(prev_end, len(lines))
|
|
161
|
+
if code.strip():
|
|
162
|
+
chunks.append((code, prev_end, len(lines)))
|
|
163
|
+
|
|
164
|
+
return merge_small_chunks(chunks)
|
|
165
|
+
|
|
166
|
+
def merge_small_chunks(chunks, min_lines=10):
|
|
167
|
+
"""
|
|
168
|
+
Merges chunks to ensure each has at least min_lines lines.
|
|
169
|
+
"""
|
|
170
|
+
merged_chunks = []
|
|
171
|
+
buffer_code = ''
|
|
172
|
+
buffer_start = None
|
|
173
|
+
buffer_end = None
|
|
174
|
+
|
|
175
|
+
for code, start_line, end_line in chunks:
|
|
176
|
+
num_lines = end_line - start_line
|
|
177
|
+
if buffer_code == '':
|
|
178
|
+
buffer_code = code
|
|
179
|
+
buffer_start = start_line
|
|
180
|
+
buffer_end = end_line
|
|
181
|
+
else:
|
|
182
|
+
buffer_code += code
|
|
183
|
+
buffer_end = end_line
|
|
184
|
+
|
|
185
|
+
if (buffer_end - buffer_start) >= min_lines:
|
|
186
|
+
merged_chunks.append((buffer_code, buffer_start, buffer_end))
|
|
187
|
+
buffer_code = ''
|
|
188
|
+
buffer_start = None
|
|
189
|
+
buffer_end = None
|
|
190
|
+
|
|
191
|
+
if buffer_code:
|
|
192
|
+
merged_chunks.append((buffer_code, buffer_start, buffer_end))
|
|
193
|
+
|
|
194
|
+
return merged_chunks
|
|
140
195
|
|
|
141
196
|
def split_javascript_file(file_content):
|
|
142
197
|
"""
|
|
@@ -187,7 +242,7 @@ def split_javascript_file(file_content):
|
|
|
187
242
|
code = ''.join(lines[prev_end_line:])
|
|
188
243
|
chunks.append((code, prev_end_line, len(lines)))
|
|
189
244
|
|
|
190
|
-
return chunks
|
|
245
|
+
return merge_small_chunks(chunks)
|
|
191
246
|
|
|
192
247
|
def split_html_file(file_content):
|
|
193
248
|
"""
|
|
@@ -221,7 +276,7 @@ def split_html_file(file_content):
|
|
|
221
276
|
code = ''.join(lines[prev_end:])
|
|
222
277
|
chunks.append((code, prev_end, len(lines)))
|
|
223
278
|
|
|
224
|
-
return chunks
|
|
279
|
+
return merge_small_chunks(chunks)
|
|
225
280
|
|
|
226
281
|
def split_c_file(file_content):
|
|
227
282
|
"""
|
|
@@ -269,7 +324,7 @@ def split_c_file(file_content):
|
|
|
269
324
|
code = ''.join(lines[prev_end_line:])
|
|
270
325
|
chunks.append((code, prev_end_line, len(lines)))
|
|
271
326
|
|
|
272
|
-
return chunks
|
|
327
|
+
return merge_small_chunks(chunks)
|
|
273
328
|
|
|
274
329
|
def split_generic_file(file_content):
|
|
275
330
|
"""
|
|
@@ -288,7 +343,7 @@ def split_generic_file(file_content):
|
|
|
288
343
|
if start < len(lines):
|
|
289
344
|
chunk_code = ''.join(lines[start:])
|
|
290
345
|
chunks.append((chunk_code, start, len(lines)))
|
|
291
|
-
return chunks
|
|
346
|
+
return merge_small_chunks(chunks)
|
|
292
347
|
|
|
293
348
|
def select_file_patches(file_path):
|
|
294
349
|
file_content = read_file_contents(file_path)
|
|
@@ -461,8 +516,13 @@ def process_directory(directory, ignore_patterns, current_char_count=0):
|
|
|
461
516
|
continue
|
|
462
517
|
|
|
463
518
|
selected_files, current_char_count = select_files_in_directory(root, ignore_patterns, current_char_count)
|
|
464
|
-
|
|
465
|
-
|
|
519
|
+
for file_tuple in selected_files:
|
|
520
|
+
if len(file_tuple) == 3:
|
|
521
|
+
f, use_snippet, chunks = file_tuple
|
|
522
|
+
files_to_include.append((os.path.join(root, f), use_snippet, chunks))
|
|
523
|
+
else:
|
|
524
|
+
f, use_snippet = file_tuple
|
|
525
|
+
files_to_include.append((os.path.join(root, f), use_snippet))
|
|
466
526
|
processed_dirs.add(root)
|
|
467
527
|
|
|
468
528
|
return files_to_include, processed_dirs, current_char_count
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
kopipasta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
kopipasta/main.py,sha256=GuelSjwHqu5IPMMp8vsYPK7r0WxMzFeCg20f80xGSD4,27873
|
|
3
|
+
kopipasta-0.7.0.dist-info/LICENSE,sha256=xw4C9TAU7LFu4r_MwSbky90uzkzNtRwAo3c51IWR8lk,1091
|
|
4
|
+
kopipasta-0.7.0.dist-info/METADATA,sha256=U1MQF6l5bVukAIhFJRNz9R50CkJOVv43Hg2s_sbZNx8,5431
|
|
5
|
+
kopipasta-0.7.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
+
kopipasta-0.7.0.dist-info/entry_points.txt,sha256=but54qDNz1-F8fVvGstq_QID5tHjczP7bO7rWLFkc6Y,50
|
|
7
|
+
kopipasta-0.7.0.dist-info/top_level.txt,sha256=iXohixMuCdw8UjGDUp0ouICLYBDrx207sgZIJ9lxn0o,10
|
|
8
|
+
kopipasta-0.7.0.dist-info/RECORD,,
|
kopipasta-0.5.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
kopipasta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
kopipasta/main.py,sha256=E1YQkvGvZSZo6t7vjkRgc2YQINrCqttIFVOgUwCAGT4,26031
|
|
3
|
-
kopipasta-0.5.0.dist-info/LICENSE,sha256=xw4C9TAU7LFu4r_MwSbky90uzkzNtRwAo3c51IWR8lk,1091
|
|
4
|
-
kopipasta-0.5.0.dist-info/METADATA,sha256=4X9EkW4d2pO3Zp6HCfBujdITqRWVMKh9SrvxldcqW0g,5431
|
|
5
|
-
kopipasta-0.5.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
-
kopipasta-0.5.0.dist-info/entry_points.txt,sha256=but54qDNz1-F8fVvGstq_QID5tHjczP7bO7rWLFkc6Y,50
|
|
7
|
-
kopipasta-0.5.0.dist-info/top_level.txt,sha256=iXohixMuCdw8UjGDUp0ouICLYBDrx207sgZIJ9lxn0o,10
|
|
8
|
-
kopipasta-0.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|