Skip to content

Commit 3c4b495

Browse files
authored
Merge pull request #8544 from readthedocs/humitos/build-review-updates
2 parents 7007f98 + d4485af commit 3c4b495

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

readthedocs/doc_builder/python_environments.py

+38-14
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,19 @@ def delete_existing_venv_dir(self):
7575
shutil.rmtree(venv_dir)
7676

7777
def install_build_tools(self):
78+
"""
79+
Install all ``build.tools`` defined by the user in the config file.
80+
81+
It uses ``asdf`` behind the scenes to manage all the tools and versions
82+
of them. These tools/versions are stored in the Cloud cache and are
83+
downloaded on each build (~50 - ~100Mb).
84+
85+
If the requested tool/version is not present in the cache, it's
86+
installed via ``asdf`` on the fly.
87+
"""
7888
if settings.RTD_DOCKER_COMPOSE:
7989
# Create a symlink for ``root`` user to use the same ``.asdf``
80-
# installation than ``docs`` user. Required for local building
90+
# installation as the ``docs`` user. Required for local building
8191
# since everything is run as ``root`` when using Local Development
8292
# instance
8393
cmd = [
@@ -88,14 +98,16 @@ def install_build_tools(self):
8898
]
8999
self.build_env.run(
90100
*cmd,
101+
record=False,
91102
)
92103

93104
for tool, version in self.config.build.tools.items():
94-
version = version.full_version # e.g. 3.9 -> 3.9.7
105+
full_version = version.full_version # e.g. 3.9 -> 3.9.7
95106

96107
# TODO: generate the correct path for the Python version
97-
# tool_path = f'{self.config.build.os}/{tool}/2021-08-30/{version}.tar.gz'
98-
tool_path = f'{self.config.build.os}-{tool}-{version}.tar.gz'
108+
# see https://github.com/readthedocs/readthedocs.org/pull/8447#issuecomment-911562267
109+
# tool_path = f'{self.config.build.os}/{tool}/2021-08-30/{full_version}.tar.gz'
110+
tool_path = f'{self.config.build.os}-{tool}-{full_version}.tar.gz'
99111
tool_version_cached = build_tools_storage.exists(tool_path)
100112
if tool_version_cached:
101113
remote_fd = build_tools_storage.open(tool_path, mode='rb')
@@ -107,32 +119,36 @@ def install_build_tools(self):
107119
# Move the extracted content to the ``asdf`` installation
108120
cmd = [
109121
'mv',
110-
f'{extract_path}/{version}',
122+
f'{extract_path}/{full_version}',
111123
os.path.join(
112124
settings.RTD_DOCKER_WORKDIR,
113-
f'.asdf/installs/{tool}/{version}',
125+
f'.asdf/installs/{tool}/{full_version}',
114126
),
115127
]
116128
self.build_env.run(
117129
*cmd,
130+
record=False,
118131
)
119132
else:
120133
log.debug(
121134
'Cached version for tool not found. os=%s tool=%s version=% filename=%s',
122135
self.config.build.os,
123136
tool,
124-
version,
137+
full_version,
125138
tool_path,
126139
)
127140
# If the tool version selected is not available from the
128141
# cache we compile it at build time
129142
cmd = [
130-
# TODO: make this environment variable to work
131-
# 'PYTHON_CONFIGURE_OPTS="--enable-shared"',
143+
# TODO: make ``PYTHON_CONFIGURE_OPTS="--enable-shared"``
144+
# environment variable to work here. Note that
145+
# ``self.build_env.run`` does not support passing
146+
# environment for a particular command:
147+
# https://github.com/readthedocs/readthedocs.org/blob/9d2d1a2/readthedocs/doc_builder/environments.py#L430-L431
132148
'asdf',
133149
'install',
134150
tool,
135-
version,
151+
full_version,
136152
]
137153
self.build_env.run(
138154
*cmd,
@@ -143,29 +159,36 @@ def install_build_tools(self):
143159
'asdf',
144160
'global',
145161
tool,
146-
version,
162+
full_version,
147163
]
148164
self.build_env.run(
149165
*cmd,
150166
)
151167

152168
# Recreate shims for this tool to make the new version
153169
# installed available
170+
# https://asdf-vm.com/learn-more/faq.html#newly-installed-exectable-not-running
154171
cmd = [
155172
'asdf',
156173
'reshim',
157174
tool,
158175
]
159176
self.build_env.run(
160177
*cmd,
178+
record=False,
161179
)
162180

