Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b63801bcff | ||
|
|
c45ebb0369 | ||
|
|
f5dcd15889 | ||
|
|
e64e20133a |
@@ -10,9 +10,9 @@ jobs:
|
|||||||
pre-commit:
|
pre-commit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.10
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
- uses: pre-commit/action@v3.0.1
|
- uses: pre-commit/action@v3.0.1
|
||||||
@@ -23,17 +23,17 @@ jobs:
|
|||||||
python-version: ['3.9', '3.10', '3.11', '3.12']
|
python-version: ['3.9', '3.10', '3.11', '3.12']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -e ".[dev]"
|
pip install -e . --group dev
|
||||||
|
|
||||||
# - name: Run mypy
|
# - name: Run mypy
|
||||||
# run: |
|
# run: |
|
||||||
|
|||||||
@@ -1,6 +1,24 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.6.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Improve _sources directory handling
|
||||||
|
`#47 <https://github.com/jdillard/sphinx-llms-txt/pull/47>`_
|
||||||
|
|
||||||
|
0.5.3
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Make sphinx a required dependency since there are imports from Sphinx
|
||||||
|
`#44 <https://github.com/jdillard/sphinx-llms-txt/pull/44>`_
|
||||||
|
|
||||||
|
0.5.2
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Remove support for singlehtml
|
||||||
|
`#40 <https://github.com/jdillard/sphinx-llms-txt/pull/40>`_
|
||||||
|
|
||||||
0.5.1
|
0.5.1
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Local development
|
|||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
pip install -e ".[dev]"
|
pip install -e . --group dev
|
||||||
|
|
||||||
#. Install pre-commit Git hook scripts:
|
#. Install pre-commit Git hook scripts:
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -26,13 +26,16 @@ classifiers = [
|
|||||||
license = {text = "MIT"}
|
license = {text = "MIT"}
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
dynamic = ["version"]
|
dynamic = ["version"]
|
||||||
|
dependencies = [
|
||||||
|
"sphinx",
|
||||||
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
download = "https://pypi.org/project/sphinx-llms-txt/"
|
download = "https://pypi.org/project/sphinx-llms-txt/"
|
||||||
source = "https://github.com/jdillard/sphinx-llms-txt"
|
source = "https://github.com/jdillard/sphinx-llms-txt"
|
||||||
changelog = "https://github.com/jdillard/sphinx-llms-txt/blob/master/CHANGELOG.rst"
|
changelog = "https://github.com/jdillard/sphinx-llms-txt/blob/master/CHANGELOG.rst"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[dependency-groups]
|
||||||
dev = [
|
dev = [
|
||||||
"pytest>=7.0.0",
|
"pytest>=7.0.0",
|
||||||
"black",
|
"black",
|
||||||
@@ -40,7 +43,6 @@ dev = [
|
|||||||
"mypy",
|
"mypy",
|
||||||
"isort",
|
"isort",
|
||||||
"pre-commit",
|
"pre-commit",
|
||||||
"sphinx",
|
|
||||||
]
|
]
|
||||||
test = [
|
test = [
|
||||||
"pytest>=7.0.0",
|
"pytest>=7.0.0",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from .manager import LLMSFullManager
|
|||||||
from .processor import DocumentProcessor
|
from .processor import DocumentProcessor
|
||||||
from .writer import FileWriter
|
from .writer import FileWriter
|
||||||
|
|
||||||
__version__ = "0.5.1"
|
__version__ = "0.6.0"
|
||||||
|
|
||||||
# Export classes needed by tests
|
# Export classes needed by tests
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@@ -129,7 +129,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||||||
def builder_inited(app):
|
def builder_inited(app):
|
||||||
"""Used to limit what builders are allowed to run the extension."""
|
"""Used to limit what builders are allowed to run the extension."""
|
||||||
|
|
||||||
allowed_builders = ["html", "singlehtml", "dirhtml"]
|
allowed_builders = ["html", "dirhtml"]
|
||||||
if hasattr(app, "builder") and app.builder.name in allowed_builders:
|
if hasattr(app, "builder") and app.builder.name in allowed_builders:
|
||||||
# Reset manager and root paragraph for each build
|
# Reset manager and root paragraph for each build
|
||||||
global _manager, _root_first_paragraph
|
global _manager, _root_first_paragraph
|
||||||
|
|||||||
+28
-12
@@ -197,7 +197,6 @@ class LLMSFullManager:
|
|||||||
possible_sources = [
|
possible_sources = [
|
||||||
Path(outdir) / "_sources",
|
Path(outdir) / "_sources",
|
||||||
Path(outdir) / "html" / "_sources",
|
Path(outdir) / "html" / "_sources",
|
||||||
Path(outdir) / "singlehtml" / "_sources",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
for path in possible_sources:
|
for path in possible_sources:
|
||||||
@@ -205,25 +204,42 @@ class LLMSFullManager:
|
|||||||
sources_dir = path
|
sources_dir = path
|
||||||
break
|
break
|
||||||
|
|
||||||
if not sources_dir:
|
# Get the correct page order (with or without source suffixes)
|
||||||
logger.warning(
|
|
||||||
"Could not find _sources directory, skipping llms-full creation"
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Get the correct page order with source suffixes
|
|
||||||
page_order = self.collector.get_page_order(sources_dir)
|
page_order = self.collector.get_page_order(sources_dir)
|
||||||
|
|
||||||
if not page_order:
|
if not page_order:
|
||||||
logger.warning(
|
logger.warning("Could not determine page order, skipping file generation")
|
||||||
"Could not determine page order, skipping llms-full creation"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Apply exclusion filter if configured
|
# Apply exclusion filter if configured
|
||||||
page_order = self.collector.filter_excluded_pages(page_order)
|
page_order = self.collector.filter_excluded_pages(page_order)
|
||||||
|
|
||||||
# Determine output file name and location
|
# If no sources directory, only generate llms.txt and return early
|
||||||
|
if not sources_dir:
|
||||||
|
# Generate llms.txt if requested
|
||||||
|
if self.config.get("llms_txt_file"):
|
||||||
|
filtered_page_order = self._filter_ignored_pages(page_order)
|
||||||
|
self.writer.write_verbose_info_to_file(
|
||||||
|
filtered_page_order,
|
||||||
|
self.collector.page_titles,
|
||||||
|
0, # No line count since no llms-full.txt
|
||||||
|
)
|
||||||
|
|
||||||
|
# Only warn if user explicitly wants llms-full.txt
|
||||||
|
if self.config.get("llms_txt_full_file"):
|
||||||
|
# Check if html_copy_source is False
|
||||||
|
if self.app and not self.app.config.html_copy_source:
|
||||||
|
logger.warning(
|
||||||
|
"Could not find _sources directory, skipping llms-full.txt."
|
||||||
|
"Set html_copy_source = True in conf.py to enable."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
"Could not find _sources directory, skipping llms-full.txt"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Determine output file name and location for llms-full.txt
|
||||||
output_filename = self.config.get("llms_txt_full_filename")
|
output_filename = self.config.get("llms_txt_full_filename")
|
||||||
output_path = Path(outdir) / output_filename
|
output_path = Path(outdir) / output_filename
|
||||||
|
|
||||||
|
|||||||
@@ -1031,3 +1031,128 @@ def test_code_files_ignored_patterns(tmp_path, caplog):
|
|||||||
assert (
|
assert (
|
||||||
"Code file pattern 'docs/**/*.rst' ignored." in captured_warnings[0]
|
"Code file pattern 'docs/**/*.rst' ignored." in captured_warnings[0]
|
||||||
), f"Warning message should contain expected text. Got: {captured_warnings[0]}"
|
), f"Warning message should contain expected text. Got: {captured_warnings[0]}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_llms_txt_generated_without_sources_dir(tmp_path):
|
||||||
|
"""Test that llms.txt is generated even when _sources directory doesn't exist."""
|
||||||
|
|
||||||
|
from sphinx_llms_txt.manager import LLMSFullManager
|
||||||
|
|
||||||
|
# Create manager
|
||||||
|
manager = LLMSFullManager()
|
||||||
|
|
||||||
|
# Set config to enable llms.txt
|
||||||
|
config = {
|
||||||
|
"llms_txt_file": True,
|
||||||
|
"llms_txt_filename": "llms.txt",
|
||||||
|
"llms_txt_full_file": True,
|
||||||
|
"llms_txt_full_filename": "llms-full.txt",
|
||||||
|
"llms_txt_exclude": [],
|
||||||
|
"llms_txt_directives": [],
|
||||||
|
}
|
||||||
|
manager.set_config(config)
|
||||||
|
|
||||||
|
# Create directories (but no _sources)
|
||||||
|
outdir = tmp_path / "build"
|
||||||
|
srcdir = tmp_path / "source"
|
||||||
|
outdir.mkdir()
|
||||||
|
srcdir.mkdir()
|
||||||
|
|
||||||
|
# Mock env with documents
|
||||||
|
class MockEnv:
|
||||||
|
all_docs = {"index": None, "about": None}
|
||||||
|
titles = {
|
||||||
|
"index": type("TitleNode", (), {"astext": lambda self: "Home"})(),
|
||||||
|
"about": type("TitleNode", (), {"astext": lambda self: "About"})(),
|
||||||
|
}
|
||||||
|
toctree_includes = {"index": ["about"]}
|
||||||
|
|
||||||
|
manager.set_env(MockEnv())
|
||||||
|
manager.set_master_doc("index")
|
||||||
|
|
||||||
|
# Update page titles directly in the collector
|
||||||
|
manager.update_page_title("index", "Home")
|
||||||
|
manager.update_page_title("about", "About")
|
||||||
|
|
||||||
|
# Call combine_sources - should generate llms.txt even without _sources
|
||||||
|
manager.combine_sources(str(outdir), str(srcdir))
|
||||||
|
|
||||||
|
# Verify llms.txt was created
|
||||||
|
llms_txt = outdir / "llms.txt"
|
||||||
|
assert llms_txt.exists(), "llms.txt should be generated even without _sources"
|
||||||
|
|
||||||
|
# Verify llms-full.txt was NOT created (since no _sources)
|
||||||
|
llms_full_txt = outdir / "llms-full.txt"
|
||||||
|
assert (
|
||||||
|
not llms_full_txt.exists()
|
||||||
|
), "llms-full.txt should not be generated without _sources"
|
||||||
|
|
||||||
|
# Read llms.txt and verify it has content
|
||||||
|
with open(llms_txt, "r", encoding="utf-8") as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
# Should contain page titles and links
|
||||||
|
assert "Home" in content
|
||||||
|
assert "About" in content
|
||||||
|
assert "index.html" in content
|
||||||
|
assert "about.html" in content
|
||||||
|
|
||||||
|
|
||||||
|
def test_llms_txt_no_warning_when_full_file_disabled(tmp_path, caplog):
|
||||||
|
"""
|
||||||
|
Test that no warning is logged when llms_txt_full_file=False and
|
||||||
|
_sources doesn't exist.
|
||||||
|
"""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from sphinx_llms_txt.manager import LLMSFullManager
|
||||||
|
|
||||||
|
# Create manager
|
||||||
|
manager = LLMSFullManager()
|
||||||
|
|
||||||
|
# Set config with llms_txt_full_file=False
|
||||||
|
config = {
|
||||||
|
"llms_txt_file": True,
|
||||||
|
"llms_txt_filename": "llms.txt",
|
||||||
|
"llms_txt_full_file": False, # User doesn't want llms-full.txt
|
||||||
|
"llms_txt_full_filename": "llms-full.txt",
|
||||||
|
"llms_txt_exclude": [],
|
||||||
|
"llms_txt_directives": [],
|
||||||
|
}
|
||||||
|
manager.set_config(config)
|
||||||
|
|
||||||
|
# Create directories (but no _sources)
|
||||||
|
outdir = tmp_path / "build"
|
||||||
|
srcdir = tmp_path / "source"
|
||||||
|
outdir.mkdir()
|
||||||
|
srcdir.mkdir()
|
||||||
|
|
||||||
|
# Mock env with documents
|
||||||
|
class MockEnv:
|
||||||
|
all_docs = {"index": None}
|
||||||
|
titles = {"index": type("TitleNode", (), {"astext": lambda self: "Home"})()}
|
||||||
|
toctree_includes = {"index": []}
|
||||||
|
|
||||||
|
manager.set_env(MockEnv())
|
||||||
|
manager.set_master_doc("index")
|
||||||
|
manager.update_page_title("index", "Home")
|
||||||
|
|
||||||
|
# Capture warnings
|
||||||
|
captured_warnings = []
|
||||||
|
|
||||||
|
def capture_warning(message, *args, **kwargs):
|
||||||
|
if "_sources" in str(message):
|
||||||
|
captured_warnings.append(message)
|
||||||
|
|
||||||
|
with patch("sphinx_llms_txt.manager.logger.warning", side_effect=capture_warning):
|
||||||
|
# Call combine_sources
|
||||||
|
manager.combine_sources(str(outdir), str(srcdir))
|
||||||
|
|
||||||
|
# Verify NO warning was logged since llms_txt_full_file=False
|
||||||
|
assert (
|
||||||
|
len(captured_warnings) == 0
|
||||||
|
), "No warning should be logged when llms_txt_full_file=False"
|
||||||
|
|
||||||
|
# Verify llms.txt was still created
|
||||||
|
llms_txt = outdir / "llms.txt"
|
||||||
|
assert llms_txt.exists()
|
||||||
|
|||||||
Reference in New Issue
Block a user