Skip to content

Build: standardize output directory for artifacts #9888

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 20 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
faec2a2
Build: standardize output directory for artifacts
humitos Jan 11, 2023
0666df6
Build: decideif there is an output type based on the path existence
humitos Jan 11, 2023
b494c64
Test: update build tests to match changes
humitos Jan 11, 2023
d2bf3f0
Test: check if the file exist before continue
humitos Jan 12, 2023
2ab29ba
Build: simplify the code by running the commands inside the container
humitos Jan 12, 2023
faa611f
Test: add checks for more commands
humitos Jan 12, 2023
c80416a
Storage: use constants to make explicit artifact types
humitos Jan 17, 2023
67f0958
PDF builder: raise an error if the PDF file is not found
humitos Jan 17, 2023
f54ca20
Build: use `relative_output_dir` and `absolute_output_dir`
humitos Jan 17, 2023
ad270e9
Builder: execute `sphinx-build` from the same directory as `conf.py`
humitos Jan 17, 2023
da328fd
HTMLZip build: use `zip` inside the Docker container to build it
humitos Jan 17, 2023
782179f
Minor changes about docstring and final dot in a sentence :)
humitos Jan 17, 2023
c999e55
Test: adapt them to match thew path and arguments changes
humitos Jan 17, 2023
411bb4e
Merge branch 'main' of github.com:readthedocs/readthedocs.org into hu…
humitos Jan 17, 2023
8195ecb
pre-commit missing changes
humitos Jan 17, 2023
1f50a3b
Sphinx builder: better default
humitos Jan 18, 2023
a88bf14
Update readthedocs/doc_builder/backends/sphinx.py
humitos Jan 18, 2023
280e8e4
Update readthedocs/projects/tests/test_build_tasks.py
humitos Jan 18, 2023
e78442a
Minor changes to fix tests
humitos Jan 18, 2023
c301c0d
Docstring: explain why there is an exception handling at this place
humitos Jan 18, 2023
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
17 changes: 15 additions & 2 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BaseSphinx(BaseBuilder):

# Output directory relative to where the repository was cloned
# (e.g. "_readthedocs/<format>")
relative_output_dir = ""
relative_output_dir = None

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -61,6 +61,18 @@ def __init__(self, *args, **kwargs):
self.config_file,
)
except ProjectConfigurationError:
# NOTE: this exception handling here is weird to me.
# We are raising this exception from inside `project.confi_file` when:
# - the repository has multiple config files (none of them with `doc` in its filename)
# - there is no config file at all
#
# IMO, if there are multiple config files,
# the build should fail immediately communicating this to the user.
# This can be achived by unhandle the exception here
# and leaving `on_failure` Celery handle to deal with it.
#
# In case there is no config file, we should continue the build
# because Read the Docs will automatically create one for it.
Comment on lines +69 to +75
Copy link
Member

Choose a reason for hiding this comment

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

This seems reasonable. Is there a good way to implement the suggested logic? I guess raise a different exception for multiple configs that we raise (or just don't catch)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I documented this here in this way because I want to change the internal behavior and also communicate these errors better to the user. I'm opening a new issue with all these findings to continue working after this, since it will require some refactor and more design decisions.

pass

def _write_config(self, master_doc='index'):
Expand Down Expand Up @@ -396,6 +408,7 @@ def _post_build(self):
)
)

# **SECURITY CRITICAL: Advisory GHSA-hqwg-gjqw-h5wg**
# Move the directory into a temporal directory,
# so we can rename the directory for zip to use
# that prefix when zipping the files (arcname).
Expand Down Expand Up @@ -555,7 +568,7 @@ def _build_latexmk(self, cwd):
# step. I don't know exactly why but most of the documentation that
# I read differentiate this language from the others. I suppose
# it's because it mix kanji (Chinese) with its own symbols.
pdfs = latex_path.glob('*.pdf')
pdfs = Path(self.absolute_output_dir).glob("*.pdf")

for image in itertools.chain(images, pdfs):
self.run(
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def test_build_updates_documentation_type(self, load_yaml_config):
}
)

# Create the artifact paths, so it's detected by the builder
# Create the artifact paths, so that `store_build_artifacts`
# properly runs: https://github.com/readthedocs/readthedocs.org/blob/faa611fad689675f81101ea643770a6b669bf529/readthedocs/projects/tasks/builds.py#L798-L804
os.makedirs(self.project.artifact_path(version=self.version.slug, type_="html"))
os.makedirs(self.project.artifact_path(version=self.version.slug, type_="epub"))
os.makedirs(self.project.artifact_path(version=self.version.slug, type_="pdf"))
Expand Down
1 change: 1 addition & 0 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def setUp(self):

BaseSphinx.type = 'base'
BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
BaseSphinx.relative_output_dir = "_readthedocs/"

@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
@patch('readthedocs.projects.models.Project.checkout_path')
Expand Down