163181
if all([
164182
tool == 'python',
165183
# Do not install them if the tool version was cached
184+
# because these dependencies are already installed when
185+
# created with our script and uploaded to the cache's
186+
# bucket
166187
not tool_version_cached,
167-
# Do not install them on conda/mamba
168-
self.config.python_interpreter == 'python',
188+
# Do not install them on conda/mamba since they are not
189+
# needed because the environment is managed by conda/mamba
190+
# itself
191+
self.config.python_interpreter not in ('conda', 'mamba'),
169192
]):
170193
# Install our own requirements if the version is compiled
171194
cmd = [
@@ -673,7 +696,8 @@ def setup_base(self):
673696
if all([
674697
# The project has CONDA_USES_MAMBA feature enabled and,
675698
self.project.has_feature(Feature.CONDA_USES_MAMBA),
676-
# the project is not using ``build.tools``
699+
# the project is not using ``build.tools``,
700+
# which has mamba installed via asdf.
677701
not self.config.using_build_tools,
678702
]):
679703
self._install_mamba()

readthedocs/rtd_tests/tests/test_celery.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -592,17 +592,17 @@ def test_build_tools(self, load_config, build_run):
592592
[
593593
mock.call('asdf', 'install', 'python', python_version),
594594
mock.call('asdf', 'global', 'python', python_version),
595-
mock.call('asdf', 'reshim', 'python'),
595+
mock.call('asdf', 'reshim', 'python', record=False),
596596
mock.call('python', '-mpip', 'install', '-U', 'virtualenv', 'setuptools'),
597597
mock.call('asdf', 'install', 'nodejs', nodejs_version),
598598
mock.call('asdf', 'global', 'nodejs', nodejs_version),
599-
mock.call('asdf', 'reshim', 'nodejs'),
599+
mock.call('asdf', 'reshim', 'nodejs', record=False),
600600
mock.call('asdf', 'install', 'rust', rust_version),
601601
mock.call('asdf', 'global', 'rust', rust_version),
602-
mock.call('asdf', 'reshim', 'rust'),
602+
mock.call('asdf', 'reshim', 'rust', record=False),
603603
mock.call('asdf', 'install', 'golang', golang_version),
604604
mock.call('asdf', 'global', 'golang', golang_version),
605-
mock.call('asdf', 'reshim', 'golang'),
605+
mock.call('asdf', 'reshim', 'golang', record=False),
606606
mock.ANY,
607607
],
608608
)
@@ -668,30 +668,34 @@ def test_build_tools_cached(self, load_config, build_run, build_tools_storage, t
668668
# and on CircleCI
669669
mock.ANY,
670670
f'/home/docs/.asdf/installs/python/{python_version}',
671+
record=False,
671672
),
672673
mock.call('asdf', 'global', 'python', python_version),
673-
mock.call('asdf', 'reshim', 'python'),
674+
mock.call('asdf', 'reshim', 'python', record=False),
674675
mock.call(
675676
'mv',
676677
mock.ANY,
677678
f'/home/docs/.asdf/installs/nodejs/{nodejs_version}',
679+
record=False,
678680
),
679681
mock.call('asdf', 'global', 'nodejs', nodejs_version),
680-
mock.call('asdf', 'reshim', 'nodejs'),
682+
mock.call('asdf', 'reshim', 'nodejs', record=False),
681683
mock.call(
682684
'mv',
683685
mock.ANY,
684686
f'/home/docs/.asdf/installs/rust/{rust_version}',
687+
record=False,
685688
),
686689
mock.call('asdf', 'global', 'rust', rust_version),
687-
mock.call('asdf', 'reshim', 'rust'),
690+
mock.call('asdf', 'reshim', 'rust', record=False),
688691
mock.call(
689692
'mv',
690693
mock.ANY,
691694
f'/home/docs/.asdf/installs/golang/{golang_version}',
695+
record=False,
692696
),
693697
mock.call('asdf', 'global', 'golang', golang_version),
694-
mock.call('asdf', 'reshim', 'golang'),
698+
mock.call('asdf', 'reshim', 'golang', record=False),
695699
mock.ANY,
696700
],
697701
)

scripts/compile_version_upload_s3.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# PRODUCTION ENVIRONMENT
2424
#
2525
# To create a pre-compiled cached version and make it available on production,
26-
# the script has to be ran from a builder (build-default or build-large) and
26+
# **the script must be ran from a builder (build-default or build-large)** and
2727
# it's required to set the following environment variables for an IAM user with
2828
# permissions on ``build-tools`` S3's bucket:
2929
#

0 commit comments

Comments
 (0)