mirror of
https://github.com/kirill-markin/repo-to-text.git
synced 2026-01-24 13:59:03 -08:00
Compare commits
No commits in common. "3ca1d7686798ef79102d128e3dc011576ddd8353" and "77209f30aa98531436550ef334541af82273393d" have entirely different histories.
3ca1d76867
...
77209f30aa
4 changed files with 8 additions and 22 deletions
|
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||
|
||||
[project]
|
||||
name = "repo-to-text"
|
||||
version = "1.0.0"
|
||||
version = "0.8.0"
|
||||
authors = [
|
||||
{ name = "Kirill Markin", email = "markinkirill@gmail.com" },
|
||||
]
|
||||
|
|
|
|||
|
|
@ -74,11 +74,6 @@ def parse_args() -> argparse.Namespace:
|
|||
help="List of files or directories to ignore in both tree and content sections. "
|
||||
"Supports wildcards (e.g., '*')."
|
||||
)
|
||||
parser.add_argument(
|
||||
'--skip-binary',
|
||||
action='store_true',
|
||||
help='Skip binary files in the output.'
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
def main() -> NoReturn:
|
||||
|
|
@ -100,8 +95,7 @@ def main() -> NoReturn:
|
|||
path=args.input_dir,
|
||||
output_dir=args.output_dir,
|
||||
to_stdout=args.stdout,
|
||||
cli_ignore_patterns=args.ignore_patterns,
|
||||
skip_binary=args.skip_binary
|
||||
cli_ignore_patterns=args.ignore_patterns
|
||||
)
|
||||
|
||||
logging.debug('repo-to-text script finished')
|
||||
|
|
|
|||
|
|
@ -261,8 +261,7 @@ def save_repo_to_text(
|
|||
path: str = '.',
|
||||
output_dir: Optional[str] = None,
|
||||
to_stdout: bool = False,
|
||||
cli_ignore_patterns: Optional[List[str]] = None,
|
||||
skip_binary: bool = False
|
||||
cli_ignore_patterns: Optional[List[str]] = None
|
||||
) -> str:
|
||||
"""Save repository structure and contents to a text file or multiple files."""
|
||||
# pylint: disable=too-many-locals
|
||||
|
|
@ -286,8 +285,7 @@ def save_repo_to_text(
|
|||
gitignore_spec,
|
||||
content_ignore_spec,
|
||||
tree_and_content_ignore_spec,
|
||||
maximum_word_count_per_file,
|
||||
skip_binary
|
||||
maximum_word_count_per_file
|
||||
)
|
||||
|
||||
if to_stdout:
|
||||
|
|
@ -354,12 +352,11 @@ def save_repo_to_text(
|
|||
return output_filepaths[0]
|
||||
return ""
|
||||
|
||||
def _read_file_content(file_path: str, skip_binary: bool = False) -> str:
|
||||
def _read_file_content(file_path: str) -> str:
|
||||
"""Read file content, handling binary files and broken symlinks.
|
||||
|
||||
Args:
|
||||
file_path: Path to the file to read
|
||||
skip_binary: Whether to skip binary files
|
||||
|
||||
Returns:
|
||||
str: File content or appropriate message for special cases
|
||||
|
|
@ -368,9 +365,6 @@ def _read_file_content(file_path: str, skip_binary: bool = False) -> str:
|
|||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
except UnicodeDecodeError:
|
||||
if skip_binary:
|
||||
logging.debug('Skipping binary file: %s', file_path)
|
||||
return "binary content skipped"
|
||||
logging.debug('Handling binary file contents: %s', file_path)
|
||||
with open(file_path, 'rb') as f_bin:
|
||||
binary_content: bytes = f_bin.read()
|
||||
|
|
@ -392,8 +386,7 @@ def generate_output_content(
|
|||
gitignore_spec: Optional[PathSpec],
|
||||
content_ignore_spec: Optional[PathSpec],
|
||||
tree_and_content_ignore_spec: Optional[PathSpec],
|
||||
maximum_word_count_per_file: Optional[int] = None,
|
||||
skip_binary: bool = False
|
||||
maximum_word_count_per_file: Optional[int] = None
|
||||
) -> List[str]:
|
||||
"""Generate the output content for the repository, potentially split into segments."""
|
||||
# pylint: disable=too-many-arguments
|
||||
|
|
@ -460,7 +453,7 @@ def generate_output_content(
|
|||
cleaned_relative_path = relative_path.replace('./', '', 1)
|
||||
|
||||
_add_chunk_to_output(f'\n<content full_path="{cleaned_relative_path}">\n')
|
||||
file_content = _read_file_content(file_path, skip_binary)
|
||||
file_content = _read_file_content(file_path)
|
||||
_add_chunk_to_output(file_content)
|
||||
_add_chunk_to_output('\n</content>\n')
|
||||
|
||||
|
|
|
|||
|
|
@ -84,8 +84,7 @@ def test_main_normal_execution(mock_save_repo: MagicMock) -> None:
|
|||
path='.',
|
||||
output_dir=None,
|
||||
to_stdout=True,
|
||||
cli_ignore_patterns=None,
|
||||
skip_binary=False
|
||||
cli_ignore_patterns=None
|
||||
)
|
||||
|
||||
@patch('repo_to_text.cli.cli.create_default_settings_file')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue