|
4 | 4 | import structlog
|
5 | 5 | import yaml
|
6 | 6 | from django.conf import settings
|
7 |
| -from django.template.loader import render_to_string |
8 |
| -from django.utils import timezone |
9 | 7 | from django.utils.translation import gettext_lazy as _
|
10 | 8 |
|
11 | 9 | from readthedocs.builds.constants import EXTERNAL
|
@@ -644,79 +642,17 @@ def generate_readthedocs_data_javascript(self):
|
644 | 642 | log.warning(yaml_path)
|
645 | 643 | data = yaml.safe_load(open(yaml_path, "r"))
|
646 | 644 | except Exception:
|
647 |
| - |
648 |
| - # NOTE: skip this work for now until we decide whether or not this YAML file is required |
| 645 | + # NOTE: skip this work for now until we decide whether or not this YAML file is required. |
| 646 | + # NOTE: decide whether or not we want this file to be mandatory and raise an exception here. |
| 647 | + log.info("No `readthedocs-build.yaml` was provided.") |
649 | 648 | return
|
650 | 649 |
|
651 |
| - # TODO: Improve this message |
652 |
| - raise BuildUserError( |
653 |
| - "The required 'readthedocs-build.yaml' file was not provided." |
654 |
| - ) |
655 |
| - |
656 | 650 | log.info("readthedocs-build.yaml loaded.", path=yaml_path)
|
657 | 651 |
|
658 | 652 | # TODO: validate the YAML generated by the user
|
659 | 653 | # self._validate_readthedocs_data_yaml(data)
|
660 | 654 |
|
661 |
| - # Populate the data provided by the doctool with data we have from the build context |
662 |
| - # TODO: this is the new structure that has to be defined |
663 |
| - # context = { |
664 |
| - # "project": { |
665 |
| - # "slug": self.data.project.slug, |
666 |
| - # }, |
667 |
| - # "version": { |
668 |
| - # "slug": self.data.version.slug, |
669 |
| - # }, |
670 |
| - # "build": { |
671 |
| - # "id": self.data.build["pk"], |
672 |
| - # }, |
673 |
| - # } |
674 |
| - |
675 |
| - # NOTE: this is the OLD structure. |
676 |
| - # This will be changed for a new structure that we have to decide yet. |
677 |
| - # I'm using the old one for now just to keep compatibility. |
678 |
| - context = { |
679 |
| - "ad_free": False, |
680 |
| - "api_host": "http://devthedocs.org", |
681 |
| - "build_date": timezone.now(), |
682 |
| - "builder": "$DOCTOOL_NAME", |
683 |
| - "canonical_url": self.data.project.canonical_url, |
684 |
| - "commit": self.data.build["commit"], |
685 |
| - "docroot": "$DOCTOOL_DOCROOT", |
686 |
| - "language": self.data.project.language, |
687 |
| - "page": "$DOCTOOL_PAGE", # Can we define this dynamically via Javascript? |
688 |
| - "programming_language": self.data.project.programming_language, |
689 |
| - "project": self.data.project.slug, |
690 |
| - "version": self.data.version.slug, |
691 |
| - "source_suffix": "$DOCTOOL_SOURCE_SUFFIX", |
692 |
| - "theme": "$DOCTOOL_THEME", |
693 |
| - # These can be removed |
694 |
| - "user_analytics_code": None, |
695 |
| - "global_analytics_code": None, |
696 |
| - "proxied_api_host": f"/{settings.DOC_PATH_PREFIX}", |
697 |
| - "subprojects": None, |
698 |
| - # TODO: remove the following ones, they are just my own tests |
699 |
| - # NOTE: eventually, some of these settings should be enabled/disabled by the reader |
700 |
| - "build": { |
701 |
| - "id": self.data.build_pk, |
702 |
| - "external_version": self.data.version.type == EXTERNAL, |
703 |
| - }, |
704 |
| - "repository_url": self.data.project.repo, |
705 |
| - } |
706 |
| - |
707 |
| - # Update user's generated data with our own data. |
708 |
| - data.update(context) |
709 |
| - |
710 |
| - js_path = os.path.join( |
711 |
| - self.data.project.artifact_path( |
712 |
| - version=self.data.version.slug, type_="html" |
713 |
| - ), |
714 |
| - "readthedocs-data.html", |
715 |
| - ) |
716 |
| - content = render_to_string( |
717 |
| - template_name="doc_builder/readthedocs-data.html", |
718 |
| - context=dict(data=context), |
719 |
| - ) |
720 |
| - with open(js_path, "w") as f: |
721 |
| - f.write(content) |
722 |
| - log.info("readthedocs-data.html written.", path=js_path) |
| 655 | + # Copy the YAML data into `Version.build_data`. |
| 656 | + # It will be saved when the API is hit. |
| 657 | + # This data will be used by the `/_/readthedocs-config.json` API endpoint. |
| 658 | + self.data.version.build_data = data |
0 commit comments