예제 #1
0
 def _remove_summary(self, s):
     # if the string does not start with one of the sections, we remove the
     # summary
     if not self._all_sections_patt.match(s.lstrip()):
         # remove the summary
         lines = summary_patt.sub('', s, 1).splitlines()
         # look for the first line with content
         first = next((i for i, l in enumerate(lines) if l.strip()), 0)
         # dedent the lines
         s = dedents('\n' + '\n'.join(lines[first:]))
     return s
예제 #2
0
파일: docrep.py 프로젝트: bccp/nbodykit
 def _remove_summary(self, s):
     # if the string does not start with one of the sections, we remove the
     # summary
     if not self._all_sections_patt.match(s.lstrip()):
         # remove the summary
         lines = summary_patt.sub('', s, 1).splitlines()
         # look for the first line with content
         first = next((i for i, l in enumerate(lines) if l.strip()), 0)
         # dedent the lines
         s = dedents('\n' + '\n'.join(lines[first:]))
     return s
예제 #3
0
    def dedents(self, s):
        """
        A special case of the DocStringProcessor that first performs a dedent
        on the incoming string

        Parameters
        ----------
        s: str
            string to dedent and insert the sections of the :attr:`params`
            attribute"""
        s = dedents(s)
        return safe_modulo(s, self.params)
예제 #4
0
    def get_sections(self,
                     s,
                     base,
                     sections=['Parameters', 'Other Parameters']):
        """
        Method that extracts the specified sections out of the given string if
        (and only if) the docstring follows the numpy documentation guidelines
        [1]_. Note that the section either must appear in the
        :attr:`param_like_sections` or the :attr:`text_sections` attribute.

        Parameters
        ----------
        s: str
            Docstring to split
        base: str
            base to use in the :attr:`sections` attribute
        sections: list of str
            sections to look for. Each section must be followed by a newline
            character ('\\n') and a bar of '-' (following the numpy (napoleon)
            docstring conventions).

        Returns
        -------
        str
            The replaced string

        References
        ----------
        .. [1] https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt

        See Also
        --------
        delete_params, keep_params, delete_types, keep_types, delete_kwargs:
            For manipulating the docstring sections
        save_docstring:
            for saving an entire docstring
        """
        params = self.params
        sections_patt = re.compile('|'.join(sections) + '(?=\n\s*-)')
        # if the string does not start with one of the sections, we remove the
        # summary
        if not sections_patt.match(s.lstrip()):
            # remove the summary
            lines = summary_patt.sub('', s, 1).splitlines()
            # look for the first line with content
            first = next((i for i, l in enumerate(lines) if l.strip()), 0)
            # dedent the lines
            s = dedents('\n' + '\n'.join(lines[first:]))
        for section in sections:
            key = '%s.%s' % (base, section.lower().replace(' ', '_'))
            params[key] = self._get_section(s, section)
        return s
예제 #5
0
    def dedents(self, s, stacklevel=3):
        """
        Dedent a string and substitute with the :attr:`params` attribute

        Parameters
        ----------
        s: str
            string to dedent and insert the sections of the :attr:`params`
            attribute
        stacklevel: int
            The stacklevel for the warning raised in :func:`safe_module` when
            encountering an invalid key in the string"""
        s = dedents(s)
        return safe_modulo(s, self.params, stacklevel=stacklevel)
예제 #6
0
파일: docrep.py 프로젝트: bccp/nbodykit
    def dedents(self, s, stacklevel=3):
        """
        Dedent a string and substitute with the :attr:`params` attribute

        Parameters
        ----------
        s: str
            string to dedent and insert the sections of the :attr:`params`
            attribute
        stacklevel: int
            The stacklevel for the warning raised in :func:`safe_module` when
            encountering an invalid key in the string"""
        s = dedents(s)
        return safe_modulo(s, self.params, stacklevel=stacklevel)