From ad36a75a7a75e689aa136cb03cac64939c0d250f Mon Sep 17 00:00:00 2001 From: Kirill Markin Date: Wed, 30 Oct 2024 08:58:24 +0100 Subject: [PATCH] pyperclip not required --- repo_to_text/main.py | 17 ++++++++++++----- requirements.txt | 11 +++++------ setup.py | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/repo_to_text/main.py b/repo_to_text/main.py index 63f2e13..3f11179 100644 --- a/repo_to_text/main.py +++ b/repo_to_text/main.py @@ -206,16 +206,23 @@ def save_repo_to_text(path='.', output_dir=None) -> str: # Read the contents of the generated file with open(output_file, 'r') as file: repo_text = file.read() - - # Copy the contents to the clipboard + + # Try to copy to clipboard if pyperclip is installed try: - import pyperclip - pyperclip.copy(repo_text) - logging.debug('Repository structure and contents copied to clipboard') + import importlib.util + if importlib.util.find_spec("pyperclip"): + import pyperclip + pyperclip.copy(repo_text) + 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: 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}') + print(f"[SUCCESS] Repository structure and contents successfully saved to file: \"./{output_file}\"") + return output_file def create_default_settings_file(): diff --git a/requirements.txt b/requirements.txt index 1d9e36e..fee77c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ -setuptools==70.0.0 -pathspec==0.12.1 -pytest==8.2.2 -argparse==1.4.0 -pyperclip==1.8.2 -PyYAML==6.0.1 +setuptools>=70.0.0 +pathspec>=0.12.1 +pytest>=8.2.2 +argparse>=1.4.0 +PyYAML>=6.0.1 diff --git a/setup.py b/setup.py index abfe716..e2d952c 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='repo-to-text', - version='0.4.2', + version='0.4.3', author='Kirill Markin', 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.',