Skip to content

Commit 0ca1422

Browse files
committed
Merge branch 'main' of github.com:readthedocs/readthedocs.org into diataxis/main
2 parents a92b58c + ae91a51 commit 0ca1422

File tree

11 files changed

+232
-80
lines changed

11 files changed

+232
-80
lines changed

docs/user/config-file/v2.rst

+19-16
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ Below is an example YAML file which shows the most common configuration options:
2323
2424
# Set the version of Python and other tools you might need
2525
build:
26-
os: ubuntu-20.04
26+
os: ubuntu-22.04
2727
tools:
28-
python: "3.9"
28+
python: "3.11"
2929
# You can also specify other tool versions:
30-
# nodejs: "16"
31-
# rust: "1.55"
32-
# golang: "1.17"
30+
# nodejs: "19"
31+
# rust: "1.64"
32+
# golang: "1.19"
3333
3434
# Build documentation in the docs/ directory with Sphinx
3535
sphinx:
@@ -57,9 +57,9 @@ Below is an example YAML file which shows the most common configuration options:
5757
5858
# Set the version of Python and other tools you might need
5959
build:
60-
os: ubuntu-20.04
60+
os: ubuntu-22.04
6161
tools:
62-
python: "3.9"
62+
python: "3.11"
6363
6464
mkdocs:
6565
configuration: mkdocs.yml
@@ -201,7 +201,6 @@ Example:
201201
version: 2
202202
203203
python:
204-
version: "3.7"
205204
install:
206205
- requirements: docs/requirements.txt
207206
- requirements: requirements.txt
@@ -249,7 +248,6 @@ Example:
249248
version: 2
250249
251250
python:
252-
version: "3.7"
253251
install:
254252
- method: pip
255253
path: .
@@ -313,12 +311,12 @@ Python, Node.js, Rust, and Go.
313311
version: 2
314312
315313
build:
316-
os: ubuntu-20.04
314+
os: ubuntu-22.04
317315
tools:
318-
python: "3.9"
319-
nodejs: "16"
320-
rust: "1.55"
321-
golang: "1.17"
316+
python: "3.11"
317+
nodejs: "18"
318+
rust: "1.64"
319+
golang: "1.19"
322320
323321
build.os
324322
````````
@@ -381,6 +379,7 @@ Node.js version to use.
381379
- ``14``
382380
- ``16``
383381
- ``18``
382+
- ``19``
384383

385384
build.tools.rust
386385
````````````````
@@ -391,6 +390,7 @@ Rust version to use.
391390
:Options:
392391
- ``1.55``
393392
- ``1.61``
393+
- ``1.64``
394394

395395
build.tools.golang
396396
``````````````````
@@ -401,6 +401,7 @@ Go version to use.
401401
:Options:
402402
- ``1.17``
403403
- ``1.18``
404+
- ``1.19``
404405

