From 67158671ec1f8e71cb235265447843513b06c342 Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Mon, 8 Sep 2025 09:39:42 -0700 Subject: [PATCH 1/4] Fix 404.html page and link in the card --- conf.py | 4 ---- recipes_index.rst | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/conf.py b/conf.py index 6b50bf4ce4e..e23388fe655 100644 --- a/conf.py +++ b/conf.py @@ -158,10 +158,6 @@ def wrapper(*args, **kwargs): "author": "PyTorch Contributors", } -html_additional_pages = { - "404": "404.html", -} - # -- Sphinx-gallery configuration -------------------------------------------- sphinx_gallery_conf = { diff --git a/recipes_index.rst b/recipes_index.rst index 53239633b64..d3cf87b381f 100644 --- a/recipes_index.rst +++ b/recipes_index.rst @@ -34,7 +34,7 @@ from our full-length tutorials. :header: Defining a Neural Network :card_description: Learn how to use PyTorch's torch.nn package to create and define a neural network for the MNIST dataset. :image: _static/img/thumbnails/cropped/defining-a-network.PNG - :link: recipesrecipes/defining_a_neural_network.html + :link: recipes/recipes/defining_a_neural_network.html :tags: Basics .. customcarditem:: From b8361d7299c46db9582db8cda0c76d70063ea1c8 Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Mon, 8 Sep 2025 14:23:14 -0700 Subject: [PATCH 2/4] Update --- conf.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/conf.py b/conf.py index e23388fe655..40e35db955d 100644 --- a/conf.py +++ b/conf.py @@ -158,6 +158,8 @@ def wrapper(*args, **kwargs): "author": "PyTorch Contributors", } + + # -- Sphinx-gallery configuration -------------------------------------------- sphinx_gallery_conf = { @@ -187,6 +189,11 @@ def wrapper(*args, **kwargs): }, } +html_additional_pages = { + "404": "404.html", +} + + html_baseurl = "https://pytorch.org/tutorials/" # needed for sphinx-sitemap sitemap_locales = [None] sitemap_excludes = [ @@ -259,6 +266,22 @@ def wrapper(*args, **kwargs): r"/(?!" + re.escape(os.getenv("GALLERY_PATTERN")) + r")[^/]+$" ) +# Add 404.html to each gallery directory and all subdirectories +for i, gallery_dir in enumerate(sphinx_gallery_conf["gallery_dirs"]): + # Add 404.html to the main gallery directory + html_additional_pages[f"{gallery_dir}/404"] = "404.html" + + # Add 404.html to all subdirectories in the corresponding source directory + source_dir = Path(sphinx_gallery_conf["examples_dirs"][i]) + if source_dir.exists(): + # Find all subdirectories in the source directory + for subdir in source_dir.rglob("*"): + if subdir.is_dir() and subdir != source_dir: + # Calculate the relative path and corresponding gallery path + relative_path = subdir.relative_to(source_dir) + gallery_subdir = f"{gallery_dir}/{relative_path}" + html_additional_pages[f"{gallery_subdir}/404"] = "404.html" + for i in range(len(sphinx_gallery_conf["examples_dirs"])): gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i]) source_dir = Path(sphinx_gallery_conf["examples_dirs"][i]) From fa67de433c7ef7b4d9ead2cba101dcc5a7c2aafe Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Mon, 8 Sep 2025 15:33:18 -0700 Subject: [PATCH 3/4] Fix linter --- conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.py b/conf.py index 40e35db955d..495b25b7937 100644 --- a/conf.py +++ b/conf.py @@ -270,7 +270,7 @@ def wrapper(*args, **kwargs): for i, gallery_dir in enumerate(sphinx_gallery_conf["gallery_dirs"]): # Add 404.html to the main gallery directory html_additional_pages[f"{gallery_dir}/404"] = "404.html" - + # Add 404.html to all subdirectories in the corresponding source directory source_dir = Path(sphinx_gallery_conf["examples_dirs"][i]) if source_dir.exists(): From 50385dd973763da08e0e8a9b6390be20b3a53db2 Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Mon, 8 Sep 2025 15:53:51 -0700 Subject: [PATCH 4/4] Update --- .ci/docker/requirements.txt | 2 +- conf.py | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.ci/docker/requirements.txt b/.ci/docker/requirements.txt index 631a40d8088..a4e07afd8e7 100644 --- a/.ci/docker/requirements.txt +++ b/.ci/docker/requirements.txt @@ -16,7 +16,7 @@ pandocfilters==1.5.1 markdown==3.8.2 # PyTorch Theme --e git+https://github.com/pytorch/pytorch_sphinx_theme.git@23a72fbf4eb9cbcb7697a71d1889da4d7c10a4f7#egg=pytorch_sphinx_theme2 +-e git+https://github.com/pytorch/pytorch_sphinx_theme.git@b39e3e1e800132815a6187bf4f7bf545a2e9d8a9#egg=pytorch_sphinx_theme2 # Tutorial dependencies tqdm==4.66.1 diff --git a/conf.py b/conf.py index 495b25b7937..f0a55898a44 100644 --- a/conf.py +++ b/conf.py @@ -266,22 +266,6 @@ def wrapper(*args, **kwargs): r"/(?!" + re.escape(os.getenv("GALLERY_PATTERN")) + r")[^/]+$" ) -# Add 404.html to each gallery directory and all subdirectories -for i, gallery_dir in enumerate(sphinx_gallery_conf["gallery_dirs"]): - # Add 404.html to the main gallery directory - html_additional_pages[f"{gallery_dir}/404"] = "404.html" - - # Add 404.html to all subdirectories in the corresponding source directory - source_dir = Path(sphinx_gallery_conf["examples_dirs"][i]) - if source_dir.exists(): - # Find all subdirectories in the source directory - for subdir in source_dir.rglob("*"): - if subdir.is_dir() and subdir != source_dir: - # Calculate the relative path and corresponding gallery path - relative_path = subdir.relative_to(source_dir) - gallery_subdir = f"{gallery_dir}/{relative_path}" - html_additional_pages[f"{gallery_subdir}/404"] = "404.html" - for i in range(len(sphinx_gallery_conf["examples_dirs"])): gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i]) source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])