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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't sync _static dir for search builder #4120

Merged
merged 2 commits into from May 21, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions readthedocs/doc_builder/backends/sphinx.py
Expand Up @@ -237,6 +237,7 @@ class SearchBuilder(BaseSphinx):
type = 'sphinx_search'
sphinx_builder = 'json'
sphinx_build_dir = '_build/json'
ignore_patterns = ['_static']


class LocalMediaBuilder(BaseSphinx):
Expand Down
9 changes: 8 additions & 1 deletion readthedocs/doc_builder/base.py
Expand Up @@ -37,6 +37,8 @@ class BaseBuilder(object):

_force = False

ignore_patterns = []

# old_artifact_path = ..

def __init__(self, build_env, python_env, force=False):
Expand All @@ -63,7 +65,12 @@ def move(self, **__):
if os.path.exists(self.target):
shutil.rmtree(self.target)
log.info('Copying %s on the local filesystem', self.type)
shutil.copytree(self.old_artifact_path, self.target)
log.info('Ignoring patterns %s', self.ignore_patterns)
shutil.copytree(
self.old_artifact_path,
self.target,
ignore=shutil.ignore_patterns(*self.ignore_patterns)
Copy link
Member Author

Choose a reason for hiding this comment

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

)
else:
log.warning('Not moving docs, because the build dir is unknown.')

Expand Down
41 changes: 40 additions & 1 deletion readthedocs/rtd_tests/tests/test_doc_builder.py
Expand Up @@ -10,7 +10,7 @@
from mock import patch, Mock
import pytest

from readthedocs.doc_builder.backends.sphinx import BaseSphinx
from readthedocs.doc_builder.backends.sphinx import BaseSphinx, SearchBuilder
from readthedocs.projects.exceptions import ProjectConfigurationError
from readthedocs.projects.models import Project

Expand Down Expand Up @@ -69,3 +69,42 @@ def test_create_conf_py(self, conf_file, get_conf_py_path, _, get_config_params,
expected_conf_py = os.path.join(os.path.dirname(__file__), '..', 'files', 'conf.py')
with open(generated_conf_py) as gf, open(expected_conf_py) as ef:
self.assertEqual(gf.read(), ef.read())


class SphinxSearchBuilderTest(TestCase):

fixtures = ['test_data']

def setUp(self):
self.project = Project.objects.get(slug='pip')
self.version = self.project.versions.first()

build_env = namedtuple('project', 'version')
build_env.project = self.project
build_env.version = self.version

self.searchbuilder = SearchBuilder(build_env=build_env, python_env=None)

def test_ignore_patterns(self):
src = tempfile.mkdtemp()
src_static = os.path.join(src, '_static/')
src_other = os.path.join(src, 'other/')
os.mkdir(src_static)
os.mkdir(src_other)

dest = tempfile.mkdtemp()
dest_static = os.path.join(dest, '_static/')
dest_other = os.path.join(dest, 'other/')

self.searchbuilder.old_artifact_path = src
self.searchbuilder.target = dest

# There is a _static/ dir in src/ but not in dest/
self.assertTrue(os.path.exists(src_static))
self.assertFalse(os.path.exists(dest_static))

self.searchbuilder.move()

# There is a dest/other/ but not a dest/_static
self.assertFalse(os.path.exists(dest_static))
self.assertTrue(os.path.exists(dest_other))