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

Adding language support to Birdy #164

Merged
merged 19 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions birdy/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ class BirdyCLI(click.MultiCommand):
:param url: URL of the Web Processing Service.
:param caps_xml: A WPS GetCapabilities response for testing.
:param desc_xml: A WPS DescribeProcess response with "identifier=all" for testing.
:param language: Language parameter for WPS GetCapabilities and DescribeProcess responses.
"""
def __init__(self, name=None, url=None, caps_xml=None, desc_xml=None, **attrs):
def __init__(self, name=None, url=None, caps_xml=None, desc_xml=None, language=None, **attrs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is doing what you want for the cli... I think you want to add the language option in _update_commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm.. I added it mainly so it could be passed on for self.wps = WebProcessingService(...), so an instance of the BirdyCLI class could be initiated with a language, but it might be a lack of comprehension of how click.MultiCommand works and is used.

Should I remove the language parameter from the init and WebProcessingService instantiation and only add it as a command?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not familiar enough with click either... I would need to check into this more.

If you want, you can focus this PR on adding language support for the client only, or find how to add it as a parameter to the cli also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, well I don't think adding it to the cli is bad per say, as it still is a class that has a wps as a parameter, which can receive a language parameter. It might not be a best practice for click though...

I have time to dig a bit more into click. If it turns out to be a time sink or I get submerged by other assignments, I'll revert what I changed to BirdyCli and we'll save it for a future PR.

click.MultiCommand.__init__(self, name, **attrs)
self.url = os.environ.get('WPS_SERVICE') or url
self.verify = get_ssl_verify()
self.caps_xml = caps_xml
self.desc_xml = desc_xml
self.wps = WebProcessingService(self.url, verify=self.verify, skip_caps=True)
self.language = language
self.wps = WebProcessingService(self.url, verify=self.verify, skip_caps=True, language=language)
self.commands = OrderedDict()

def _update_commands(self):
Expand Down
17 changes: 17 additions & 0 deletions birdy/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
version=WPS_DEFAULT_VERSION,
caps_xml=None,
desc_xml=None,
language=None,
):
"""
Args:
Expand All @@ -63,13 +64,16 @@ def __init__(
verbose (str): passed to :class:`owslib.wps.WebProcessingService`
progress (bool): If True, enable interactive user mode.
version (str): WPS version to use.
language (str): passed to :class:`owslib.wps.WebProcessingService`
ex: 'fr-CA', 'en_US'. Will default to en-US.
f-PLT marked this conversation as resolved.
Show resolved Hide resolved
huard marked this conversation as resolved.
Show resolved Hide resolved
"""
self._converters = converters
self._interactive = progress
self._mode = ASYNC if progress else SYNC
self._notebook = notebook.is_notebook()
self._inputs = {}
self._outputs = {}
self._language = language
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not necessary (the language property takes its value in self._wps.language)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right. Didn't remove this one after adding the language property functions.


if not verify:
import urllib3
Expand Down Expand Up @@ -102,6 +106,7 @@ def __init__(
verify=verify,
cert=cert,
skip_caps=True,
language=language
)

try:
Expand All @@ -125,6 +130,18 @@ def __init__(

self.__doc__ = utils.build_wps_client_doc(self._wps, self._processes)

@property
def language(self):
return self._wps.language

@language.setter
def language(self, value):
self._wps.language = value

@property
def languages(self):
return self._wps.languages

def _get_process_description(self, processes=None, xml=None):
"""Return the description for each process.

Expand Down
3 changes: 2 additions & 1 deletion tests/resources/wps_emu_caps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
<ows:Language>en-US</ows:Language>
</wps:Default>
<wps:Supported>
<ows:Language>lang</ows:Language>
<ows:Language>en-US</ows:Language>
<ows:Language>fr-CA</ows:Language>
</wps:Supported>
</wps:Languages>
</wps:Capabilities>
10 changes: 10 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def test_emu_offline():
assert 'Hello' in wps.hello.__doc__


def test_wps_supported_languages():
wps = WPSClient(URL_EMU, caps_xml=EMU_CAPS_XML, desc_xml=EMU_DESC_XML)
assert wps.languages.supported == ['en-US', 'fr-CA']


def test_wps_with_language_arg():
wps = WPSClient(URL_EMU, caps_xml=EMU_CAPS_XML, desc_xml=EMU_DESC_XML, language='fr-CA')
assert wps.language == 'fr-CA'


@pytest.mark.online
@pytest.mark.xfail(reason="a wps process has invalid defaultValue Inf")
def test_52north():
Expand Down