405406
build.apt_packages
406407
``````````````````
@@ -444,7 +445,7 @@ See :doc:`/build-customization` for more details.
444445
build:
445446
os: ubuntu-22.04
446447
tools:
447-
python: "3.10"
448+
python: "3.11"
448449
jobs:
449450
pre_create_environment:
450451
- echo "Command run at 'pre_create_environment' step"
@@ -489,7 +490,7 @@ The ``_readthedocs/html`` directory (relative to the checkout's path) will be up
489490
build:
490491
os: ubuntu-22.04
491492
tools:
492-
python: "3.10"
493+
python: "3.11"
493494
commands:
494495
- pip install pelican
495496
- pelican --settings docs/pelicanconf.py --output _readthedocs/html/ docs/
@@ -803,7 +804,9 @@ Schema
803804

804805
You can see the complete schema
805806
`here <https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/rtd_tests/fixtures/spec/v2/schema.json>`_.
807+
This schema is available at `Schema Store`_, use it with your favorite editor for validation and autocompletion.
806808

809+
.. _Schema Store: https://www.schemastore.org/
807810

808811
Legacy ``build`` specification
809812
------------------------------

docs/user/guides/reproducible-builds.rst

+28-35
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ A configuration file with explicit dependencies looks like this:
4747
version: 2
4848
4949
build:
50-
os: "ubuntu-20.04"
50+
os: "ubuntu-22.04"
5151
tools:
52-
python: "3.9"
52+
python: "3.11"
5353
5454
# Build from the docs/ directory with Sphinx
5555
sphinx:
@@ -64,8 +64,8 @@ A configuration file with explicit dependencies looks like this:
6464
:caption: docs/requirements.txt
6565
6666
# Defining the exact version will make sure things don't break
67-
sphinx==4.2.0
68-
sphinx_rtd_theme==1.0.0
67+
sphinx==5.3.0
68+
sphinx_rtd_theme==1.1.1
6969
readthedocs-sphinx-search==0.1.1
7070
7171
Don't rely on implicit dependencies
@@ -88,9 +88,9 @@ for example:
8888
version: 2
8989
9090
build:
91-
os: "ubuntu-20.04"
91+
os: "ubuntu-22.04"
9292
tools:
93-
python: "3.9"
93+
python: "3.11"
9494
9595
sphinx:
9696
configuration: docs/conf.py
@@ -124,9 +124,9 @@ Some examples:
124124
.. code-block::
125125
:caption: docs/requirements.txt
126126
127-
sphinx==4.2.0
128-
sphinx_rtd_theme==1.0.0
129-
readthedocs-sphinx-search==0.1.1
127+
sphinx==5.3.0
128+
sphinx_rtd_theme==1.1.1
129+
readthedocs-sphinx-search==0.1.2
130130
131131
.. code-block:: yaml
132132
:caption: docs/environment.yaml
@@ -136,10 +136,10 @@ Some examples:
136136
- conda-forge
137137
- defaults
138138
dependencies:
139-
- sphinx==4.2.0
140-
- nbsphinx==0.8.1
139+
- sphinx==5.3.0
140+
- nbsphinx==0.8.10
141141
- pip:
142-
- sphinx_rtd_theme==1.0.0
142+
- sphinx_rtd_theme==1.1.1
143143
144144
❌ Bad:
145145
The latest or any other already installed version will be used,
@@ -197,49 +197,46 @@ and it generates a ``requirements.txt`` file with the full set of transitive dep
197197
.. code-block::
198198
:caption: docs/requirements.in
199199
200-
sphinx==4.2.0
200+
sphinx==5.3.0
201201
202202
.. code-block:: yaml
203203
:caption: docs/requirements.txt
204204
205-
# This file is autogenerated by pip-compile with python 3.7
206-
# To update, run:
205+
#
206+
# This file is autogenerated by pip-compile with Python 3.10
207+
# by the following command:
207208
#
208209
# pip-compile docs.in
209210
#
210211
alabaster==0.7.12
211212
# via sphinx
212-
babel==2.10.1
213+
babel==2.11.0
213214
# via sphinx
214-
certifi==2021.10.8
215+
certifi==2022.12.7
215216
# via requests
216-
charset-normalizer==2.0.12
217+
charset-normalizer==2.1.1
217218
# via requests
218-
docutils==0.17.1
219+
docutils==0.19
219220
# via sphinx
220-
idna==3.3
221+
idna==3.4
221222
# via requests
222-
imagesize==1.3.0
223-
# via sphinx
224-
importlib-metadata==4.11.3
223+
imagesize==1.4.1
225224
# via sphinx
226225
jinja2==3.1.2
227226
# via sphinx
228227
markupsafe==2.1.1
229228
# via jinja2
230-
packaging==21.3
229+
packaging==22.0
231230
# via sphinx
232-
pygments==2.11.2
231+
pygments==2.13.0
233232
# via sphinx
234-
pyparsing==3.0.8
235-
# via packaging
236-
pytz==2022.1
233+
pytz==2022.7
237234
# via babel
238-
requests==2.27.1
235+
requests==2.28.1
239236
# via sphinx
240237
snowballstemmer==2.2.0
241238
# via sphinx
242-
sphinx==4.4.0
239+
sphinx==5.3.0
243240
# via -r docs.in
244241
sphinxcontrib-applehelp==1.0.2
245242
# via sphinx
@@ -253,9 +250,5 @@ and it generates a ``requirements.txt`` file with the full set of transitive dep
253250
# via sphinx
254251
sphinxcontrib-serializinghtml==1.1.5
255252
# via sphinx
256-
typing-extensions==4.2.0
257-
# via importlib-metadata
258-
urllib3==1.26.9
253+
urllib3==1.26.13
259254
# via requests
260-
zipp==3.8.0
261-
# via importlib-metadata

readthedocs/api/v2/serializers.py

+77-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Defines serializers for each of our models."""
22

3+
import re
4+
35
from allauth.socialaccount.models import SocialAccount
6+
from django.conf import settings
47
from rest_framework import serializers
58

69
from readthedocs.builds.models import Build, BuildCommandResult, Version
@@ -133,11 +136,63 @@ class Meta:
133136
exclude = []
134137

135138

139+
class BuildCommandReadOnlySerializer(BuildCommandSerializer):
140+
141+
"""
142+
Serializer used on GETs to trim the commands' path.
143+
144+
Remove unreadable paths from the command outputs when returning it from the API.
145+
We could make this change at build level, but we want to avoid undoable issues from now
146+
and hack a small solution to fix the immediate problem.
147+
148+
This converts:
149+
$ /usr/src/app/checkouts/readthedocs.org/user_builds/
150+
<container_hash>/<project_slug>/envs/<version_slug>/bin/python
151+
$ /home/docs/checkouts/readthedocs.org/user_builds/
152+
<project_slug>/envs/<version_slug>/bin/python
153+
into
154+
$ python
155+
"""
156+
157+
command = serializers.SerializerMethodField()
158+
159+
def get_command(self, obj):
160+
project_slug = obj.build.version.project.slug
161+
version_slug = obj.build.version.slug
162+
docroot = settings.DOCROOT.rstrip("/") # remove trailing '/'
163+
164+
# Remove Docker hash from DOCROOT when running it locally
165+
# DOCROOT contains the Docker container hash (e.g. b7703d1b5854).
166+
# We have to remove it from the DOCROOT it self since it changes each time
167+
# we spin up a new Docker instance locally.
168+
container_hash = "/"
169+
if settings.RTD_DOCKER_COMPOSE:
170+
docroot = re.sub("/[0-9a-z]+/?$", "", settings.DOCROOT, count=1)
171+
container_hash = "/([0-9a-z]+/)?"
172+
173+
regex = f"{docroot}{container_hash}{project_slug}/envs/{version_slug}(/bin/)?"
174+
command = re.sub(regex, "", obj.command, count=1)
175+
return command
176+
177+
136178
class BuildSerializer(serializers.ModelSerializer):
137179

138-
"""Build serializer for user display, doesn't display internal fields."""
180+
"""
181+
Build serializer for user display.
139182
140-
commands = BuildCommandSerializer(many=True, read_only=True)
183+
This is the default serializer for Build objects over read-only operations from regular users.
184+
Take into account that:
185+
186+
- It doesn't display internal fields (builder, _config)
187+
- It's read-only for multiple fields (commands, project_slug, etc)
188+
189+
Staff users should use either:
190+
191+
- BuildAdminSerializer for write operations (e.g. builders hitting the API),
192+
- BuildAdminReadOnlySerializer for read-only actions (e.g. dashboard retrieving build details)
193+
"""
194+
195+
commands = BuildCommandReadOnlySerializer(many=True, read_only=True)
141196
project_slug = serializers.ReadOnlyField(source='project.slug')
142197
version_slug = serializers.ReadOnlyField(source='get_version_slug')
143198
docs_url = serializers.SerializerMethodField()
@@ -160,13 +215,32 @@ def get_docs_url(self, obj):
160215

161216
class BuildAdminSerializer(BuildSerializer):
162217

163-
"""Build serializer for display to admin users and build instances."""
218+
"""
219+
Build serializer to update Build objects from build instances.
220+
221+
It allows write operations on `commands` and display fields (e.g. builder)
222+
that are allowed for admin purposes only.
223+
"""
224+
225+
commands = BuildCommandSerializer(many=True, read_only=True)
164226

165227
class Meta(BuildSerializer.Meta):
166228
# `_config` should be excluded to avoid conflicts with `config`
167229
exclude = ('_config',)
168230

169231

232+
class BuildAdminReadOnlySerializer(BuildAdminSerializer):
233+
234+
"""
235+
Build serializer to retrieve Build objects from the dashboard.
236+
237+
It uses `BuildCommandReadOnlySerializer` to automatically parse the command
238+
and trim the useless path.
239+
"""
240+
241+
commands = BuildCommandReadOnlySerializer(many=True, read_only=True)
242+
243+
170244
class SearchIndexSerializer(serializers.Serializer):
171245
q = serializers.CharField(max_length=500)
172246
project = serializers.CharField(max_length=500, required=False)

0 commit comments

Comments
 (0)