Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require the output dir to exist at startup, it might not exist yet #175

Merged
merged 3 commits into from
Sep 17, 2024

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Sep 4, 2024

Fixes #177.

With sphinx-autobuild 2023.9.3 and the https://github.com/python/peps repo:

❯ make clean
rm -rf .venv
rm -rf build topic
❯ sphinx-autobuild --builder html --jobs auto  --re-ignore="/\.idea/|/venv/|/pep-0000.rst|/topic/" --open-browser --delay 0 --port 55302 peps build
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.13/bin/sphinx-autobuild", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/sphinx_autobuild/__main__.py", line 34, in main
    args, build_args = _parse_args(list(argv))
                       ~~~~~~~~~~~^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/sphinx_autobuild/__main__.py", line 101, in _parse_args
    args.outdir = Path(sphinx_args.outputdir).resolve(strict=True)
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/pathlib/_local.py", line 670, in resolve
    return self.with_segments(os.path.realpath(self, strict=strict))
                              ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 439, in realpath
FileNotFoundError: [Errno 2] No such file or directory: '/Users/hugo/github/peps/build'

With 2024.4.16 it gets further, then another error and servers the page showing "Not Found":

diff --git a/Makefile b/Makefile
 .PHONY: _ensure-sphinx-autobuild
 _ensure-sphinx-autobuild:
-	make _ensure-package PACKAGE=sphinx-autobuild
+	make _ensure-package PACKAGE=sphinx-autobuild==2024.4.16
make clean
rm -rf .venv
rm -rf build topicsphinx-autobuild --builder html --jobs auto  --re-ignore="/\.idea/|/venv/|/pep-0000.rst|/topic/" --open-browser --delay 0 --port 55302 peps build
[sphinx-autobuild] Starting initial build
[sphinx-autobuild] > sphinx-build --builder html --jobs auto peps build
Running Sphinx v8.0.2
loading translations [en]... done
loading intersphinx inventory 'python' from https://docs.python.org/3//objects.inv ...
loading intersphinx inventory 'packaging' from https://packaging.python.org/en/latest//objects.inv ...
loading intersphinx inventory 'typing' from https://typing.readthedocs.io/en/latest//objects.inv ...
loading intersphinx inventory 'trio' from https://trio.readthedocs.io/en/latest//objects.inv ...
loading intersphinx inventory 'devguide' from https://devguide.python.org//objects.inv ...
loading intersphinx inventory 'py3.11' from https://docs.python.org/3.11//objects.inv ...
loading intersphinx inventory 'py3.12' from https://docs.python.org/3.12//objects.inv ...
loading intersphinx inventory 'py3.13' from https://docs.python.org/3.13//objects.inv ...
intersphinx inventory has moved: https://trio.readthedocs.io/en/latest//objects.inv -> https://trio.readthedocs.io/en/latest/objects.inv
intersphinx inventory has moved: https://typing.readthedocs.io/en/latest//objects.inv -> https://typing.readthedocs.io/en/latest/objects.inv
intersphinx inventory has moved: https://packaging.python.org/en/latest//objects.inv -> https://packaging.python.org/en/latest/objects.inv
building [html]: targets for 659 source files that are out of date
updating environment: [new config] 659 added, 0 changed, 0 removed
reading sources... [100%] pep-8014 .. topic/typing
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets...
copying static files... done
copying extra files... done
copying assets: done
writing output... [100%] pep-8013 .. topic/typing
generating indices... done
writing additional pages... done
copying images... [100%] pep-3147-1.png
dumping object inventory... done

Extension error (pep_sphinx_extensions):
Handler <function _post_build at 0x107e87380> for event 'build-finished' threw an exception (exception: cannot import name 'create_index_file' from 'build' (/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/build/__init__.py))
Sphinx exited with exit code: 2
The server will continue serving the build folder, but the contents being served are no longer in sync with the documentation sources. Please fix the cause of the error above or press Ctrl+C to stop the server.
[sphinx-autobuild] Serving on http://127.0.0.1:55302
[sphinx-autobuild] Waiting to detect changes...

But one thing at a time :)


git bisect points to 41a7d8c (no PR):

41a7d8ced2a23a3dc533341a2950209ab871eece is the first bad commit
commit 41a7d8ced2a23a3dc533341a2950209ab871eece
Author: Adam Turner <[email protected]>
Date:   Tue Sep 3 02:39:40 2024 -0500

    Prefer ``pathlib``

 sphinx_autobuild/__main__.py | 19 +++++++++----------
 sphinx_autobuild/filter.py   |  4 ++--
 sphinx_autobuild/server.py   | 14 +++-----------
 3 files changed, 14 insertions(+), 23 deletions(-)

