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

ext_autodoc: support RST anonymous link #542

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pywps/ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
from pywps.app.Common import Metadata


class MetadataUrl(Metadata):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the anonymous option to the Metadata class itself instead of sub-classing it. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my initial thought until I saw how the Metadata class is being used. It's being used to generate the xml response, it can be serialized to and deserialized from json format. So bigger impact and not required for what I needed to solve.

So I am unsure if adding the new anonymous option there is appropriate.

But it's my first pywps commit so I will follow you guidance. Let me know if adding it to the Metadata is the right thing to do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomkralidis What is your opinion?

"""Metadata subclass to allow anonymous links generation.

Useful to avoid Sphinx "Duplicate explicit target name" warning.

See https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#anonymous-hyperlinks.
"""

def __init__(self, title, href=None, role=None, type_='simple',
anonymous=False):
super().__init__(title, href=href, role=role, type_=type_)
self.anonymous = anonymous
"Whether to create anonymous link (boolean)."


class ProcessDocumenter(ClassDocumenter):
"""Sphinx autodoc ClassDocumenter subclass that understands the
pywps.Process class.
Expand Down Expand Up @@ -126,8 +141,11 @@ class instance.
title, href = m['title'], m['href']
else:
title, href = None, None
extra_underscore = ""
if isinstance(m, MetadataUrl):
extra_underscore = "_" if m.anonymous else ""
if title and href:
ref.append(u" - `{} <{}>`_".format(title, href))
ref.append(u" - `{} <{}>`_{}".format(title, href, extra_underscore))
hasref = True

ref.append('')
Expand Down
6 changes: 5 additions & 1 deletion pywps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pywps.inout import LiteralInput, LiteralOutput, ComplexInput, ComplexOutput, BoundingBoxInput, BoundingBoxOutput
from pywps.inout import Format
from pywps.app.Common import Metadata
from pywps.ext_autodoc import MetadataUrl

import re

Expand Down Expand Up @@ -75,7 +76,10 @@ def __init__(self):
version="4.0",
metadata=[Metadata('PyWPS docs', 'https://pywps.org'),
Metadata('NumPy docstring conventions',
'https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt')],
'https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt'),
MetadataUrl('Duplicate label', 'http://one.example.com', anonymous=True),
MetadataUrl('Duplicate label', 'http://two.example.com', anonymous=True),
],
inputs=inputs,
outputs=outputs,
)
Expand Down