Skip to content

Stop creating a conf.py automatically and doing magic around README handling #5609

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

Merged
merged 18 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 1 addition & 19 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ def __init__(self, *args, **kwargs):
self.sphinx_build_dir,
)

def _write_config(self, master_doc='index'):
"""Create ``conf.py`` if it doesn't exist."""
docs_dir = self.docs_dir()
conf_template = render_to_string(
'sphinx/conf.py.conf',
{
'project': self.project,
'version': self.version,
'master_doc': master_doc,
},
)
conf_file = os.path.join(docs_dir, 'conf.py')
safe_write(conf_file, conf_template)

def get_config_params(self):
"""Get configuration parameters to be rendered into the conf file."""
# TODO this should be handled better in the theme
Expand Down Expand Up @@ -168,14 +154,10 @@ def get_config_params(self):

def append_conf(self, **__):
"""
Find or create a ``conf.py`` and appends default content.
Find a ``conf.py`` and appends default content.

The default content is rendered from ``doc_builder/conf.py.tmpl``.
"""
if self.config_file is None:
master_doc = self.create_index(extension='rst')
self._write_config(master_doc=master_doc)

try:
self.config_file = (
self.config_file or self.project.conf_file(self.version.slug)
Expand Down
9 changes: 1 addition & 8 deletions readthedocs/doc_builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ def create_index(self, extension='md', **__):
'index.{ext}'.format(ext=extension),
)
if not os.path.exists(index_filename):
readme_filename = os.path.join(
docs_dir,
'README.{ext}'.format(ext=extension),
)
if os.path.exists(readme_filename):
return 'README'

index_file = open(index_filename, 'w+')
index_text = """

Expand All @@ -118,7 +111,7 @@ def create_index(self, extension='md', **__):

This is an autogenerated index file.

Please create an ``index.{ext}`` or ``README.{ext}`` file with your own content
Please create an ``index.{ext}`` file with your own content
under the root (or ``/docs``) directory in your repository.

If you want to use another markup, choose a different builder in your settings.
Expand Down
39 changes: 6 additions & 33 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,23 @@ def test_conf_py_path(self, checkout_path, docs_dir):
)

@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index')
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
@patch('readthedocs.builds.models.Version.get_conf_py_path')
@patch('readthedocs.projects.models.Project.checkout_path')
def test_create_conf_py(
def test_project_without_conf_py(
self, checkout_path, get_conf_py_path, _,
get_config_params, create_index, docs_dir,
get_config_params, docs_dir,
):
"""
Test for a project without ``conf.py`` file.

When this happen, the ``get_conf_py_path`` raises a
``ProjectConfigurationError`` which is captured by our own code and
generates a conf.py file based using our own template.

This template should be properly rendered in Python2 and Python3 without
any kind of exception raised by ``append_conf`` (we were originally
having a ``TypeError`` because of an encoding problem in Python3)
``ProjectConfigurationError`` which is captured by our own code.
"""
tmp_dir = tempfile.mkdtemp()
checkout_path.return_value = tmp_dir
docs_dir.return_value = tmp_dir
create_index.return_value = 'README.rst'
get_config_params.return_value = {}
get_conf_py_path.side_effect = ProjectConfigurationError
python_env = Virtualenv(
Expand All @@ -105,36 +98,17 @@ def test_create_conf_py(
build_env=self.build_env,
python_env=python_env,
)
try:
with pytest.raises(ProjectConfigurationError):
base_sphinx.append_conf()
except Exception:
pytest.fail('Exception was generated when append_conf called.')

# Check the content generated by our method is the same than what we
# expects from a pre-generated file
generated_conf_py = os.path.join(base_sphinx.docs_dir(), 'conf.py')
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:
autogenerated_confpy_lines = 28
self.assertEqual(
gf.readlines()[:autogenerated_confpy_lines],
ef.readlines()[:autogenerated_confpy_lines],
)

@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index')
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
@patch('readthedocs.builds.models.Version.get_conf_py_path')
@patch('readthedocs.projects.models.Project.checkout_path')
def test_multiple_conf_py(
self, checkout_path, get_conf_py_path, _, get_config_params,
create_index, docs_dir,
self, checkout_path, get_conf_py_path,
_, get_config_params, docs_dir
):
"""
Test for a project with multiple ``conf.py`` files.
Expand All @@ -148,7 +122,6 @@ def test_multiple_conf_py(
tmp_docs_dir.join('test').mkdir().join('conf.py').write('')
docs_dir.return_value = str(tmp_docs_dir)
checkout_path.return_value = str(tmp_docs_dir)
create_index.return_value = 'README.rst'
get_config_params.return_value = {}
get_conf_py_path.side_effect = ProjectConfigurationError
python_env = Virtualenv(
Expand Down