kopipasta 0.15.0__tar.gz → 0.16.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.

Potentially problematic release.


This version of kopipasta might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kopipasta
3
- Version: 0.15.0
3
+ Version: 0.16.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
@@ -5,7 +5,7 @@ import json
5
5
  import os
6
6
  import argparse
7
7
  import re
8
- from typing import Dict, List, Optional, Tuple
8
+ from typing import Dict, List, Optional, Set, Tuple
9
9
  import pyperclip
10
10
  import fnmatch
11
11
 
@@ -519,9 +519,9 @@ def select_files_in_directory(directory: str, ignore_patterns: List[str], curren
519
519
  else:
520
520
  print("Invalid choice. Please try again.")
521
521
 
522
- def process_directory(directory, ignore_patterns, current_char_count=0):
522
+ def process_directory(directory: str, ignore_patterns: List[str], current_char_count: int = 0) -> Tuple[List[FileTuple], Set[str], int]:
523
523
  files_to_include: List[FileTuple] = []
524
- processed_dirs = set()
524
+ processed_dirs: Set[str] = set()
525
525
 
526
526
  for root, dirs, files in os.walk(directory):
527
527
  dirs[:] = [d for d in dirs if not is_ignored(os.path.join(root, d), ignore_patterns)]
@@ -535,12 +535,8 @@ def process_directory(directory, ignore_patterns, current_char_count=0):
535
535
  if choice == 'y':
536
536
  selected_files, current_char_count = select_files_in_directory(root, ignore_patterns, current_char_count)
537
537
  for file_tuple in selected_files:
538
- if len(file_tuple) == 3:
539
- f, use_snippet, chunks = file_tuple
540
- files_to_include.append((os.path.join(root, f), use_snippet, chunks))
541
- else:
542
- f, use_snippet = file_tuple
543
- files_to_include.append((os.path.join(root, f), use_snippet))
538
+ full_path = os.path.join(root, file_tuple[0])
539
+ files_to_include.append((full_path, file_tuple[1], file_tuple[2], file_tuple[3]))
544
540
  processed_dirs.add(root)
545
541
  elif choice == 'n':
546
542
  dirs[:] = [] # Skip all subdirectories
@@ -553,20 +549,25 @@ def process_directory(directory, ignore_patterns, current_char_count=0):
553
549
 
554
550
  return files_to_include, processed_dirs, current_char_count
555
551
 
556
- def fetch_web_content(url):
552
+ def fetch_web_content(url: str) -> Tuple[Optional[FileTuple], Optional[str], Optional[str]]:
557
553
  try:
558
554
  response = requests.get(url)
559
555
  response.raise_for_status()
560
556
  content_type = response.headers.get('content-type', '').lower()
557
+ full_content = response.text
558
+ snippet = full_content[:10000] + "..." if len(full_content) > 10000 else full_content
559
+
561
560
  if 'json' in content_type:
562
- return response.json(), 'json'
561
+ content_type = 'json'
563
562
  elif 'csv' in content_type:
564
- return response.text, 'csv'
563
+ content_type = 'csv'
565
564
  else:
566
- return response.text, 'text'
565
+ content_type = 'text'
566
+
567
+ return (url, False, None, content_type), full_content, snippet
567
568
  except requests.RequestException as e:
568
569
  print(f"Error fetching content from {url}: {e}")
569
- return None, None
570
+ return None, None, None
570
571
 
571
572
  def read_file_content(file_path):
572
573
  _, ext = os.path.splitext(file_path)
@@ -670,7 +671,7 @@ def handle_env_variables(content, env_vars):
670
671
 
671
672
  return content
672
673
 
673
- def generate_prompt(files_to_include: List[FileTuple], ignore_patterns: List[str], web_contents: Dict[str, Tuple[str, str]], env_vars: Dict[str, str]) -> str:
674
+ def generate_prompt(files_to_include: List[FileTuple], ignore_patterns: List[str], web_contents: Dict[str, Tuple[FileTuple, str]], env_vars: Dict[str, str]) -> str:
674
675
  prompt = "# Project Overview\n\n"
675
676
  prompt += "## Project Structure\n\n"
676
677
  prompt += "```\n"
@@ -696,7 +697,8 @@ def generate_prompt(files_to_include: List[FileTuple], ignore_patterns: List[str
696
697
 
697
698
  if web_contents:
698
699
  prompt += "## Web Content\n\n"
699
- for url, (content, is_snippet, content_type) in web_contents.items():
700
+ for url, (file_tuple, content) in web_contents.items():
701
+ _, is_snippet, _, content_type = file_tuple
700
702
  content = handle_env_variables(content, env_vars)
701
703
  language = content_type if content_type in ['json', 'csv'] else ''
702
704
  prompt += f"### {url}{' (snippet)' if is_snippet else ''}\n\n```{language}\n{content}\n```\n\n"
@@ -721,18 +723,45 @@ def main():
721
723
  ignore_patterns = read_gitignore()
722
724
  env_vars = read_env_file()
723
725
 
724
- files_to_include:List[FileTuple] = []
726
+ files_to_include: List[FileTuple] = []
725
727
  processed_dirs = set()
726
- web_contents = {}
728
+ web_contents: Dict[str, Tuple[FileTuple, str]] = {}
727
729
  current_char_count = 0
728
730
 
729
731
  for input_path in args.inputs:
730
732
  if input_path.startswith(('http://', 'https://')):
731
- full_content, snippet = fetch_web_content(input_path)
732
- if full_content:
733
- web_contents[input_path] = (full_content, snippet)
734
- current_char_count += len(snippet if len(full_content) > 10000 else full_content)
735
- print(f"Added web content from: {input_path}")
733
+ result = fetch_web_content(input_path)
734
+ if result:
735
+ file_tuple, full_content, snippet = result
736
+ is_large = len(full_content) > 10000
737
+ if is_large:
738
+ print(f"\nContent from {input_path} is large. Here's a snippet:\n")
739
+ print(snippet)
740
+ print("\n" + "-"*40 + "\n")
741
+
742
+ while True:
743
+ choice = input("Use (f)ull content or (s)nippet? ").lower()
744
+ if choice in ['f', 's']:
745
+ break
746
+ print("Invalid choice. Please enter 'f' or 's'.")
747
+
748
+ if choice == 'f':
749
+ content = full_content
750
+ is_snippet = False
751
+ print("Using full content.")
752
+ else:
753
+ content = snippet
754
+ is_snippet = True
755
+ print("Using snippet.")
756
+ else:
757
+ content = full_content
758
+ is_snippet = False
759
+ print(f"Content from {input_path} is not large. Using full content.")
760
+
761
+ file_tuple = (file_tuple[0], is_snippet, file_tuple[2], file_tuple[3])
762
+ web_contents[input_path] = (file_tuple, content)
763
+ current_char_count += len(content)
764
+ print(f"Added {'snippet of ' if is_snippet else ''}web content from: {input_path}")
736
765
  elif os.path.isfile(input_path):
737
766
  if not is_ignored(input_path, ignore_patterns) and not is_binary(input_path):
738
767
  while True:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kopipasta
3
- Version: 0.15.0
3
+ Version: 0.16.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
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="kopipasta",
8
- version="0.15.0",
8
+ version="0.16.0",
9
9
  author="Mikko Korpela",
10
10
  author_email="mikko.korpela@gmail.com",
11
11
  description="A CLI tool to generate prompts with project structure and file contents",
File without changes
File without changes
File without changes
File without changes
File without changes