Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tolerant docstring parser #31

Open
PicoCentauri opened this issue May 20, 2021 · 6 comments
Open

More tolerant docstring parser #31

PicoCentauri opened this issue May 20, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@PicoCentauri
Copy link
Collaborator

Our current docstring parser located at

def parse_docs(klass):

returns a dictionary of the the docstring. It works but it is not as flexible and tolerant as the sphinx/napoleon implementation. Especially we have problems with the separator between a parameter name and its type; usually denoted by name : type. A different notation can not be parsed since we use a hardcoded split

mdacli/src/mdacli/utils.py

Lines 230 to 232 in 78fa3f2

for line in doc_lines[par_i: end_param_line][::-1]:
if ' : ' in line:
par_name, others_ = line.split(' : ')

Improvements with using a regex did also not succeed. If possible we should incorporate the sphinx parser or at least get some ideas from their implementation.

@PicoCentauri PicoCentauri added enhancement New feature or request help wanted Extra attention is needed labels May 20, 2021
@joaomcteixeira
Copy link
Member

I had committed a re.split in the PR, then we rejected it. Won't that help?
Do you wan to go beyond #23 ?

@joaomcteixeira
Copy link
Member

Example by @PicoCentauri

"""
    Attributes
    ----------
    dim_fac : int
        Dimensionality :math:`d` of the MSD.
    results.timeseries : :class:`numpy.ndarray`
        The averaged MSD over all the particles with respect to lag-time.
    results.msds_by_particle : :class:`numpy.ndarray`
        The MSD of each individual particle with respect to lag-time.
    ag : :class:`AtomGroup`
        The :class:`AtomGroup` resulting from your selection
    n_frames : int
        Number of frames included in the analysis.
    n_particles : int
        Number of particles MSD was calculated over.


    .. versionadded:: 2.0.0
"""

@joaomcteixeira
Copy link
Member

joaomcteixeira commented May 20, 2021

"""
    Parameters
    ----------
    universe : Universe
        Universe object
    select : str
        Selection string to evaluate its angular distribution ['byres name OH2']
    bins : int (optional)
        Number of bins to create the histogram by means of :func:`numpy.histogram`
    axis : {'x', 'y', 'z'} (optional)
        Axis to create angle with the vector (HH, OH or dipole) and calculate
        cosine theta ['z'].


    .. versionadded:: 0.11.0

    .. versionchanged:: 1.0.0
       Changed `selection` keyword to `select`
"""

@joaomcteixeira
Copy link
Member

try again numpydocs. where docstrings updated in mda since #2 ?

@PicoCentauri
Copy link
Collaborator Author

I just checked the numpydocs parser and they are still not able to parse docstrings without surrounding spaces...

@joaomcteixeira
Copy link
Member

Yes,

I tried the other day and I saw it was also a bit of a mess. I think we (ok me 😛 ) should write this more general parser, that is also compatible with the synphx parsing and than create tests on the side of MDAnalysis to enforce new Analysis classes follow these guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants