Skip to content

Commit 0c7c483

Browse files
committed
Build: missing updates from review
See #8453 (review)
1 parent 9d2d1a2 commit 0c7c483

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

readthedocs/doc_builder/python_environments.py

+35-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 = [
@@ -91,11 +101,12 @@ def install_build_tools(self):
91101
)
92102

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

96106
# 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'
107+
# see https://github.com/readthedocs/readthedocs.org/pull/8447#issuecomment-911562267
108+
# tool_path = f'{self.config.build.os}/{tool}/2021-08-30/{full_version}.tar.gz'
109+
tool_path = f'{self.config.build.os}-{tool}-{full_version}.tar.gz'
99110
tool_version_cached = build_tools_storage.exists(tool_path)
100111
if tool_version_cached:
101112
remote_fd = build_tools_storage.open(tool_path, mode='rb')
@@ -107,10 +118,10 @@ def install_build_tools(self):
107118
# Move the extracted content to the ``asdf`` installation
108119
cmd = [
109120
'mv',
110-
f'{extract_path}/{version}',
121+
f'{extract_path}/{full_version}',
111122
os.path.join(
112123
settings.RTD_DOCKER_WORKDIR,
113-
f'.asdf/installs/{tool}/{version}',
124+
f'.asdf/installs/{tool}/{full_version}',
114125
),
115126
]
116127
self.build_env.run(
@@ -121,18 +132,21 @@ def install_build_tools(self):
121132
'Cached version for tool not found. os=%s tool=%s version=% filename=%s',
122133
self.config.build.os,
123134
tool,
124-
version,
135+
full_version,
125136
tool_path,
126137
)
127138
# If the tool version selected is not available from the
128139
# cache we compile it at build time
129140
cmd = [
130-
# TODO: make this environment variable to work
131-
# 'PYTHON_CONFIGURE_OPTS="--enable-shared"',
141+
# TODO: make ``PYTHON_CONFIGURE_OPTS="--enable-shared"``
142+
# environment variable to work here. Note that
143+
# ``self.build_env.run`` does not support passing
144+
# environment for a particular command:
145+
# https://github.com/readthedocs/readthedocs.org/blob/9d2d1a2/readthedocs/doc_builder/environments.py#L430-L431
132146
'asdf',
133147
'install',
134148
tool,
135-
version,
149+
full_version,
136150
]
137151
self.build_env.run(
138152
*cmd,
@@ -143,14 +157,15 @@ def install_build_tools(self):
143157
'asdf',
144158
'global',
145159
tool,
146-
version,
160+
full_version,
147161
]
148162
self.build_env.run(
149163
*cmd,
150164
)
151165

152166
# Recreate shims for this tool to make the new version
153167
# installed available
168+
# https://asdf-vm.com/learn-more/faq.html#newly-installed-exectable-not-running
154169
cmd = [
155170
'asdf',
156171
'reshim',
@@ -163,9 +178,14 @@ def install_build_tools(self):
163178
if all([
164179
tool == 'python',
165180
# Do not install them if the tool version was cached
181+
# because these dependencies are already installed when
182+
# created with our script and uploaded to the cache's
183+
# bucket
166184
not tool_version_cached,
167-
# Do not install them on conda/mamba
168-
self.config.python_interpreter == 'python',
185+
# Do not install them on conda/mamba since they are not
186+
# needed because the environment is managed by conda/mamba
187+
# itself
188+
self.config.python_interpreter not in ('conda', 'mamba'),
169189
]):
170190
# Install our own requirements if the version is compiled
171191
cmd = [
@@ -673,7 +693,8 @@ def setup_base(self):
673693
if all([
674694
# The project has CONDA_USES_MAMBA feature enabled and,
675695
self.project.has_feature(Feature.CONDA_USES_MAMBA),
676-
# the project is not using ``build.tools``
696+
# the project is not using ``build.tools``,
697+
# which has mamba installed via asdf.
677698
not self.config.using_build_tools,
678699
]):
679700
self._install_mamba()

scripts/compile_version_upload_s3.sh

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

0 commit comments

Comments
 (0)