This looks like the relevant bit:

     # Copy needed settings
-    args.sourcedir = os.path.realpath(sphinx_args.sourcedir)
-    args.outdir = os.path.realpath(sphinx_args.outputdir)
+    args.sourcedir = Path(sphinx_args.sourcedir).resolve(strict=True)
+    args.outdir = Path(sphinx_args.outputdir).resolve(strict=True)

We're just starting up, so the output directory (build in my case) might not exist yet. So let's not be strict in resolving it.

https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve

@hugovk
Copy link
Contributor Author

hugovk commented Sep 4, 2024

There may be problems with these strict checks too? I didn't test these cases so haven't changed them.

    if sphinx_args.doctreedir:
        args.doctree_dir = Path(sphinx_args.doctreedir).resolve(strict=True)
    else:
        args.doctree_dir = None
    if sphinx_args.warnfile:
        args.warnings_file = Path(sphinx_args.warnfile).resolve(strict=True)
    else:
        args.warnings_file = None

@hugovk
Copy link
Contributor Author

hugovk commented Sep 16, 2024

Also happening with CPython docs:

❯ make -C Doc clean venv htmllive
rm -rf ./venv
rm -rf build/*
Creating venv in ./venv
Using Python 3.13.0rc2
Creating virtualenv at: ./venv
Activate with: source venv/bin/activate
Resolved 29 packages in 12ms
Installed 29 packages in 74ms
 + accessible-pygments==0.0.5
 + alabaster==1.0.0
 + babel==2.16.0
 + beautifulsoup4==4.12.3
 + blurb==1.2.1
 + certifi==2024.8.30
 + charset-normalizer==3.3.2
 + docutils==0.21.2
 + idna==3.10
 + imagesize==1.4.1
 + jinja2==3.1.4
 + markupsafe==2.1.5
 + packaging==24.1
 + pydata-sphinx-theme==0.15.4
 + pygments==2.18.0
 + requests==2.32.3
 + snowballstemmer==2.2.0
 + soupsieve==2.6
 + sphinx==8.0.2
 + sphinx-notfound-page==1.0.4
 + sphinxcontrib-applehelp==2.0.0
 + sphinxcontrib-devhelp==2.0.0
 + sphinxcontrib-htmlhelp==2.1.0
 + sphinxcontrib-jsmath==1.0.1
 + sphinxcontrib-qthelp==2.0.0
 + sphinxcontrib-serializinghtml==2.0.0
 + sphinxext-opengraph==0.9.1
 + typing-extensions==4.12.2
 + urllib3==2.2.3
The venv has been created in the ./venv directory
/Applications/Xcode.app/Contents/Developer/usr/bin/make _ensure-package PACKAGE=sphinx-autobuild
venv already exists.
To recreate it, remove it first with `make clean-venv'.
if uv --version >/dev/null 2>&1; then \
                VIRTUAL_ENV=./venv uv pip install sphinx-autobuild; \
        else \
                ./venv/bin/python3 -m pip install sphinx-autobuild; \
        fi
Resolved 31 packages in 8ms
Installed 10 packages in 6ms
 + anyio==4.4.0
 + click==8.1.7
 + colorama==0.4.6
 + h11==0.14.0
 + sniffio==1.3.1
 + sphinx-autobuild==2024.9.3
 + starlette==0.38.5
 + uvicorn==0.30.6
 + watchfiles==0.24.0
 + websockets==13.0.1
mkdir -p build
Building NEWS from Misc/NEWS.d with blurb
./venv/bin/sphinx-autobuild -b html -d build/doctrees -j auto  --re-ignore="/venv/" --open-browser --delay 0 -W . build/html
Traceback (most recent call last):
  File "/Users/hugo/github/python/cpython/main/Doc/./venv/bin/sphinx-autobuild", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.13/site-packages/sphinx_autobuild/__main__.py", line 34, in main
    args, build_args = _parse_args(list(argv))
                       ~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.13/site-packages/sphinx_autobuild/__main__.py", line 101, in _parse_args
    args.outdir = Path(sphinx_args.outputdir).resolve(strict=True)
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/hugo/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/lib/python3.13/pathlib/_local.py", line 670, in resolve
    return self.with_segments(os.path.realpath(self, strict=strict))
                              ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 439, in realpath
FileNotFoundError: [Errno 2] No such file or directory: '/Users/hugo/github/python/cpython/main/Doc/build/html'
make: *** [build] Error 1

@AA-Turner AA-Turner merged commit 3e702d8 into sphinx-doc:main Sep 17, 2024
6 checks passed
@hugovk hugovk deleted the fix-outputdir-check branch September 18, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2024.09.03 release cannot build in a directory that does not exist
3 participants