kopipasta 0.5.0__py3-none-any.whl → 0.6.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 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
- if hasattr(node, 'lineno'):
126
- start_line = node.lineno - 1 # Convert to 0-indexed
127
- end_line = getattr(node, 'end_lineno', None)
128
- if end_line is None:
129
- end_line = node.lineno
130
- # Add code before the node
131
- if prev_end < start_line:
132
- chunks.append((get_code(prev_end, start_line), prev_end, start_line))
133
- # Add the node code
134
- chunks.append((get_code(start_line, end_line), start_line, end_line))
135
- prev_end = end_line
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
- chunks.append((get_code(prev_end, len(lines)), prev_end, len(lines)))
139
- return chunks
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kopipasta
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: A CLI tool to generate prompts with project structure and file contents
5
5
  Home-page: https://github.com/mkorpela/kopipasta
6
6
  Author: Mikko Korpela
@@ -0,0 +1,8 @@
1
+ kopipasta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ kopipasta/main.py,sha256=OmS54IQo4mJLUu_t6RYrEuLuJlFmnN9lEoZbZya3m-A,27657
3
+ kopipasta-0.6.0.dist-info/LICENSE,sha256=xw4C9TAU7LFu4r_MwSbky90uzkzNtRwAo3c51IWR8lk,1091
4
+ kopipasta-0.6.0.dist-info/METADATA,sha256=F3sWcMABaUy5hT0RWuZwpCkIsvhMNxLya8mhV6nXcFs,5431
5
+ kopipasta-0.6.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
6
+ kopipasta-0.6.0.dist-info/entry_points.txt,sha256=but54qDNz1-F8fVvGstq_QID5tHjczP7bO7rWLFkc6Y,50
7
+ kopipasta-0.6.0.dist-info/top_level.txt,sha256=iXohixMuCdw8UjGDUp0ouICLYBDrx207sgZIJ9lxn0o,10
8
+ kopipasta-0.6.0.dist-info/RECORD,,
@@ -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,,