From a4fcaa6531b0fe1980f045e1ecf8ad7a58a7a00a Mon Sep 17 00:00:00 2001 From: Jared Dillard Date: Fri, 16 May 2025 13:48:36 -0700 Subject: [PATCH] fix flake8 --- sphinx_llms_txt/__init__.py | 17 +++++++++++------ tests/test_integration.py | 5 ++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sphinx_llms_txt/__init__.py b/sphinx_llms_txt/__init__.py index 8c69273..df2fb97 100644 --- a/sphinx_llms_txt/__init__.py +++ b/sphinx_llms_txt/__init__.py @@ -184,7 +184,7 @@ class LLMSFullManager: else: logger.warning(f"sphinx-llm-txt: Source file not found for: {docname}") - # Add any remaining files (in alphabetical order) if not aborted due to max lines + # Add any remaining files (in alphabetical order) if not aborted if not abort_due_to_max_lines: remaining_files = sorted( [name for name in txt_files if name not in added_files] @@ -205,9 +205,12 @@ class LLMSFullManager: # Check if line limit was exceeded before creating the file max_lines = self.config.get("llms_txt_max_lines") - if abort_due_to_max_lines or (max_lines is not None and total_line_count > max_lines): + if abort_due_to_max_lines or ( + max_lines is not None and total_line_count > max_lines + ): logger.warning( - f"sphinx-llm-txt: Max line limit ({max_lines}) exceeded: {total_line_count} > {max_lines}. " + f"sphinx-llm-txt: Max line limit ({max_lines}) exceeded:" + f" {total_line_count} > {max_lines}. " f"Not creating llms-full.txt file." ) @@ -223,7 +226,8 @@ class LLMSFullManager: f.write("\n".join(content_parts)) logger.info( - f"sphinx-llms-txt: created {output_path} with {len(txt_files)} sources and {total_line_count} lines" + f"sphinx-llms-txt: created {output_path} with {len(txt_files)}" + f" sources and {total_line_count} lines" ) # Log summary information if requested @@ -237,14 +241,15 @@ class LLMSFullManager: """Read and format a single source file. Returns: - tuple: (content_str, line_count) where line_count is the number of lines in the file + tuple: (content_str, line_count) where line_count is the number of lines + in the file """ try: with open(file_path, "r", encoding="utf-8") as f: content = f.read() # Count the lines in the content - line_count = content.count('\n') + (0 if content.endswith('\n') else 1) + line_count = content.count("\n") + (0 if content.endswith("\n") else 1) section_lines = [content, ""] content_str = "\n".join(section_lines) diff --git a/tests/test_integration.py b/tests/test_integration.py index 8cba01f..a06ea78 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -2,6 +2,7 @@ import sys from pathlib import Path + from sphinx.testing.util import _clean_up_global_state @@ -95,7 +96,9 @@ def test_max_lines_limit(temp_dir, rootdir): # Check that the output file was NOT created (since it would exceed the limit) output_file = Path(app.outdir) / "limited.txt" - assert not output_file.exists(), f"Output file {output_file} exists but should not when limit is exceeded" + assert ( + not output_file.exists() + ), f"Output file {output_file} exists but should not when limit is exceeded" # Custom cleanup to avoid missing_ok issue sys.path[:] = app._saved_path