Пример #1
0
        def clean_doc_log(file_name):
            """
            Removes sphinx/python 2.6 warning messages.

            Sphinx is very noisy with some warning messages.  This method removes these noisy warnings.

            Messages to remove:

            * WARNING: py:class reference target not found: object
            * WARNING: py:class reference target not found: exceptions.Exception
            * WARNING: py:class reference target not found: type
            * WARNING: py:class reference target not found: tuple

            :param file_name: log file name
             :type file_name: str
            """
            if os.path.isfile(file_name):
                with safe_edit(file_name) as files:
                    in_file = files["in"]
                    out_file = files["out"]
                    for line in in_file.readlines():
                        match = re.search(r"WARNING: py:class reference target not found: (\S+)", line)
                        if match:
                            if match.group(1) in ["object", "exceptions.Exception", "type", "tuple"]:
                                continue
                        out_file.write(line)
Пример #2
0
    def clean_doc_log(file_name):
        """
        Removes sphinx/python 2.6 warning messages.

        Sphinx is very noisy with some warning messages.  This method removes these noisy warnings.

        Messages to remove:

        * WARNING: py:class reference target not found: object
        * WARNING: py:class reference target not found: exceptions.Exception
        * WARNING: py:class reference target not found: type
        * WARNING: py:class reference target not found: tuple
        * WARNING: No classes found for inheritance diagram

        :param file_name: log file name
         :type file_name: str
        """
        if os.path.isfile(file_name):
            with safe_edit(file_name) as files:
                in_file = files['in']
                out_file = files['out']
                for line in in_file.readlines():
                    match = re.search(r'WARNING: py:class reference target not found: (\S+)', line)
                    if match:
                        if match.group(1) in ['object', 'exceptions.Exception', 'type', 'tuple']:
                            continue
                    match = re.search(r'WARNING: No classes found for inheritance diagram', line)
                    if match:
                        continue
                    out_file.write(line)
Пример #3
0
            def hack(self, exclude=None):
                """
                substitute full names into mod lines with base names.

                :param exclude: list of files to exclude from generating inheritance diagrams
                :type exclude: list(str)
                """
                if os.path.splitext(self.file_name)[1] != ".rst":
                    return

                if exclude is None:
                    exclude = []

                with safe_edit(self.file_name) as files:
                    in_file = files["in"]
                    out_file = files["out"]
                    info("Editing %s" % self.file_name)

                    self.line_length = 0
                    self.package = False
                    self.class_name = ""

                    headers_to_remove = ["Subpackages", "Submodules", "Module contents"]

                    out_file.write(".. include:: ../icons.rst")
                    out_file.write("\n\n")

                    delete_next_line = False
                    for line in in_file.readlines():
                        if delete_next_line and line.startswith("---"):
                            info("removing " + line.strip())
                            delete_next_line = False
                            continue
                        delete_next_line = False
                        line = self._hack_mod(line)
                        line = self._hack_package(line)
                        line = self._hack_module(line)
                        line = self._hack_init(line)
                        line = self._hack_underline(line)
                        line = self._hack_members(line)
                        if line.strip() in headers_to_remove:
                            info("removing " + line.strip())
                            delete_next_line = True
                            continue
                        out_file.write(line)

                    out_file.write("\n\n")
                    # title = "%s Inheritance Diagrams" % self.module_name
                    # out_file.write("%s\n" % title)
                    # out_file.write('-' * len(title) + "\n\n")
                    for value in sorted(self.name_dict.values()):
                        if value not in exclude:
                            out_file.write(".. inheritance-diagram:: %s\n" % value)
                    out_file.write("\n\n")
Пример #4
0
def _edit_package_version(version_str, project_package=None):
    def version_line(ver_str):
        """
        return python line for setting the __version__ attribute

        :param ver_str: the version string
         :type ver_str: str
        """
        return "__version__ = '{version}'".format(version=ver_str)
    file_name = _file_spec('__init__.py', project_package)
    # if not os.path.isfile(file_name):
    #     touch(file_name)
    with safe_edit(file_name) as files:
        replaced = False
        for line in files['in'].readlines():
            match = re.match(VERSION_REGEX, line)
            if match:
                line = re.sub(VERSION_REGEX, version_line(version_str), line)
                replaced = True
            files['out'].write(line)
        if not replaced:
            files['out'].write("\n")
            files['out'].write(version_line(version_str))
            files['out'].write("\n")