|
8 | 8 | import logging
|
9 | 9 | import os
|
10 | 10 | import shutil
|
| 11 | +import tarfile |
11 | 12 |
|
12 | 13 | import yaml
|
13 | 14 | from django.conf import settings
|
|
22 | 23 | from readthedocs.doc_builder.loader import get_builder_class
|
23 | 24 | from readthedocs.projects.constants import LOG_TEMPLATE
|
24 | 25 | from readthedocs.projects.models import Feature
|
| 26 | +from readthedocs.storage import build_languages_storage |
25 | 27 |
|
26 | 28 | log = logging.getLogger(__name__)
|
27 | 29 |
|
@@ -317,15 +319,117 @@ def setup_base(self):
|
317 | 319 | cli_args.append(
|
318 | 320 | self.venv_path(),
|
319 | 321 | )
|
| 322 | + |
| 323 | + # TODO: make ``self.config.python_interpreter`` return the correct value |
| 324 | + if self.project.has_feature(Feature.USE_NEW_DOCKER_IMAGES_STRUCTURE): |
| 325 | + python_interpreter = 'python' |
| 326 | + else: |
| 327 | + python_interpreter = self.config.python_interpreter |
| 328 | + |
320 | 329 | self.build_env.run(
|
321 |
| - self.config.python_interpreter, |
| 330 | + python_interpreter, |
322 | 331 | *cli_args,
|
323 | 332 | # Don't use virtualenv bin that doesn't exist yet
|
324 | 333 | bin_path=None,
|
325 | 334 | # Don't use the project's root, some config files can interfere
|
326 | 335 | cwd=None,
|
327 | 336 | )
|
328 | 337 |
|
| 338 | + def install_languages(self): |
| 339 | + if settings.RTD_DOCKER_COMPOSE: |
| 340 | + # Create a symlink for ``root`` user to use the same ``.asdf`` |
| 341 | + # installation than ``docs`` user. Required for local building |
| 342 | + # since everything is run as ``root`` when using Local Development |
| 343 | + # instance |
| 344 | + cmd = [ |
| 345 | + 'ln', |
| 346 | + '-s', |
| 347 | + '/home/docs/.asdf', |
| 348 | + '/root/.asdf', |
| 349 | + ] |
| 350 | + self.build_env.run( |
| 351 | + *cmd, |
| 352 | + ) |
| 353 | + |
| 354 | + # TODO: do not use a Feature flag here, but check for ``build.os`` and |
| 355 | + # ``build.languages`` instead |
| 356 | + if self.project.has_feature(Feature.USE_NEW_DOCKER_IMAGES_STRUCTURE): |
| 357 | + # TODO: iterate over ``build.languages`` and install all languages |
| 358 | + # specified for this project |
| 359 | + os = 'ubuntu20' |
| 360 | + language = 'python' |
| 361 | + version = '3.9.6' |
| 362 | + |
| 363 | + # TODO: generate the correct path for the Python version |
| 364 | + # language_path = f'{os}/{language}/2021-08-30/{version}.tar.gz' |
| 365 | + language_path = f'{os}-{language}-{version}.tar.gz' |
| 366 | + language_version_cached = build_languages_storage.exists(language_path) |
| 367 | + if language_version_cached: |
| 368 | + remote_fd = build_languages_storage.open(language_path, mode='rb') |
| 369 | + with tarfile.open(fileobj=remote_fd) as tar: |
| 370 | + # Extract it on the shared path between host and Docker container |
| 371 | + extract_path = os.path.join(self.project.doc_path, 'languages') |
| 372 | + tar.extractall(extra_path) |
| 373 | + |
| 374 | + # Move the extracted content to the ``asdf`` installation |
| 375 | + cmd = [ |
| 376 | + 'mv', |
| 377 | + f'{extract_path}/{version}', |
| 378 | + f'/home/docs/.asdf/installs/{language}/{version}', |
| 379 | + ] |
| 380 | + self.build_env.run( |
| 381 | + *cmd, |
| 382 | + ) |
| 383 | + else: |
| 384 | + # If the language version selected is not available from the |
| 385 | + # cache we compile it at build time |
| 386 | + cmd = [ |
| 387 | + 'asdf', |
| 388 | + 'install', |
| 389 | + language, |
| 390 | + version, |
| 391 | + ] |
| 392 | + self.build_env.run( |
| 393 | + *cmd, |
| 394 | + ) |
| 395 | + |
| 396 | + # Make the language version chosen by the user the default one |
| 397 | + cmd = [ |
| 398 | + 'asdf', |
| 399 | + 'global', |
| 400 | + language, |
| 401 | + version, |
| 402 | + ] |
| 403 | + self.build_env.run( |
| 404 | + *cmd, |
| 405 | + ) |
| 406 | + |
| 407 | + # Recreate shims for this language to make the new version |
| 408 | + # installed available |
| 409 | + cmd = [ |
| 410 | + 'asdf', |
| 411 | + 'reshim', |
| 412 | + language, |
| 413 | + ] |
| 414 | + self.build_env.run( |
| 415 | + *cmd, |
| 416 | + ) |
| 417 | + |
| 418 | + if not language_version_cached: |
| 419 | + # Install our own requirements if the version is compiled |
| 420 | + cmd = [ |
| 421 | + 'python', |
| 422 | + '-m' |
| 423 | + 'pip', |
| 424 | + 'install', |
| 425 | + '-U', |
| 426 | + 'virtualenv', |
| 427 | + 'setuptools', |
| 428 | + ] |
| 429 | + self.build_env.run( |
| 430 | + *cmd, |
| 431 | + ) |
| 432 | + |
329 | 433 | def install_core_requirements(self):
|
330 | 434 | """Install basic Read the Docs requirements into the virtualenv."""
|
331 | 435 | pip_install_cmd = [
|
|
0 commit comments