sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.61k stars 2.13k forks source link

Current master breaks ``make clean`` #13157

Open jfbu opened 10 hours ago

jfbu commented 10 hours ago

Describe the bug

We can not execute make clean anymore on current Sphinx HEAD

$ make html && make clean
Sphinx v8.2.0+/de24fd0b7 en cours d'exécution
chargement des traductions [en]... fait
chargement de l'environnement pickled... fait
construction en cours [mo] : cibles périmées pour les fichiers po 0
écriture... 
construction [html] : cibles périmées pour les fichiers sources 0
mise à jour de l'environnement : 0 ajouté(s), 0 modifié(s), 0 supprimé(s)
lecture des sources... 
recherche des fichiers périmés... aucun résultat trouvé
aucune cible n'est périmée.
La compilation a réussi.

Les pages HTML sont dans _build/html.
Removing everything under '_build'...
Traceback (most recent call last):
  File "/path/to/work/.venv312/bin/sphinx-build", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/path/to/sphinx/sphinx/cmd/build.py", line 561, in main
    return make_mode.run_make_mode(argv[1:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/sphinx/sphinx/cmd/make_mode.py", line 222, in run_make_mode
    return getattr(make, run_method)()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/sphinx/sphinx/cmd/make_mode.py", line 90, in build_clean
    rmtree(self.build_dir_join(item))
  File "/path/to/sphinx/sphinx/util/osutil.py", line 243, in rmtree
    os.remove(path)
FileNotFoundError: [Errno 2] No such file or directory: '_build/_build/html'
make: *** [Makefile:20: clean] Error 1

How to Reproduce

sphinx-quickstart then make html && make clean . Install first Sphinx master in a venv.

Environment Information

Platform:              darwin;
Python version:        3.12.3 (v3.12.3:f6650f9ad7, Apr  9 2024, 08:18:48) [Clang 13.0.0 (clang-1300.0.29.30)])
Python implementation: CPython
Sphinx version:        8.2.0+/de24fd0b7
Docutils version:      0.21.2
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

none

Additional context

First bad commit is reported by git bisect to be de24fd0b76f6d86672a721f8c130642b0be4bcf0

I am on macOS, too old to reveal which one here publicly (I don't want to be attacked by hackers).

jayaddison commented 5 hours ago

I can confirm this from following the repro steps.

A possible fix:

diff --git a/sphinx/cmd/make_mode.py b/sphinx/cmd/make_mode.py
index 5966b628a..7642b6229 100644
--- a/sphinx/cmd/make_mode.py
+++ b/sphinx/cmd/make_mode.py
@@ -87,7 +87,7 @@ class Make:
             return 1
         print("Removing everything under '%s'..." % self.build_dir)
         for item in self.build_dir.iterdir():
-            rmtree(self.build_dir_join(item))
+            rmtree(item)
         return 0

     def build_help(self) -> None:

(the code in HEAD performs a build-dir-relative resolution step for each item-to-clean from the build dir, and that seems to be the bug, I think?)

jayaddison commented 4 hours ago

We might also want to use build_dir instead of self.build_dir in that part of the code, I think. I'll open a pull request soon unless anyone else gets to that before me.