fix flake8
This commit is contained in:
@@ -184,7 +184,7 @@ class LLMSFullManager:
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"sphinx-llm-txt: Source file not found for: {docname}")
|
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:
|
if not abort_due_to_max_lines:
|
||||||
remaining_files = sorted(
|
remaining_files = sorted(
|
||||||
[name for name in txt_files if name not in added_files]
|
[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
|
# Check if line limit was exceeded before creating the file
|
||||||
max_lines = self.config.get("llms_txt_max_lines")
|
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(
|
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."
|
f"Not creating llms-full.txt file."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -223,7 +226,8 @@ class LLMSFullManager:
|
|||||||
f.write("\n".join(content_parts))
|
f.write("\n".join(content_parts))
|
||||||
|
|
||||||
logger.info(
|
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
|
# Log summary information if requested
|
||||||
@@ -237,14 +241,15 @@ class LLMSFullManager:
|
|||||||
"""Read and format a single source file.
|
"""Read and format a single source file.
|
||||||
|
|
||||||
Returns:
|
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:
|
try:
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
with open(file_path, "r", encoding="utf-8") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
# Count the lines in the content
|
# 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, ""]
|
section_lines = [content, ""]
|
||||||
content_str = "\n".join(section_lines)
|
content_str = "\n".join(section_lines)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from sphinx.testing.util import _clean_up_global_state
|
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)
|
# Check that the output file was NOT created (since it would exceed the limit)
|
||||||
output_file = Path(app.outdir) / "limited.txt"
|
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
|
# Custom cleanup to avoid missing_ok issue
|
||||||
sys.path[:] = app._saved_path
|
sys.path[:] = app._saved_path
|
||||||
|
|||||||
Reference in New Issue
Block a user