示例#1
0
    def conf_file(self, version=LATEST):
        """Find a ``conf.py`` file in the project checkout."""
        if self.conf_py_file:
            conf_path = os.path.join(
                self.checkout_path(version),
                self.conf_py_file,
            )

            if os.path.exists(conf_path):
                log.info('Inserting conf.py file path from model')
                return conf_path

            log.warning("Conf file specified on model doesn't exist")

        files = self.find('conf.py', version)
        if not files:
            files = self.full_find('conf.py', version)
        if len(files) == 1:
            return files[0]
        for filename in files:
            # When multiples conf.py files, we look up the first one that
            # contains the `doc` word in its path and return this one
            if filename.find('doc', 70) != -1:
                return filename

        # If the project has more than one conf.py file but none of them have
        # the `doc` word in the path, we raise an error informing this to the user
        if len(files) > 1:
            raise ProjectConfigurationError(
                ProjectConfigurationError.MULTIPLE_CONF_FILES)

        raise ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND)
示例#2
0
    def append_conf(self, **__):
        """Find or create a ``conf.py`` with a rendered ``doc_builder/conf.py.tmpl`` appended"""
        if self.config_file is None:
            master_doc = self.create_index(extension='rst')
            self._write_config(master_doc=master_doc)

        try:
            self.config_file = (self.config_file
                                or self.project.conf_file(self.version.slug))
            outfile = codecs.open(self.config_file, encoding='utf-8', mode='a')
        except (ProjectConfigurationError, IOError):
            trace = sys.exc_info()[2]
            six.reraise(
                ProjectConfigurationError,
                ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND),
                trace)

        # Append config to project conf file
        tmpl = template_loader.get_template('doc_builder/conf.py.tmpl')
        rendered = tmpl.render(self.get_config_params())

        with outfile:
            outfile.write('\n')
            outfile.write(rendered)

        # Print the contents of conf.py in order to make the rendered
        # configfile visible in the build logs
        self.run(
            'cat',
            os.path.relpath(
                self.config_file,
                self.project.checkout_path(self.version.slug),
            ),
            cwd=self.project.checkout_path(self.version.slug),
        )
示例#3
0
    def append_conf(self, **__):
        """Modify given ``conf.py`` file from a whitelisted user's project."""
        try:
            self.version.get_conf_py_path()
        except ProjectConfigurationError:
            master_doc = self.create_index(extension='rst')
            self._write_config(master_doc=master_doc)

        try:
            outfile_path = self.project.conf_file(self.version.slug)
            outfile = codecs.open(outfile_path, encoding='utf-8', mode='a')
        except (ProjectConfigurationError, IOError):
            trace = sys.exc_info()[2]
            six.reraise(
                ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND),
                None, trace)

        # Append config to project conf file
        tmpl = template_loader.get_template('doc_builder/conf.py.tmpl')
        rendered = tmpl.render(self.get_config_params())

        with outfile:
            outfile.write('\n')
            outfile.write(rendered)

        # Print the contents of conf.py in order to make the rendered
        # configfile visible in the build logs
        self.run(
            'cat',
            os.path.relpath(
                outfile_path,
                self.project.checkout_path(self.version.slug),
            ),
            cwd=self.project.checkout_path(self.version.slug),
        )
示例#4
0
 def conf_file(self, version=LATEST):
     """Find a ``conf.py`` file in the project checkout"""
     if self.conf_py_file:
         conf_path = os.path.join(self.checkout_path(version),
                                  self.conf_py_file)
         if os.path.exists(conf_path):
             log.info('Inserting conf.py file path from model')
             return conf_path
         else:
             log.warning("Conf file specified on model doesn't exist")
     files = self.find('conf.py', version)
     if not files:
         files = self.full_find('conf.py', version)
     if len(files) == 1:
         return files[0]
     for filename in files:
         if filename.find('doc', 70) != -1:
             return filename
     raise ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND)
示例#5
0
    def append_conf(self, **__):
        """Find or create a ``conf.py`` with a rendered ``doc_builder/conf.py.tmpl`` appended"""
        if self.config_file is None:
            master_doc = self.create_index(extension='rst')
            self._write_config(master_doc=master_doc)

        try:
            self.config_file = (self.config_file
                                or self.project.conf_file(self.version.slug))
            # Prepend line that sets the readthedocs env variable to false
            with open(self.config_file, mode="r") as orig:
                data = orig.read().splitlines(True)
            with open(self.config_file, mode="w") as prep:
                prep.write("import os \nos.environ['READTHEDOCS']='False'\n")
                prep.writelines(data[1:])
            outfile = codecs.open(self.config_file, encoding='utf-8', mode='a')
        except (ProjectConfigurationError, IOError):
            trace = sys.exc_info()[2]
            six.reraise(
                ProjectConfigurationError,
                ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND),
                trace)

        # Append config to project conf file
        tmpl = template_loader.get_template('doc_builder/conf.py.tmpl')
        rendered = tmpl.render(self.get_config_params())

        with outfile:
            outfile.write('\n')
            outfile.write(rendered)

        # Print the contents of conf.py in order to make the rendered
        # configfile visible in the build logs
        self.run(
            'cat',
            os.path.relpath(
                self.config_file,
                self.project.checkout_path(self.version.slug),
            ),
            cwd=self.project.checkout_path(self.version.slug),
        )
示例#6
0
    def append_conf(self):
        """
        Find or create a ``conf.py`` and appends default content.

        The default content is rendered from ``doc_builder/conf.py.tmpl``.
        """
        if self.config_file is None:
            master_doc = self.create_index(extension='rst')
            self._write_config(master_doc=master_doc)

        try:
            self.config_file = (self.config_file
                                or self.project.conf_file(self.version.slug))
            outfile = codecs.open(self.config_file, encoding='utf-8', mode='a')
        except IOError:
            raise ProjectConfigurationError(
                ProjectConfigurationError.NOT_FOUND)

        # Append config to project conf file
        tmpl = template_loader.get_template('doc_builder/conf.py.tmpl')
        rendered = tmpl.render(self.get_config_params())

        with outfile:
            outfile.write('\n')
            outfile.write(rendered)

        # Print the contents of conf.py in order to make the rendered
        # configfile visible in the build logs
        self.run(
            'cat',
            os.path.relpath(
                self.config_file,
                self.project_path,
            ),
            cwd=self.project_path,
        )