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

fix parallel read error and add test #112

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions notfound/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ def process_doc(self, app, doctree):
if sphinx.version_info >= (3, 0, 0):
metadata.update({'nosearch': True})

def merge_other(self, app, env, docnames, other):
"""Merge in specified data regarding docnames from a different `BuildEnvironment`
object which coming from a subprocess in parallel builds."""
# TODO: find an example about why this is strictly required for parallel read
# https://github.com/readthedocs/sphinx-notfound-page/pull/112/files#r498219556
env.metadata.update(other.metadata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of other collector that works in parallel and implement this method? It would be good to put it here as reference as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find an example, so I read the documentation and printed out values while processing documents. Maybe @jakobandersen would be willing to look at it, because he diagnosed the problem here: sphinx-doc/sphinx#8256

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with what this extension is doing, so perhaps the following is irrelevant: technically you should not copy all data from other, but only the data related to the documents in docnames. However, I don't think I ever ran into a case where this in practice didn't mean "copy everything from other", so maybe is really is a guarantee that other at most contains data about those documents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be easier to add the filter than to prove whether or not it is needed. I will submit another PR.

humitos marked this conversation as resolved.
Show resolved Hide resolved


def handle_deprecated_configs(app, *args, **kwargs):
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/examples/parallel-build/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Sample ``conf.py``.
"""

master_doc = 'index'

extensions = [
'notfound.extension',
]


4 changes: 4 additions & 0 deletions tests/examples/parallel-build/five.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=======
Five
=======

4 changes: 4 additions & 0 deletions tests/examples/parallel-build/four.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=======
Four
=======

17 changes: 17 additions & 0 deletions tests/examples/parallel-build/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Samples for substitution directives
===================================

..

This is a test of parallel document builds. You need at least 5
documents. See:
https://github.com/adamtheturtle/sphinx-substitution-extensions/pull/173

.. toctree::
:hidden:

one
two
three
four
five
4 changes: 4 additions & 0 deletions tests/examples/parallel-build/one.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=====
One
=====

4 changes: 4 additions & 0 deletions tests/examples/parallel-build/three.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=======
Three
=======

4 changes: 4 additions & 0 deletions tests/examples/parallel-build/two.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=====
Two
=====

7 changes: 7 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import sphinx
import shutil
import subprocess
import warnings

srcdir = os.path.join(
Expand All @@ -27,6 +28,12 @@ def remove_sphinx_build_output():
shutil.rmtree(build_path)


@pytest.mark.sphinx(srcdir=srcdir)
def test_parallel_build():
# TODO: migrate to `app.build(..., parallel=2)` after merging
# https://github.com/sphinx-doc/sphinx/pull/8257
subprocess.check_call('sphinx-build -j 2 -W -b html tests/examples/parallel-build build', shell=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we call app.build here instead, with a parallel argument here in some way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, similar to what we are doing in the rest of the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other tests rely on SphinxTestApp, which does not have a way to pass parallel=2 through to the Sphinx constructor. I submitted a PR to add it, but we would have to wait for the next sphinx release, and it would not be usable for your testing that runs on older versions of sphinx. You can see a discussion of the problem in a PR for another extension: executablebooks/sphinx-book-theme#225 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Makes sense. So, should we check stderr or exit code or similar here to be sure that the subprocess didn't failed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, check call_raises an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. And I added the test first and verified that it caught the problem before adding the fix.

humitos marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.sphinx(srcdir=srcdir)
def test_404_page_created(app, status, warning):
app.build()
Expand Down