pyperclip not required

This commit is contained in:
Kirill Markin 2024-10-30 08:58:24 +01:00
parent 42326ae797
commit ad36a75a7a
3 changed files with 18 additions and 12 deletions

View file

@ -207,15 +207,22 @@ def save_repo_to_text(path='.', output_dir=None) -> str:
with open(output_file, 'r') as file: with open(output_file, 'r') as file:
repo_text = file.read() repo_text = file.read()
# Copy the contents to the clipboard # Try to copy to clipboard if pyperclip is installed
try: try:
import importlib.util
if importlib.util.find_spec("pyperclip"):
import pyperclip import pyperclip
pyperclip.copy(repo_text) pyperclip.copy(repo_text)
logging.debug('Repository structure and contents copied to clipboard') logging.debug('Repository structure and contents copied to clipboard')
else:
print("Tip: Install 'pyperclip' package to enable automatic clipboard copying:")
print(" pip install pyperclip")
except Exception as e: except Exception as e:
logging.warning('Could not copy to clipboard. You might be running this script over SSH or without clipboard support.') logging.warning('Could not copy to clipboard. You might be running this script over SSH or without clipboard support.')
logging.debug(f'Clipboard copy error: {e}') logging.debug(f'Clipboard copy error: {e}')
print(f"[SUCCESS] Repository structure and contents successfully saved to file: \"./{output_file}\"")
return output_file return output_file
def create_default_settings_file(): def create_default_settings_file():

View file

@ -1,6 +1,5 @@
setuptools==70.0.0 setuptools>=70.0.0
pathspec==0.12.1 pathspec>=0.12.1
pytest==8.2.2 pytest>=8.2.2
argparse==1.4.0 argparse>=1.4.0
pyperclip==1.8.2 PyYAML>=6.0.1
PyYAML==6.0.1

View file

@ -5,7 +5,7 @@ with open('requirements.txt') as f:
setup( setup(
name='repo-to-text', name='repo-to-text',
version='0.4.2', version='0.4.3',
author='Kirill Markin', author='Kirill Markin',
author_email='markinkirill@gmail.com', author_email='markinkirill@gmail.com',
description='Convert a directory structure and its contents into a single text file, including the tree output and file contents in markdown code blocks. It may be useful to chat with LLM about your code.', description='Convert a directory structure and its contents into a single text file, including the tree output and file contents in markdown code blocks. It may be useful to chat with LLM about your code.',